@@ -160,6 +160,60 @@ func BenchmarkFilter_Lookup(b *testing.B) {
160160 }
161161}
162162
163+ func TestDelete (t * testing.T ) {
164+ cf := NewFilter (8 )
165+ cf .Insert ([]byte ("one" ))
166+ cf .Insert ([]byte ("two" ))
167+ cf .Insert ([]byte ("three" ))
168+
169+ testCases := []struct {
170+ word string
171+ want bool
172+ }{
173+ {"four" , false },
174+ {"five" , false },
175+ {"one" , true },
176+ {"two" , true },
177+ {"three" , true },
178+ }
179+ for _ , tc := range testCases {
180+ t .Run (fmt .Sprintf ("cf.Delete(%q)" , tc .word ), func (t * testing.T ) {
181+ if got := cf .Delete ([]byte (tc .word )); got != tc .want {
182+ t .Errorf ("cf.Delete(%q) got %v, want %v" , tc .word , got , tc .want )
183+ }
184+ })
185+ }
186+ }
187+
188+ func TestDeleteMultipleSame (t * testing.T ) {
189+ cf := NewFilter (4 )
190+ for i := 0 ; i < 5 ; i ++ {
191+ cf .Insert ([]byte ("some_item" ))
192+ }
193+
194+ testCases := []struct {
195+ word string
196+ want bool
197+ wantCount uint
198+ }{
199+ {"missing" , false , 5 },
200+ {"missing2" , false , 5 },
201+ {"some_item" , true , 4 },
202+ {"some_item" , true , 3 },
203+ {"some_item" , true , 2 },
204+ {"some_item" , true , 1 },
205+ {"some_item" , true , 0 },
206+ {"some_item" , false , 0 },
207+ }
208+ for _ , tc := range testCases {
209+ t .Run (fmt .Sprintf ("cf.Delete(%q)" , tc .word ), func (t * testing.T ) {
210+ if got , gotCount := cf .Delete ([]byte (tc .word )), cf .Count (); got != tc .want || gotCount != tc .wantCount {
211+ t .Errorf ("cf.Delete(%q) = %v, count = %d; want %v, count = %d" , tc .word , got , gotCount , tc .want , tc .wantCount )
212+ }
213+ })
214+ }
215+ }
216+
163217func TestEncodeDecode (t * testing.T ) {
164218 cf := NewFilter (10 )
165219 cf .Insert ([]byte {1 })
0 commit comments