-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.spec.ts
95 lines (75 loc) · 2.42 KB
/
index.spec.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
87
88
89
90
91
92
93
94
95
import 'mocha';
import { expect } from 'chai';
import ArrayList from '.';
describe('unit test using `mocha ☕️` & `chai 🍵` 👻 ..', () => {
const myList = new ArrayList<number|string>();
const data = ['nodejs', 'js-lover', 'tunisia', 'red', 'CA', 'js-lover'];
const dataForSortCase = [100, 0, 50, -50, 0, -100];
beforeEach(() =>{
myList.removeAll();
myList.addAll(data);
});
it('add method ✅ ..', () => {
myList.removeAll();
myList.add('imed jaberi');
expect(myList.getAll().length).to.equal(1);
});
it('add all method ✅ ..', () => {
expect(myList.getAll().length).to.equal(data.length);
});
it('remove method ✅ ..', () => {
myList.remove(4);
expect(myList.getAll().length).to.equal((data.length - 1));
});
it('remove all method ✅ ..', () => {
myList.removeAll();
expect(myList.getAll().length).to.equal(0);
});
it('size method ✅ ..', () => {
expect(myList.size()).to.equal(data.length);
});
it('get method ✅ ..', () => {
expect(myList.get(1)).to.equal(data[1]);
});
it('get method - failed ❌ ..', () => {
expect(myList.get(data.length)).to.be.undefined;
});
it('get all method ✅ ..', () => {
expect(myList.getAll().length).to.equal(data.length);
});
it('set method ✅ ..', () => {
myList.set(0, 'react-js');
expect(myList.get(0)).to.equal('react-js');
});
it('isEmpty method ✅ ..', () => {
expect(myList.isEmpty()).to.be.false;
});
it('contains method ✅ ..', () => {
expect(myList.contains('tunisia')).to.be.true;
});
it('indexOf method ✅ ..', () => {
expect(myList.indexOf('tunisia')).to.equal(data.indexOf('tunisia'));
});
it('lastIndexOf method ✅ ..', () => {
expect(myList.lastIndexOf('js-lover')).to.equal(data.lastIndexOf('js-lover'));
});
it('nbrIndex method ✅ ..', () => {
expect(myList.nbrIndex('js-lover')).to.equal(data.filter((item) => item === 'js-lover').length);
});
it('sort method ✅ ..', () => {
// asc
myList.removeAll();
myList.addAll(dataForSortCase);
myList.sort();
// desc
let myList2 = new ArrayList();
myList2.addAll(dataForSortCase);
myList2.sort('desc');
// asc with params
let myList3 = new ArrayList();
myList3.addAll(dataForSortCase);
myList3.sort('asc');
expect(myList.getAll()).to.not.equal(myList2.getAll())
expect(myList.getAll()).to.deep.equal(myList3.getAll())
});
});