-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.ts
86 lines (82 loc) · 2.2 KB
/
index.test.ts
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
/**
* index.test.ts
*
* @module index.test.ts
*/
import thanos, { shuffleList, isArray } from './index';
describe('isArray', () => {
it('when receive null, should return false ', () => {
expect(isArray(null)).toBeFalsy();
});
it('when receive an object, should return false', () => {
const param = {
name: 'test',
};
expect(isArray(param)).toBeFalsy();
});
it('when receive an empty array should return true', () => {
expect(isArray([])).toBeTruthy();
});
it('when receive an filled array should return true', () => {
expect(isArray([1, 2, 3])).toBeTruthy();
});
});
describe('thanos', () => {
describe('shuffleList', () => {
it('should return a list', () => {
const result = shuffleList([]);
expect(result).toHaveLength(0);
});
it('should always return an array with the same length', () => {
const result = shuffleList([1, 2, 3, 4, 5]);
expect(result).toHaveLength(5);
});
});
describe('thanos', () => {
let obj: any;
beforeEach(() => {
obj = {
a: 1,
b: 2,
c: 3,
d: 4,
};
});
it('should return a new object', () => {
const result = thanos(obj);
expect(result).not.toBe(obj);
});
it('should apply thanos funcion recursivelly', () => {
const param = {
child: obj,
};
const result = thanos(param);
const keys = Object.keys(result.child);
expect(keys).toHaveLength(2);
});
it('the object should result with half of fields', () => {
const result = thanos(obj);
const keys = Object.keys(result);
expect(keys).toHaveLength(2);
});
it('array fields should have half of its elemtns removed', () => {
const param = {
...obj,
list: [1, 2, 3, 4, 5, 6],
};
const result = thanos(param);
expect(result.list).toHaveLength(3);
});
it('arrays with just one element shoud randomlly removed that one element', () => {
const param = [4];
let result = thanos(param);
if (result.length) {
result = thanos(param);
}
if (result.length) {
result = thanos(param);
}
expect(result).toHaveLength(0);
});
});
});