Commit ed79d29a authored by Petar Maymounkov's avatar Petar Maymounkov

Add intersection tests: random and read from JSON.

parent ca509f6c
package trie package trie
import ( import (
"encoding/json"
"math/rand" "math/rand"
"testing" "testing"
...@@ -9,7 +10,7 @@ import ( ...@@ -9,7 +10,7 @@ import (
func TestIntersectRandom(t *testing.T) { func TestIntersectRandom(t *testing.T) {
for i := 0; i < 100; i++ { for i := 0; i < 100; i++ {
testIntersect(t, randomTestIntersectSample(10, 10, 5)) testIntersect(t, randomTestIntersectSample(10, 21, 7))
} }
} }
...@@ -19,6 +20,13 @@ func TestIntersect(t *testing.T) { ...@@ -19,6 +20,13 @@ func TestIntersect(t *testing.T) {
} }
} }
func TestIntersectFromJSON(t *testing.T) {
for _, json := range testIntersectJSONSamples {
s := testIntersectSampleFromJSON(json)
testIntersect(t, s)
}
}
func testIntersect(t *testing.T, sample *testIntersectSample) { func testIntersect(t *testing.T, sample *testIntersectSample) {
left, right, expected := New(), New(), New() left, right, expected := New(), New(), New()
for _, l := range sample.LeftKeys { for _, l := range sample.LeftKeys {
...@@ -65,6 +73,14 @@ type testIntersectSample struct { ...@@ -65,6 +73,14 @@ type testIntersectSample struct {
RightKeys []key.Key RightKeys []key.Key
} }
func testIntersectSampleFromJSON(srcJSON string) *testIntersectSample {
s := &testIntersectSample{}
if err := json.Unmarshal([]byte(srcJSON), s); err != nil {
panic(err)
}
return s
}
var testIntersectSamples = []*testIntersectSample{ var testIntersectSamples = []*testIntersectSample{
{ {
LeftKeys: []key.Key{{1, 2, 3}}, LeftKeys: []key.Key{{1, 2, 3}},
...@@ -79,3 +95,24 @@ var testIntersectSamples = []*testIntersectSample{ ...@@ -79,3 +95,24 @@ var testIntersectSamples = []*testIntersectSample{
RightKeys: []key.Key{{2, 11, 17, 19, 23}}, RightKeys: []key.Key{{2, 11, 17, 19, 23}},
}, },
} }
var testIntersectJSONSamples = []string{
`
{
"LeftKeys": [
"gAlMTjoCy6ZDZFN/0okF65fxscCLVxnQhlJsyfp6uWU=",
"IOZLVCi+OWdUqu0N7DX9T6sweK6RffGnBChy3I3G424=",
"yIsHasiWkbMESfShoZ5yvS4fv6m0KnBSV6emNyMgYrg=",
"qAISv6yZjs3WWlDC89iJUSdq45F0D/1y9fLnsPvavdA=",
"aOl3hzLR2jArVpbEWaLOjH4QqoUo/7pJlmbY1mCHgYI=",
"6P28fa97aZOOImD9TGO+x2+XJbzPSEh5rP6NqKoDj88=",
"2Lh4bHSBoSvqloX+v7IYMvmq0k0bUcYAkQesOUPxLVo=",
"eLqLdLjusZJlqDZT94U0PC4bdVQeUNaGwkOn9i5KRoI="
],
"RightKeys": [
"gAlMTjoCy6ZDZFN/0okF65fxscCLVxnQhlJsyfp6uWU=",
"qAISv6yZjs3WWlDC89iJUSdq45F0D/1y9fLnsPvavdA="
]
}
`,
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment