github.com/MetalBlockchain/metalgo@v1.11.9/pubsub/bloom/filter_test.go (about) 1 // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 // See the file LICENSE for licensing terms. 3 4 package bloom 5 6 import ( 7 "testing" 8 9 "github.com/stretchr/testify/require" 10 11 "github.com/MetalBlockchain/metalgo/utils/units" 12 ) 13 14 func TestNew(t *testing.T) { 15 var ( 16 require = require.New(t) 17 maxN = 10000 18 p = 0.1 19 maxBytes = 1 * units.MiB // 1 MiB 20 ) 21 f, err := New(maxN, p, maxBytes) 22 require.NoError(err) 23 require.NotNil(f) 24 25 f.Add([]byte("hello")) 26 27 checked := f.Check([]byte("hello")) 28 require.True(checked, "should have contained the key") 29 30 checked = f.Check([]byte("bye")) 31 require.False(checked, "shouldn't have contained the key") 32 }