forked from javascript-obfuscator/javascript-obfuscator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayUtils.spec.ts
More file actions
117 lines (87 loc) · 3.6 KB
/
Copy pathArrayUtils.spec.ts
File metadata and controls
117 lines (87 loc) · 3.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import { assert } from 'chai';
import { ServiceIdentifiers } from '../../../src/container/ServiceIdentifiers';
import { IArrayUtils } from '../../../src/interfaces/utils/IArrayUtils';
import { IInversifyContainerFacade } from '../../../src/interfaces/container/IInversifyContainerFacade';
import { InversifyContainerFacade } from '../../../src/container/InversifyContainerFacade';
describe('Utils', () => {
let arrayUtils: IArrayUtils;
before(() => {
const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade();
inversifyContainerFacade.load('', {});
arrayUtils = inversifyContainerFacade.get<IArrayUtils>(ServiceIdentifiers.IArrayUtils);
});
describe('arrayRange (length: number): number[]', () => {
describe('range length more than 0', () => {
const rangeLength: number = 5;
const expectedArray: number[] = [0, 1, 2, 3, 4];
let array: number[];
before(() => {
array = arrayUtils.arrayRange(rangeLength);
});
it('should return array with range of numbers', () => {
assert.deepEqual(array, expectedArray);
});
});
describe('range length is 0', () => {
const rangeLength: number = 0;
const expectedArray: number[] = [];
let array: number[];
before(() => {
array = arrayUtils.arrayRange(rangeLength);
});
it('should return empty array', () => {
assert.deepEqual(array, expectedArray);
});
});
describe('range length less than 0', () => {
const rangeLength: number = -5;
const expectedArray: number[] = [];
let array: number[];
before(() => {
array = arrayUtils.arrayRange(rangeLength);
});
it('should return empty array', () => {
assert.deepEqual(array, expectedArray);
});
});
});
describe('arrayRotate <T> (array: T[], times: number): T[]', () => {
let array: number[],
rotatedArray: number[];
beforeEach(() => {
array = [1, 2, 3, 4, 5, 6];
});
describe('value is not 0', () => {
const rotateValue: number = 2;
const expectedArray: number[] = [5, 6, 1, 2, 3, 4];
beforeEach(() => {
rotatedArray = arrayUtils.arrayRotate(array, rotateValue);
});
it('should rotate (shift) array by a given value', () => {
assert.deepEqual(rotatedArray, expectedArray);
});
});
describe('value equals or less 0', () => {
const rotateValue: number = 0;
const expectedArray: number[] = [1, 2, 3, 4, 5, 6];
beforeEach(() => {
rotatedArray = arrayUtils.arrayRotate(array, rotateValue);
});
it('shouldn\'t rotate array', () => {
assert.deepEqual(rotatedArray, expectedArray);
});
});
describe('empty array', () => {
const emptyArray: number[] = [];
const rotateValue: number = 5;
const expectedError: ReferenceErrorConstructor = ReferenceError;
let testFunc: () => void;
beforeEach(() => {
testFunc = () => arrayUtils.arrayRotate(emptyArray, rotateValue);
});
it('should throw exception if array is empty', () => {
assert.throws(testFunc, expectedError);
});
});
});
});