Commit 1ec50265 authored by Petar Maymounkov's avatar Petar Maymounkov

Add test for order-independence of mutable addition.

parent ed79d29a
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
} }
......
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