-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patht_predicates_test.go
More file actions
171 lines (159 loc) · 3.21 KB
/
t_predicates_test.go
File metadata and controls
171 lines (159 loc) · 3.21 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
package numstream
import (
"testing"
)
var ints = []int{-99, -2, -1, 0, 1, 2, 99}
func TestTrue(t *testing.T) {
for _, n := range ints {
if !True(n) {
t.Errorf("True(%d) => %v, want %v", n, false, true)
}
}
}
func TestFalse(t *testing.T) {
for _, n := range ints {
if False(n) {
t.Errorf("False(%d) => %v, want %v", n, true, false)
}
}
}
func TestDisjoin(t *testing.T) {
var tests = []struct {
in []Predicate
out bool
}{
{[]Predicate{}, false},
{[]Predicate{True}, true},
{[]Predicate{False}, false},
{[]Predicate{True, False}, true},
{[]Predicate{False, True}, true},
{[]Predicate{False, False, False}, false},
{[]Predicate{False, True, False}, true},
}
for i, r := range tests {
p := Disjoin(r.in...)
for _, n := range ints {
b := p(n)
if b != r.out {
t.Errorf("Disjoin([row %d Predicates]...) => %v, want %v", i, b, r.out)
}
}
}
}
func TestConjoin(t *testing.T) {
var tests = []struct {
in []Predicate
out bool
}{
{[]Predicate{}, true},
{[]Predicate{True}, true},
{[]Predicate{False}, false},
{[]Predicate{True, False}, false},
{[]Predicate{False, True}, false},
{[]Predicate{True, True}, true},
{[]Predicate{True, False, True}, false},
{[]Predicate{True, True, True}, true},
{[]Predicate{False, False, False}, false},
}
for i, r := range tests {
p := Conjoin(r.in...)
for _, n := range ints {
b := p(n)
if b != r.out {
t.Errorf("Conjoin([row %d Predicates]...) => %v, want %v", i, b, r.out)
}
}
}
}
func TestDone(t *testing.T) {
ch := make(chan bool)
isDone := Done(ch)
for _, n := range ints {
if isDone(n) {
t.Errorf("isDone(%d) before signal sent on done channel => false, want true", n)
}
}
ch <- true
for _, n := range ints {
if !isDone(n) {
t.Errorf("isDone(%d) after signal sent on done channel => true, want false", n)
}
}
}
func TestIsLessThan(t *testing.T) {
b := IsLessThan(3, 4)
if b {
t.Errorf("IsLessThan(3, 4) => true, want false")
}
}
func TestIsLessThanX(t *testing.T) {
isLessThan10 := IsLessThanX(10)
if isLessThan10(11) {
t.Errorf("IsLessThan(10)(11) => true, want false")
}
}
func TestIsMultipleOf(t *testing.T) {
b := IsMultipleOf(3, 6)
if !b {
t.Error("6 is a multiple of 3")
}
}
func TestIsMultipleOfX(t *testing.T) {
var tests = []struct {
multiple int
value int
out bool
}{
{2, 2, true},
{2, 3, false},
{2, 4, true},
{3, 1, false},
{3, 2, false},
{3, 3, true},
{3, 4, false},
{3, 6, true},
{3, 9, true},
{10, 200, true},
{4, 1024, true},
}
for _, r := range tests {
p := IsMultipleOfX(r.multiple)
b := p(r.value)
if b != r.out {
t.Errorf("IsMultipleOf(%d)(%d) => %v, want %v", r.multiple, r.value, b, r.out)
}
}
}
func TestIsPalindrome(t *testing.T) {
var tests = []struct {
in int
out bool
}{
{1, true},
{2, true},
{3, true},
{4, true},
{5, true},
{6, true},
{7, true},
{8, true},
{9, true},
{10, false},
{11, true},
{12, false},
{99, true},
{100, false},
{101, true},
{9889, true},
{9989, false},
{6543456, true},
{10999901, true},
{76535677, false},
}
for _, r := range tests {
b := IsPalindrome(r.in)
if b != r.out {
t.Errorf("IsPalindrome(%d) => %v, want %v", r.in, b, r.out)
}
}
}