-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathindex.test.js
116 lines (100 loc) · 2.93 KB
/
index.test.js
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
import HashTable from '.';
describe('HashTable', () => {
it('should pass every test', () => {
var hashT = new HashTable();
hashT.insert('Alex Hawkins', '510-599-1930');
expect(hashT.retrieve('Alex Hawkins')).toEqual('510-599-1930');
hashT.insert('Boo Radley', '520-589-1970');
expect(hashT.retrieveAll()).toEqual([
undefined,
[['Boo Radley', '520-589-1970']],
undefined,
[['Alex Hawkins', '510-599-1930']],
]);
hashT
.insert('Vance Carter', '120-589-1970')
.insert('Rick Mires', '520-589-1970')
.insert('Tom Bradey', '520-589-1970')
.insert('Biff Tanin', '520-589-1970');
expect(hashT.retrieveAll()).toEqual([
undefined,
[
['Boo Radley', '520-589-1970'],
['Tom Bradey', '520-589-1970'],
],
[['Vance Carter', '120-589-1970']],
[
['Alex Hawkins', '510-599-1930'],
['Rick Mires', '520-589-1970'],
],
undefined,
undefined,
[['Biff Tanin', '520-589-1970']],
]);
//overide example (Phone Number Change)
//
hashT
.insert('Rick Mires', '650-589-1970')
.insert('Tom Bradey', '818-589-1970')
.insert('Biff Tanin', '987-589-1970');
expect(hashT.retrieveAll()).toEqual([
undefined,
[
['Boo Radley', '520-589-1970'],
['Tom Bradey', '818-589-1970'],
],
[['Vance Carter', '120-589-1970']],
[
['Alex Hawkins', '510-599-1930'],
['Rick Mires', '650-589-1970'],
],
undefined,
undefined,
[['Biff Tanin', '987-589-1970']],
]);
hashT.remove('Rick Mires');
hashT.remove('Tom Bradey');
expect(hashT.retrieveAll()).toEqual([
undefined,
[['Boo Radley', '520-589-1970']],
[['Vance Carter', '120-589-1970']],
[['Alex Hawkins', '510-599-1930']],
undefined,
undefined,
[['Biff Tanin', '987-589-1970']],
]);
hashT
.insert('Dick Mires', '650-589-1970')
.insert('Lam James', '818-589-1970')
.insert('Ricky Ticky Tavi', '987-589-1970');
expect(hashT.retrieveAll()).toEqual([
undefined,
undefined,
[['Vance Carter', '120-589-1970']],
[
['Alex Hawkins', '510-599-1930'],
['Dick Mires', '650-589-1970'],
['Lam James', '818-589-1970'],
],
undefined,
undefined,
undefined,
undefined,
undefined,
[
['Boo Radley', '520-589-1970'],
['Ricky Ticky Tavi', '987-589-1970'],
],
undefined,
undefined,
undefined,
undefined,
[['Biff Tanin', '987-589-1970']],
]);
/* NOTICE HOW HASH TABLE HAS NOW DOUBLED IN SIZE UPON REACHING 75% CAPACITY ie 6/8. It is now size 16.
*/
expect(hashT.retrieve('Lam James')).toEqual('818-589-1970'); //818-589-1970
expect(hashT.retrieve('Dick Mires')).toEqual('650-589-1970'); //818-589-1970
expect(hashT.retrieve('Lebron James')).toBeNull();
});
});