v8.run/go/exp@v0.0.26-0.20230226010534-afcdbd3f782d/hash/hashutil/bloom/bloomf_test.go (about) 1 package bloom 2 3 import ( 4 "testing" 5 ) 6 7 func TestBloom(t *testing.T) { 8 t.Run("bloom-3", func(t *testing.T) { 9 var list = []string{ 10 "apple", 11 "banana", 12 "cherry", 13 } 14 bf := NewBloom(uint64(len(list)), 0.01) 15 for _, s := range list { 16 bf.SetString(s) 17 } 18 19 for _, s := range list { 20 if !bf.GetString(s) { 21 t.Errorf("TestString(%q) = false, want true", s) 22 } 23 } 24 }) 25 } 26 27 func BenchmarkBloom(b *testing.B) { 28 var list = []string{ 29 "apple", 30 "banana", 31 "cherry", 32 "golang", 33 "python", 34 "ruby", 35 "rust", 36 "java", 37 } 38 bf := NewBloom(uint64(len(list)), 0.01) 39 for _, s := range list { 40 bf.SetString(s) 41 } 42 43 b.ResetTimer() 44 for i := 0; i < b.N; i++ { 45 bf.GetString("apple") 46 } 47 }