-
Notifications
You must be signed in to change notification settings - Fork 311
/
Copy pathtest_predicates.py
125 lines (102 loc) · 3.48 KB
/
test_predicates.py
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
import doctest
import pytest
from datascience import predicates
from datascience import *
def test_both():
"""Both f and g."""
p = are.above(2) & are.below(4)
ps = [p(x) for x in range(1, 6)]
assert ps == [False, False, True, False, False]
def test_tautology():
p = are.above(3) | are.below(4)
ps = [p(x) for x in range(1, 6)]
assert ps == [True, True, True, True, True]
def test_contradiction():
p = are.above(3) & are.below(3)
ps = [p(x) for x in range(1, 6)]
assert ps == [False, False, False, False, False]
def test_either():
"""Either f or g."""
p = are.above(3) | are.below(2)
ps = [p(x) for x in range(1, 6)]
assert ps == [True, False, False, True, True]
def test_equal_to():
"""Equal to y."""
p = are.equal_to(1)
ps = [p(x) for x in range(1, 6)]
assert ps == [True, False, False, False, False]
def test_above():
"""Greater than y."""
p = are.above(3)
ps = [p(x) for x in range(1, 6)]
assert ps == [False, False, False, True, True]
def test_below():
"""Less than y."""
p = are.not_below(4)
ps = [p(x) for x in range(1, 6)]
assert ps == [False, False, False, True, True]
def test_above_or_equal_to():
"""Greater than or equal to y."""
p = are.above_or_equal_to(4)
ps = [p(x) for x in range(1, 6)]
assert ps == [False, False, False, True, True]
def test_below_or_equal_to():
"""Less than or equal to y."""
p = are.not_below_or_equal_to(3)
ps = [p(x) for x in range(1, 6)]
assert ps == [False, False, False, True, True]
def test_strictly_between():
"""Greater than y and less than z."""
p = are.strictly_between(2, 4)
ps = [p(x) for x in range(1, 6)]
assert ps == [False, False, True, False, False]
def test_between():
"""Greater than or equal to y and less than z."""
p = are.between(3, 4)
ps = [p(x) for x in range(1, 6)]
assert ps == [False, False, True, False, False]
def test_between_or_equal_to():
"""Greater than or equal to y and less than or equal to z."""
p = are.between_or_equal_to(3, 3)
ps = [p(x) for x in range(1, 6)]
assert ps == [False, False, True, False, False]
#############
# Aliases #
#############
def test_greater_than_and_less_than():
"""Both f and g."""
p = are.greater_than(2) & are.less_than(4)
ps = [p(x) for x in range(1, 6)]
assert ps == [False, False, True, False, False]
def test_greater_than_or_less_than():
"""Either f or g."""
p = are.greater_than(3) | are.less_than(2)
ps = [p(x) for x in range(1, 6)]
assert ps == [True, False, False, True, True]
def test_greater_than():
"""Greater than y."""
p = are.greater_than(3)
ps = [p(x) for x in range(1, 6)]
assert ps == [False, False, False, True, True]
def test_less_than():
"""Less than y."""
p = are.not_less_than(4)
ps = [p(x) for x in range(1, 6)]
assert ps == [False, False, False, True, True]
def test_greater_than_or_equal_to():
"""Greater than or equal to y."""
p = are.greater_than_or_equal_to(4)
ps = [p(x) for x in range(1, 6)]
assert ps == [False, False, False, True, True]
def test_less_than_or_equal_to():
"""Less than or equal to y."""
p = are.not_less_than_or_equal_to(3)
ps = [p(x) for x in range(1, 6)]
assert ps == [False, False, False, True, True]
############
# Doctests #
############
def test_doctests():
results = doctest.testmod(predicates,
optionflags=doctest.NORMALIZE_WHITESPACE)
assert results.failed == 0