-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest_waldo.py
140 lines (109 loc) · 5.47 KB
/
test_waldo.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
126
127
128
129
130
131
132
133
134
135
136
"""Universal and existential quantifiers """
import unittest
from waldo import *
class TestAE(unittest.TestCase):
"""For all x, there exists y . P(y)"""
# By row
def test_exists_waldo_every_row(self):
"""For all rows in matrix, there exists a Waldo in the row"""
self.assertTrue(all_row_exists_waldo([[Other, Other, Waldo],
[Waldo, Other, Other],
[Waldo, Waldo, Waldo]]))
self.assertFalse(all_row_exists_waldo([[Other, Other, Waldo],
[Other, Other, Other],
[Waldo, Waldo, Waldo]]))
# Vacuous: No rows
self.assertTrue(all_row_exists_waldo([]))
# Vacuous: No columns
self.assertFalse(all_row_exists_waldo([[],[]]))
# By column
def test_exists_waldo_every_col(self):
"""For all columns in the matrix, there exists a Waldo in the column"""
self.assertTrue(all_col_exists_waldo([[Other, Waldo, Other],
[Waldo, Other, Other],
[Other, Waldo, Waldo]]))
self.assertFalse(all_col_exists_waldo([[Waldo, Other, Other],
[Other, Waldo, Other],
[Waldo, Other, Other]]))
# Vacuous: No rows
self.assertTrue(all_col_exists_waldo([]))
# Vacuous: No columns
self.assertTrue(all_col_exists_waldo([[],[]]))
class TestAA(unittest.TestCase):
"""For all x, for all y . P(y)"""
# By row
def test_all_row_all_waldo(self):
self.assertTrue(all_row_all_waldo([[Waldo, Waldo, Waldo],
[Waldo, Waldo, Waldo],
[Waldo, Waldo, Waldo]]))
self.assertFalse(all_row_all_waldo([[Waldo, Waldo, Waldo, Waldo],
[Waldo, Waldo, Other, Waldo],
[Waldo, Waldo, Waldo, Waldo]]))
# Vacuous: No rows
self.assertTrue(all_row_all_waldo([]))
# Vacuous: No columns
self.assertTrue(all_row_all_waldo([[], [], []]))
# By col
def test_all_col_all_waldo(self):
self.assertTrue(all_col_all_waldo([[Waldo, Waldo, Waldo],
[Waldo, Waldo, Waldo],
[Waldo, Waldo, Waldo]]))
self.assertFalse(all_col_all_waldo([[Waldo, Waldo, Waldo, Waldo],
[Waldo, Waldo, Other, Waldo],
[Waldo, Waldo, Waldo, Waldo]]))
# Vacuous: No rows
self.assertTrue(all_row_all_waldo([]))
# Vacuous: No columns
self.assertTrue(all_row_all_waldo([[], [], []]))
class TestEE(unittest.TestCase):
"""There exists x such that there exists y . P(y)"""
# By row
def test_exists_row_exists_waldo(self):
self.assertTrue(exists_row_exists_waldo([[Other, Other, Other],
[Other, Other, Waldo],
[Other, Other, Other]]))
self.assertFalse(exists_row_exists_waldo([[Other, Other],
[Other, Other]]))
# Vacuous: No rows
self.assertFalse(exists_row_exists_waldo([]))
# Vacuous: No columns
self.assertFalse(exists_row_exists_waldo([[], []]))
# By column
def test_exists_col_exists_waldo(self):
self.assertTrue(exists_col_exists_waldo([[Other, Other, Other],
[Other, Other, Waldo],
[Other, Other, Other]]))
self.assertFalse(exists_col_exists_waldo([[Other, Other],
[Other, Other]]))
# Vacuous: No rows
self.assertFalse(exists_col_exists_waldo([]))
# Vacuous: No columns
self.assertFalse(exists_col_exists_waldo([[], []]))
class TestEA(unittest.TestCase):
"""There exists x such that all y . P(y)"""
# By row
def test_exists_row_all_waldo(self):
self.assertTrue(exists_row_all_waldo([[Other, Waldo, Other],
[Waldo, Waldo, Waldo],
[Other, Other, Other]]))
self.assertFalse(exists_row_all_waldo([[Waldo, Other, Waldo],
[Waldo, Other, Waldo],
[Other, Waldo, Waldo]]))
#Vacuous: No rows
self.assertFalse(exists_row_all_waldo([]))
#Vacuous: No columns
self.assertTrue(exists_row_all_waldo([[], []]))
# By column
def tests_exists_col_all_waldo(self):
self.assertTrue(exists_col_all_waldo([[Other, Waldo, Other],
[Waldo, Waldo, Other],
[Other, Waldo, Waldo]]))
self.assertFalse(exists_col_all_waldo([[Waldo, Waldo, Waldo],
[Waldo, Other, Waldo],
[Other, Waldo, Other]]))
# Vacuous: No rows
self.assertFalse(exists_col_all_waldo([]))
# Vacuous: No columns
self.assertFalse(exists_col_all_waldo([[], []]))
if __name__ == "__main__":
unittest.main()