forked from leon-richardt/jaf
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathset_test.go
More file actions
75 lines (60 loc) · 1.42 KB
/
set_test.go
File metadata and controls
75 lines (60 loc) · 1.42 KB
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
package main
import (
"math/rand"
"testing"
"time"
)
func TestContains(t *testing.T) {
set := NewSet()
// Oracle testing
dummy := 0
in := set.Contains(dummy)
if in {
t.Errorf("oracle > set.Contains(%d) = true before insertion", dummy)
}
set.Insert(dummy)
in = set.Contains(dummy)
if !in {
t.Errorf("oracle > set.Contains(%d) = false after insertion", dummy)
}
// Property testing
rand.Seed(time.Now().UnixNano())
const reps = 1000
for i := 0; i < reps; i++ {
lastInsert := rand.Int()
set.Insert(lastInsert)
in = set.Contains(lastInsert)
if !in {
t.Errorf("property > set.Contains(%d) = false after insertion", dummy)
}
}
}
func TestInsert(t *testing.T) {
set := NewSet()
// Oracle testing
dummy := 0
innovative := set.Insert(dummy)
if !innovative {
t.Errorf("oracle > set.Insert(%d) = false but was innovative", dummy)
}
in := set.Contains(dummy)
if !in {
t.Errorf("oracle > set.Contains(%d) = false after insertion", dummy)
}
// Duplicate insertion should return false
innovative = set.Insert(dummy)
if innovative {
t.Errorf("oracle > set.Insert(%d) = true but was not innovative", dummy)
}
// Property testing
rand.Seed(time.Now().UnixNano())
const reps = 1000
for i := 0; i < reps; i++ {
val := rand.Int()
inBefore := set.Contains(val)
innovative = set.Insert(val)
if inBefore && innovative {
t.Errorf("property > included value reported as innovative")
}
}
}