refactor-for-testability (#3)
Co-authored-by: jdl <jdl@desktop> Co-authored-by: jdl <jdl@crumpington.com> Reviewed-on: #3
This commit is contained in:
57
peer/dupcheck_test.go
Normal file
57
peer/dupcheck_test.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package peer
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestDupCheck(t *testing.T) {
|
||||
dc := newDupCheck(0)
|
||||
|
||||
for i := range bitSetSize {
|
||||
if dc.IsDup(uint64(i)) {
|
||||
t.Fatal("!")
|
||||
}
|
||||
}
|
||||
|
||||
type TestCase struct {
|
||||
Counter uint64
|
||||
Dup bool
|
||||
}
|
||||
|
||||
testCases := []TestCase{
|
||||
{511, true},
|
||||
{0, true},
|
||||
{1, true},
|
||||
{2, true},
|
||||
{3, true},
|
||||
{63, true},
|
||||
{256, true},
|
||||
{510, true},
|
||||
{511, true},
|
||||
{512, false},
|
||||
{0, true},
|
||||
{512, true},
|
||||
{513, false},
|
||||
{517, false},
|
||||
{512, true},
|
||||
{513, true},
|
||||
{514, false},
|
||||
{515, false},
|
||||
{516, false},
|
||||
{517, true},
|
||||
{2512, false},
|
||||
{2512, true},
|
||||
{2001, true},
|
||||
{2002, false},
|
||||
{2002, true},
|
||||
{4000, false},
|
||||
{4000 - 511, true}, // Too old.
|
||||
{4000 - 510, false}, // Just in the window.
|
||||
}
|
||||
|
||||
for i, tc := range testCases {
|
||||
if ok := dc.IsDup(tc.Counter); ok != tc.Dup {
|
||||
t.Fatal(i, ok, tc)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user