|
1 | 1 | import BloomFilter from '../BloomFilter';
|
2 | 2 |
|
3 |
| -describe('Bloom Filter', () => { |
| 3 | +describe('BloomFilter', () => { |
4 | 4 | let bloomFilter;
|
5 |
| - const people = ['Bruce Wayne', 'Clark Kent', 'Barry Allen']; |
| 5 | + const people = [ |
| 6 | + 'Bruce Wayne', |
| 7 | + 'Clark Kent', |
| 8 | + 'Barry Allen', |
| 9 | + ]; |
6 | 10 |
|
7 | 11 | beforeEach(() => {
|
8 | 12 | bloomFilter = new BloomFilter();
|
9 | 13 | });
|
10 | 14 |
|
11 |
| - it('Should have methods named "insert" and "mayContain"', () => { |
| 15 | + it('should have methods named "insert" and "mayContain"', () => { |
12 | 16 | expect(typeof bloomFilter.insert).toBe('function');
|
13 | 17 | expect(typeof bloomFilter.mayContain).toBe('function');
|
14 | 18 | });
|
15 | 19 |
|
16 |
| - it('Should create a new filter store with the appropriate methods', () => { |
| 20 | + it('should create a new filter store with the appropriate methods', () => { |
17 | 21 | const store = bloomFilter.createStore(18);
|
18 | 22 | expect(typeof store.getValue).toBe('function');
|
19 | 23 | expect(typeof store.setValue).toBe('function');
|
20 | 24 | });
|
21 | 25 |
|
22 |
| - it('Should hash deterministically with all 3 hash functions', () => { |
23 |
| - const str = 'abc'; |
24 |
| - expect(bloomFilter.hash1(str)).toEqual(bloomFilter.hash1(str)); |
25 |
| - expect(bloomFilter.hash2(str)).toEqual(bloomFilter.hash2(str)); |
26 |
| - expect(bloomFilter.hash3(str)).toEqual(bloomFilter.hash3(str)); |
| 26 | + it('should hash deterministically with all 3 hash functions', () => { |
| 27 | + const str1 = 'apple'; |
| 28 | + |
| 29 | + expect(bloomFilter.hash1(str1)).toEqual(bloomFilter.hash1(str1)); |
| 30 | + expect(bloomFilter.hash2(str1)).toEqual(bloomFilter.hash2(str1)); |
| 31 | + expect(bloomFilter.hash3(str1)).toEqual(bloomFilter.hash3(str1)); |
| 32 | + |
| 33 | + expect(bloomFilter.hash1(str1)).toBe(14); |
| 34 | + expect(bloomFilter.hash2(str1)).toBe(43); |
| 35 | + expect(bloomFilter.hash3(str1)).toBe(10); |
| 36 | + |
| 37 | + const str2 = 'orange'; |
| 38 | + |
| 39 | + expect(bloomFilter.hash1(str2)).toEqual(bloomFilter.hash1(str2)); |
| 40 | + expect(bloomFilter.hash2(str2)).toEqual(bloomFilter.hash2(str2)); |
| 41 | + expect(bloomFilter.hash3(str2)).toEqual(bloomFilter.hash3(str2)); |
| 42 | + |
| 43 | + expect(bloomFilter.hash1(str2)).toBe(0); |
| 44 | + expect(bloomFilter.hash2(str2)).toBe(61); |
| 45 | + expect(bloomFilter.hash3(str2)).toBe(10); |
27 | 46 | });
|
28 | 47 |
|
29 |
| - it('Should create an array with 3 hash values', () => { |
30 |
| - expect(bloomFilter.getHashValues('abc').length).toEqual(3); |
| 48 | + it('should create an array with 3 hash values', () => { |
| 49 | + expect(bloomFilter.getHashValues('abc').length).toBe(3); |
| 50 | + expect(bloomFilter.getHashValues('abc')).toEqual([66, 63, 54]); |
31 | 51 | });
|
32 | 52 |
|
33 |
| - it('Should insert strings correctly and return true when checking for inserted values', () => { |
| 53 | + it('should insert strings correctly and return true when checking for inserted values', () => { |
34 | 54 | people.forEach(person => bloomFilter.insert(person));
|
35 |
| - expect(bloomFilter.mayContain('Bruce Wayne')).toBe(true); |
36 |
| - expect(bloomFilter.mayContain('Clark Kent')).toBe(true); |
37 |
| - expect(bloomFilter.mayContain('Barry Allen')).toBe(true); |
| 55 | + |
| 56 | + expect(bloomFilter.mayContain('Bruce Wayne')).toBeTruthy(); |
| 57 | + expect(bloomFilter.mayContain('Clark Kent')).toBeTruthy(); |
| 58 | + expect(bloomFilter.mayContain('Barry Allen')).toBeTruthy(); |
| 59 | + |
| 60 | + expect(bloomFilter.mayContain('Tony Stark')).toBeFalsy(); |
38 | 61 | });
|
39 | 62 | });
|
0 commit comments