mirror of
https://github.com/luxfi/cache.git
synced 2026-09-24 00:24:18 +00:00
35 lines
700 B
Go
35 lines
700 B
Go
// Copyright (C) 2019-2025, Lux Industries, Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package bloom
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/luxfi/constants"
|
|
"github.com/luxfi/ids"
|
|
)
|
|
|
|
func TestCollisionResistance(t *testing.T) {
|
|
require := require.New(t)
|
|
|
|
f, err := New(8, 16*constants.KiB)
|
|
require.NoError(err)
|
|
|
|
Add(f, []byte("hello world?"), []byte("so salty"))
|
|
collision := Contains(f, []byte("hello world!"), []byte("so salty"))
|
|
require.False(collision)
|
|
}
|
|
|
|
func BenchmarkHash(b *testing.B) {
|
|
key := ids.GenerateTestID()
|
|
salt := ids.GenerateTestID()
|
|
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
Hash(key[:], salt[:])
|
|
}
|
|
}
|