mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-04-18 21:45:48 +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")
|
||
|
|
}
|
||
|
|
}
|