Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
p2p
go-p2p-xor
Commits
ed79d29a
Commit
ed79d29a
authored
Mar 26, 2020
by
Petar Maymounkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add intersection tests: random and read from JSON.
parent
ca509f6c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
1 deletion
+38
-1
trie/intersect_test.go
trie/intersect_test.go
+38
-1
No files found.
trie/intersect_test.go
View file @
ed79d29a
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
,
1
0
,
5
))
testIntersect
(
t
,
randomTestIntersectSample
(
10
,
2
1
,
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="
]
}
`
,
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment