@@ -12,16 +12,16 @@ describe('HashTable', () => {
12
12
it ( 'should generate proper hash for specified keys' , ( ) => {
13
13
const hashTable = new HashTable ( ) ;
14
14
15
- expect ( hashTable . hash ( 'a' ) ) . toBe ( 17 ) ;
16
- expect ( hashTable . hash ( 'b' ) ) . toBe ( 20 ) ;
17
- expect ( hashTable . hash ( 'abc' ) ) . toBe ( 17 ) ;
15
+ expect ( hashTable . hash ( 'a' ) ) . toBe ( 20 ) ;
16
+ expect ( hashTable . hash ( 'b' ) ) . toBe ( 31 ) ;
17
+ expect ( hashTable . hash ( 'abc' ) ) . toBe ( 19 ) ;
18
18
} ) ;
19
19
20
20
it ( 'should set, read and delete data with collisions' , ( ) => {
21
21
const hashTable = new HashTable ( 3 ) ;
22
22
23
- expect ( hashTable . hash ( 'a' ) ) . toBe ( 2 ) ;
24
- expect ( hashTable . hash ( 'b' ) ) . toBe ( 0 ) ;
23
+ expect ( hashTable . hash ( 'a' ) ) . toBe ( 1 ) ;
24
+ expect ( hashTable . hash ( 'b' ) ) . toBe ( 1 ) ;
25
25
expect ( hashTable . hash ( 'c' ) ) . toBe ( 0 ) ;
26
26
expect ( hashTable . hash ( 'd' ) ) . toBe ( 2 ) ;
27
27
@@ -37,9 +37,9 @@ describe('HashTable', () => {
37
37
38
38
const stringifier = ( value ) => `${ value . key } :${ value . value } ` ;
39
39
40
- expect ( hashTable . buckets [ 0 ] . toString ( stringifier ) ) . toBe ( 'b:sea, c:earth' ) ;
41
- expect ( hashTable . buckets [ 1 ] . toString ( stringifier ) ) . toBe ( '' ) ;
42
- expect ( hashTable . buckets [ 2 ] . toString ( stringifier ) ) . toBe ( 'a:sky, d:ocean' ) ;
40
+ expect ( hashTable . buckets [ 0 ] . toString ( stringifier ) ) . toBe ( 'c:earth' ) ;
41
+ expect ( hashTable . buckets [ 1 ] . toString ( stringifier ) ) . toBe ( 'a:sky,b:sea ' ) ;
42
+ expect ( hashTable . buckets [ 2 ] . toString ( stringifier ) ) . toBe ( 'd:ocean' ) ;
43
43
44
44
expect ( hashTable . get ( 'a' ) ) . toBe ( 'sky' ) ;
45
45
expect ( hashTable . get ( 'd' ) ) . toBe ( 'ocean' ) ;
@@ -94,7 +94,7 @@ describe('HashTable', () => {
94
94
hashTable . set ( 'b' , 'beta' ) ;
95
95
hashTable . set ( 'c' , 'gamma' ) ;
96
96
97
- expect ( hashTable . getValues ( ) ) . toEqual ( [ 'beta ' , 'gamma ' , 'alpha ' ] ) ;
97
+ expect ( hashTable . getValues ( ) ) . toEqual ( [ 'gamma ' , 'alpha ' , 'beta ' ] ) ;
98
98
} ) ;
99
99
100
100
it ( 'should get all the values from empty hash table' , ( ) => {
@@ -111,6 +111,6 @@ describe('HashTable', () => {
111
111
112
112
hashTable . set ( 'ac' , 'three' ) ;
113
113
114
- expect ( hashTable . getValues ( ) ) . toEqual ( [ 'two ' , 'one ' , 'three' ] ) ;
114
+ expect ( hashTable . getValues ( ) ) . toEqual ( [ 'one ' , 'two ' , 'three' ] ) ;
115
115
} ) ;
116
116
} ) ;
0 commit comments