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
1ec50265
Commit
1ec50265
authored
Mar 26, 2020
by
Petar Maymounkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add test for order-independence of mutable addition.
parent
ed79d29a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
0 deletions
+20
-0
trie/add_test.go
trie/add_test.go
+20
-0
No files found.
trie/add_test.go
View file @
1ec50265
package
trie
package
trie
import
(
import
(
"math/rand"
"testing"
"testing"
"github.com/libp2p/go-libp2p-xor/key"
"github.com/libp2p/go-libp2p-xor/key"
...
@@ -21,6 +22,25 @@ func TestMutableAndImmutableAddSame(t *testing.T) {
...
@@ -21,6 +22,25 @@ func TestMutableAndImmutableAddSame(t *testing.T) {
}
}
}
}
func
TestAddIsOrderIndependent
(
t
*
testing
.
T
)
{
for
_
,
s
:=
range
testAddSameSamples
{
base
:=
New
()
for
_
,
k
:=
range
s
.
Keys
{
base
.
Add
(
k
)
}
for
j
:=
0
;
j
<
100
;
j
++
{
perm
:=
rand
.
Perm
(
len
(
s
.
Keys
))
reordered
:=
New
()
for
i
:=
range
s
.
Keys
{
reordered
.
Add
(
s
.
Keys
[
perm
[
i
]])
}
if
!
Equal
(
base
,
reordered
)
{
t
.
Errorf
(
"trie %v differs from trie %v"
,
base
,
reordered
)
}
}
}
}
type
testAddSameSample
struct
{
type
testAddSameSample
struct
{
Keys
[]
key
.
Key
Keys
[]
key
.
Key
}
}
...
...
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