-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhash-table.test.ts
39 lines (35 loc) · 996 Bytes
/
hash-table.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
import { HashTable } from './hash-table'
import { std } from '../../javascript/_/math/std'
describe('Test HashTable', () => {
let ht: HashTable<string>
beforeEach(() => {
ht = new HashTable()
ht.set('a', 'a1')
ht.set('b', 'b1')
ht.set('c', 'c1')
ht.set('d', 'd1')
ht.set('e', 'e1')
})
it('should hash works', () => {
const hashed = {}
for (let i = 'A'.charCodeAt(0); i <= 'z'.charCodeAt(0); i++) {
const h = ht.hash(String.fromCharCode(i))
if (Object.prototype.hasOwnProperty.call(hashed, h)) {
hashed[h]++
} else {
hashed[h] = 0
}
}
expect(std(Object.values(hashed))).toBeLessThan(1)
})
it('should set works', () => {
expect(ht.keys()).toStrictEqual('a|b|c|d|e'.split('|'))
expect(ht.values()).toEqual(
expect.arrayContaining('a1|b1|c1|d1|e1'.split('|'))
)
})
it('should has works', () => {
expect(ht.has('a')).toBeTruthy()
expect(ht.has('f')).not.toBeTruthy()
})
})