-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquantifier_test.go
86 lines (77 loc) · 1.86 KB
/
quantifier_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
package quango_test
import (
. "github.com/totherme/quango"
)
var _ = Describe("Quango quantifiers", func() {
Describe("for all", func() {
Context("when called on an empty list", func() {
It("doesn't call the body", func() {
list := make([]int, 0)
ForAll(list, func(_ int) bool {
Fail("This shouldn't be called")
return false
})
})
It("returns true", func() {
list := make([]int, 0)
Expect(ForAll(list, func(_ int) bool {
return false
})).To(BeTrue())
})
})
Context("when called on a list of length n ", func() {
Context("with a true body", func() {
It("calls the body n times", func() {
Expect(func(list []int) bool {
n := len(list)
count := 0
ForAll(list, func(_ int) bool {
count++
return true
})
return count == n
}).To(Hold())
})
})
Context("with a false body", func() {
It("calls the body only once", func() {
Expect(func(list []int) bool {
if len(list) == 0 {
return true
}
count := 0
ForAll(list, func(_ int) bool {
count++
return false
})
return count == 1
}).To(Hold())
})
})
})
Context("when called with a body that returns true", func() {
It("returns true", func() {
list := make([]int, 1)
Expect(ForAll(list, func(_ int) bool {
return true
})).To(BeTrue())
})
})
Context("when called with a body that returns false", func() {
It("returns false", func() {
list := make([]int, 1)
Expect(ForAll(list, func(_ int) bool {
return false
})).To(BeFalse())
})
})
Context("when called with a body that sometimes returns true, and sometimes false", func() {
It("returns false", func() {
list := []int{1, 0, 1, 0, 1, 0}
Expect(ForAll(list, func(n int) bool {
return n == 0
})).To(BeFalse())
})
})
})
})