@@ -48,26 +48,45 @@ import {
48
48
49
49
describe ( 'BloomFilter' , ( ) => {
50
50
it ( 'can initiate an empty BloomFilter' , ( ) => {
51
- const bloomFilter = new BloomFilter (
52
- /* bitmap */ new Uint8Array ( 0 ) ,
53
- /* padding */ 0 ,
54
- /* hashCount */ 0
55
- ) ;
51
+ const bloomFilter = new BloomFilter ( new Uint8Array ( 0 ) , 0 , 0 ) ;
56
52
expect ( bloomFilter . getBitSize ( ) ) . to . equal ( 0 ) ;
57
53
} ) ;
58
54
59
55
it ( 'can initiate a non empty BloomFilter' , ( ) => {
60
56
const bloomFilter = new BloomFilter (
61
- /* bitmap */ new Uint8Array ( [ 151 , 153 , 236 , 116 , 7 ] ) ,
62
- /* padding */ 3 ,
63
- /* hashCount */ 13
57
+ new Uint8Array ( [ 151 , 153 , 236 , 116 , 7 ] ) ,
58
+ 3 ,
59
+ 13
64
60
) ;
65
61
expect ( bloomFilter . getBitSize ( ) ) . to . equal ( 37 ) ;
66
62
} ) ;
67
63
64
+ it ( 'should throw error if empty BloomFilter has hash count' , ( ) => {
65
+ try {
66
+ new BloomFilter ( new Uint8Array ( 0 ) , 0 , 1 ) ;
67
+ expect . fail ( ) ;
68
+ } catch ( error ) {
69
+ expect (
70
+ ( error as Error ) ?. message . includes (
71
+ 'INTERNAL ASSERTION FAILED: An empty bitmap should correspond to 0 hashCount.'
72
+ )
73
+ ) . to . be . true ;
74
+ }
75
+ try {
76
+ new BloomFilter ( new Uint8Array ( 1 ) , 8 , 1 ) ;
77
+ expect . fail ( ) ;
78
+ } catch ( error ) {
79
+ expect (
80
+ ( error as Error ) ?. message . includes (
81
+ 'INTERNAL ASSERTION FAILED: An empty bitmap should correspond to 0 hashCount.'
82
+ )
83
+ ) . to . be . true ;
84
+ }
85
+ } ) ;
86
+
68
87
it ( 'should throw error if padding is negative' , ( ) => {
69
88
try {
70
- new BloomFilter ( new Uint8Array ( 0 ) , - 1 , 0 ) ;
89
+ new BloomFilter ( new Uint8Array ( 1 ) , - 1 , 1 ) ;
71
90
expect . fail ( ) ;
72
91
} catch ( error ) {
73
92
expect (
@@ -80,7 +99,7 @@ describe('BloomFilter', () => {
80
99
81
100
it ( 'should throw error if bitmap size is negative' , ( ) => {
82
101
try {
83
- new BloomFilter ( new Uint8Array ( 0 ) , 1 , 0 ) ;
102
+ new BloomFilter ( new Uint8Array ( 0 ) , 1 , 1 ) ;
84
103
expect . fail ( ) ;
85
104
} catch ( error ) {
86
105
expect (
@@ -93,7 +112,7 @@ describe('BloomFilter', () => {
93
112
94
113
it ( 'should throw error if hash count is negative' , ( ) => {
95
114
try {
96
- new BloomFilter ( new Uint8Array ( 0 ) , 0 , - 1 ) ;
115
+ new BloomFilter ( new Uint8Array ( 1 ) , 1 , - 1 ) ;
97
116
expect . fail ( ) ;
98
117
} catch ( error ) {
99
118
expect (
@@ -123,17 +142,18 @@ describe('BloomFilter', () => {
123
142
124
143
/**
125
144
* Golden tests are generated by backend based on inserting n number of
126
- * documents path into Bloom filter.
145
+ * documents path into a bloom filter.
127
146
*
128
- * Full documents path is generated by concating documentPrefix and n, ie ,
129
- * projects/project-1/databases/database-1/documents/coll/doc11
147
+ * Full document path is generated by concating documentPrefix and number n ,
148
+ * ie, projects/project-1/databases/database-1/documents/coll/doc12
130
149
*
131
150
* The test result is generated by checking the membership of documents from
132
151
* documentPrefix+0 to documentPrefix+2n. The membership results from 0 to n
133
- * is expected to be 1, and from n to 2n to be 0 with some false positive results.
152
+ * is expected to be true (1), and the membership results from n to 2n is
153
+ * expected to be false (0) with some false positive results (1).
134
154
*
135
- * The test result of BloomFilter.mightContain() should match the backend result
136
- * exactly.
155
+ * The test result of BloomFilter.mightContain() should match the backend
156
+ * result exactly.
137
157
*/
138
158
describe ( 'BloomFilter membership test' , ( ) => {
139
159
const documentPrefix =
@@ -155,7 +175,7 @@ describe('BloomFilter', () => {
155
175
return ByteString . fromBase64String ( encoded ) . toUint8Array ( ) ;
156
176
}
157
177
158
- it ( 'mightContain result for 1 document with 1 false positive rate should match backend result ' , ( ) => {
178
+ it ( 'mightContain result for 1 document with 1 false positive rate' , ( ) => {
159
179
const { bits, hashCount } = testDataCount1Rate1 as TestDataType ;
160
180
const { membershipTestResults } = testResultCount1Rate1 as TestResultType ;
161
181
@@ -171,7 +191,7 @@ describe('BloomFilter', () => {
171
191
expect ( mightContain ) . to . equal ( backendMembershipResult ) ;
172
192
}
173
193
} ) ;
174
- it ( 'mightContain result for 1 document with 0.01 false positive rate should match backend result ' , ( ) => {
194
+ it ( 'mightContain result for 1 document with 0.01 false positive rate' , ( ) => {
175
195
const { bits, hashCount } = testDataCount1Rate01 as TestDataType ;
176
196
const { membershipTestResults } =
177
197
testResultCount1Rate01 as TestResultType ;
@@ -188,7 +208,7 @@ describe('BloomFilter', () => {
188
208
expect ( mightContain ) . to . equal ( backendMembershipResult ) ;
189
209
}
190
210
} ) ;
191
- it ( 'mightContain result for 1 document with 0.0001 false positive rate should match backend result ' , ( ) => {
211
+ it ( 'mightContain result for 1 document with 0.0001 false positive rate' , ( ) => {
192
212
const { bits, hashCount } = testDataCount1Rate0001 as TestDataType ;
193
213
const { membershipTestResults } =
194
214
testResultCount1Rate0001 as TestResultType ;
@@ -205,7 +225,7 @@ describe('BloomFilter', () => {
205
225
expect ( mightContain ) . to . equal ( backendMembershipResult ) ;
206
226
}
207
227
} ) ;
208
- it ( 'mightContain result for 500 documents with 1 false positive rate should match backend result ' , ( ) => {
228
+ it ( 'mightContain result for 500 documents with 1 false positive rate' , ( ) => {
209
229
const { bits, hashCount } = testDataCount500Rate1 as TestDataType ;
210
230
const { membershipTestResults } =
211
231
testResultCount500Rate1 as TestResultType ;
@@ -222,7 +242,7 @@ describe('BloomFilter', () => {
222
242
expect ( mightContain ) . to . equal ( backendMembershipResult ) ;
223
243
}
224
244
} ) ;
225
- it ( 'mightContain result for 500 documents with 0.01 false positive rate should match backend result ' , ( ) => {
245
+ it ( 'mightContain result for 500 documents with 0.01 false positive rate' , ( ) => {
226
246
const { bits, hashCount } = testDataCount500Rate01 as TestDataType ;
227
247
const { membershipTestResults } =
228
248
testResultCount500Rate01 as TestResultType ;
@@ -239,7 +259,7 @@ describe('BloomFilter', () => {
239
259
expect ( mightContain ) . to . equal ( backendMembershipResult ) ;
240
260
}
241
261
} ) ;
242
- it ( 'mightContain result for 500 document with 0.0001 false positive rate should match backend result ' , ( ) => {
262
+ it ( 'mightContain result for 500 document with 0.0001 false positive rate' , ( ) => {
243
263
const { bits, hashCount } = testDataCount500Rate0001 as TestDataType ;
244
264
const { membershipTestResults } =
245
265
testResultCount500Rate0001 as TestResultType ;
@@ -256,7 +276,7 @@ describe('BloomFilter', () => {
256
276
expect ( mightContain ) . to . equal ( backendMembershipResult ) ;
257
277
}
258
278
} ) ;
259
- it ( 'mightContain result for 5000 documents with 1 false positive rate should match backend result ' , ( ) => {
279
+ it ( 'mightContain result for 5000 documents with 1 false positive rate' , ( ) => {
260
280
const { bits, hashCount } = testDataCount5000Rate1 as TestDataType ;
261
281
const { membershipTestResults } =
262
282
testResultCount5000Rate1 as TestResultType ;
@@ -273,7 +293,7 @@ describe('BloomFilter', () => {
273
293
expect ( mightContain ) . to . equal ( backendMembershipResult ) ;
274
294
}
275
295
} ) ;
276
- it ( 'mightContain result for 5000 documenta with 0.01 false positive rate should match backend result ' , ( ) => {
296
+ it ( 'mightContain result for 5000 documenta with 0.01 false positive rate' , ( ) => {
277
297
const { bits, hashCount } = testDataCount5000Rate01 as TestDataType ;
278
298
const { membershipTestResults } =
279
299
testResultCount5000Rate01 as TestResultType ;
@@ -290,7 +310,7 @@ describe('BloomFilter', () => {
290
310
expect ( mightContain ) . to . equal ( backendMembershipResult ) ;
291
311
}
292
312
} ) ;
293
- it ( 'mightContain result for 5000 documenta with 0.0001 false positive rate should match backend result ' , ( ) => {
313
+ it ( 'mightContain result for 5000 documenta with 0.0001 false positive rate' , ( ) => {
294
314
const { bits, hashCount } = testDataCount5000Rate0001 as TestDataType ;
295
315
const { membershipTestResults } =
296
316
testResultCount5000Rate0001 as TestResultType ;
@@ -307,7 +327,7 @@ describe('BloomFilter', () => {
307
327
expect ( mightContain ) . to . equal ( backendMembershipResult ) ;
308
328
}
309
329
} ) ;
310
- it ( 'mightContain result for 50000 documents with 1 false positive rate should match backend result ' , ( ) => {
330
+ it ( 'mightContain result for 50000 documents with 1 false positive rate' , ( ) => {
311
331
const { bits, hashCount } = testDataCount50000Rate1 as TestDataType ;
312
332
const { membershipTestResults } =
313
333
testResultCount50000Rate1 as TestResultType ;
@@ -324,7 +344,7 @@ describe('BloomFilter', () => {
324
344
expect ( mightContain ) . to . equal ( backendMembershipResult ) ;
325
345
}
326
346
} ) ;
327
- it ( 'mightContain result for 50000 documents with 0.01 false positive rate should match backend result ' , ( ) => {
347
+ it ( 'mightContain result for 50000 documents with 0.01 false positive rate' , ( ) => {
328
348
const { bits, hashCount } = testDataCount50000Rate01 as TestDataType ;
329
349
const { membershipTestResults } =
330
350
testResultCount50000Rate01 as TestResultType ;
@@ -341,9 +361,9 @@ describe('BloomFilter', () => {
341
361
expect ( mightContain ) . to . equal ( backendMembershipResult ) ;
342
362
}
343
363
//Extend default timeout(2000)
344
- } ) . timeout ( 5000 ) ;
364
+ } ) . timeout ( 10_000 ) ;
345
365
346
- it ( 'mightContain result for 50000 documents with 0.0001 false positive rate should match backend result ' , ( ) => {
366
+ it ( 'mightContain result for 50000 documents with 0.0001 false positive rate' , ( ) => {
347
367
const { bits, hashCount } = testDataCount50000Rate0001 as TestDataType ;
348
368
const { membershipTestResults } =
349
369
testResultCount50000Rate0001 as TestResultType ;
@@ -360,6 +380,6 @@ describe('BloomFilter', () => {
360
380
expect ( mightContain ) . to . equal ( backendMembershipResult ) ;
361
381
}
362
382
//Extend default timeout(2000)
363
- } ) . timeout ( 5000 ) ;
383
+ } ) . timeout ( 10_000 ) ;
364
384
} ) ;
365
385
} ) ;
0 commit comments