-
Notifications
You must be signed in to change notification settings - Fork 4
/
random_tree_test.go
47 lines (41 loc) · 1.02 KB
/
random_tree_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package ssp
import "testing"
func TestRandomGenerate(t *testing.T) {
numBytes := 16
tree, err := NewRandomTree(numBytes)
if err != nil {
t.Fatalf("Error creating tree: %v", err)
}
nut, err := tree.Nut()
if err != nil {
t.Fatalf("Error creating nut: %v", err)
}
if checkByteSize(nut) != numBytes {
t.Fatalf("Wrong size expected %d but got %d", numBytes, checkByteSize(nut))
}
}
func TestRandomUniqueGenerate(t *testing.T) {
numBytes := 8
tree, err := NewRandomTree(numBytes)
if err != nil {
t.Fatalf("Error creating tree: %v", err)
}
values := make(map[Nut]struct{}, 10)
for i := 0; i < 10; i++ {
nut, err := tree.Nut()
if err != nil {
t.Fatalf("Error creating nut: %v", err)
}
if checkByteSize(nut) != numBytes {
t.Fatalf("Wrong size expected %d but got %d", numBytes, checkByteSize(nut))
}
if _, ok := values[nut]; ok {
t.Fatalf("Found duplicate %v", nut)
}
values[nut] = struct{}{}
}
}
func checkByteSize(nut Nut) int {
bytes, _ := Sqrl64.DecodeString(string(nut))
return len(bytes)
}