-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgopherwood_test.go
87 lines (71 loc) · 1.49 KB
/
gopherwood_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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package gopherwood
import (
"fmt"
"math/rand"
"sync"
"testing"
)
func TestNothing(t *testing.T) {}
func TestSearch(t *testing.T) {
rand.Seed(boringRandomSeed)
noKeys := 100
keySize := 30
keys := make([]string, noKeys)
tree := Tree{}
for n := 0; n < noKeys; n++ {
k := randStringBytesRmndr(keySize)
keys[n] = k
tree.Add(k)
}
for n := 0; n < noKeys; n++ {
k := keys[n]
got := tree.Search(k)
if k != got {
t.Error("want", k, "but got", got)
}
}
}
func TestConcurrentSearch1pct(t *testing.T) {
rand.Seed(boringRandomSeed)
noKeys := 15
keySize := 30
keys := make([]string, noKeys)
tree := Tree{}
for n := 0; n < noKeys; n++ {
k := randStringBytesRmndr(keySize)
keys[n] = k
tree.Add(k)
}
//noSearchers := 1 * noKeys / 100
noSearchers := 2
var wg sync.WaitGroup
wg.Add(noSearchers)
sliceSize := noKeys / noSearchers
fmt.Println("noKeys: ", noKeys)
fmt.Println("noSearchers: ", noSearchers)
fmt.Println("sliceSize: ", sliceSize)
for n := 0; n < noSearchers; n++ {
go func(n int) {
base := n * sliceSize
for m := 0; m < sliceSize; m++ {
fmt.Println("n: ", n, "base: ", base, "base+m: ", base+m)
key := keys[base+m]
fmt.Println(key)
got := tree.Search(key)
if key != got {
t.Error("want", key, "but got", got)
}
}
wg.Done()
}(n)
}
wg.Wait()
fmt.Println("wow")
}
func BenchmarkGopherwoodAdd(b *testing.B) {
rand.Seed(boringRandomSeed)
t := Tree{}
for n := 0; n < b.N; n++ {
t.Add(randStringBytesRmndr(b.N))
}
}