/
set_test.go
65 lines (55 loc) · 1.04 KB
/
set_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
package set
import (
"fmt"
"rand"
"testing"
)
const (
ELEM_TEST_TRIES = 10
UNION_TEST_TRIES = 10
)
func randomizeSet(n int) *IntTreap {
s := Init([]int{})
for i := 0; i < n; i++ {
p := rand.Int()
s = s.Insert(p)
}
return s
}
func TestSanity (t *testing.T) {
fmt.Printf("this works!\n")
}
func TestAddElem (test *testing.T) {
fmt.Printf("Testing TestElem...\n")
s := Init([]int{})
for i := 0; i < ELEM_TEST_TRIES; i++ {
p := rand.Int()
s = s.Insert(p)
if !s.Elem(p) {
test.Fail()
}
}
}
func TestUnion (test *testing.T) {
s := randomizeSet(UNION_TEST_TRIES)
t := randomizeSet(UNION_TEST_TRIES)
u := s.Union(t)
u.Display()
}
func TestParUnion (test *testing.T) {
fmt.Printf("Testing parallelized union...")
s := randomizeSet(UNION_TEST_TRIES)
t := randomizeSet(UNION_TEST_TRIES)
u := s.UnionPar(t)
u.Display()
}
func BenchmarkUnion (b *testing.B) {
s := randomizeSet(b.N)
t := randomizeSet(b.N)
s.Union(t)
}
func BenchmarkParUnion (b *testing.B) {
s := randomizeSet(b.N)
t := randomizeSet(b.N)
s.UnionPar(t)
}