mirror of
https://github.com/XTLS/Xray-core.git
synced 2026-05-08 14:13:22 +00:00
34 lines
610 B
Go
34 lines
610 B
Go
package antireplay
|
|
|
|
import (
|
|
"bufio"
|
|
"crypto/rand"
|
|
"testing"
|
|
)
|
|
|
|
func BenchmarkMapFilter(b *testing.B) {
|
|
filter := NewMapFilter[[16]byte](120)
|
|
var sample [16]byte
|
|
reader := bufio.NewReader(rand.Reader)
|
|
reader.Read(sample[:])
|
|
b.ResetTimer()
|
|
for range b.N {
|
|
reader.Read(sample[:])
|
|
filter.Check(sample)
|
|
}
|
|
}
|
|
|
|
func TestMapFilter(t *testing.T) {
|
|
filter := NewMapFilter[[16]byte](120)
|
|
var sample [16]byte
|
|
rand.Read(sample[:])
|
|
filter.Check(sample)
|
|
if filter.Check(sample) {
|
|
t.Error("Unexpected true negative")
|
|
}
|
|
sample[0]++
|
|
if !filter.Check(sample) {
|
|
t.Error("Unexpected false positive")
|
|
}
|
|
}
|