-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
218 lines (182 loc) · 6.78 KB
/
tests.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
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
import unittest
import rowop
import re
class add_row_tests(unittest.TestCase):
def test_one(self):
a = [[1]]
expected = [[2]]
actual = rowop.add_row(a,1,1,1)
self.failUnless(actual == expected)
def test_two(self):
a = [[1],[1]]
expected = [[2],[1]]
actual = rowop.add_row(a,2,1,1)
self.failUnless(actual == expected)
def test_three(self):
a = [[rowop.F(-1) for xi in range(3)] for x in range(3)]
expected = [[-2,-2,-2],[-1,-1,-1],[-1,-1,-1]]
actual = rowop.add_row(a,2,1,1)
self.failUnless(actual == expected)
def test_four(self):
a = [[rowop.F(1,2) for xi in range(10)] for x in range(2)]
expected = [[1 for xi in range(10)],[rowop.F(1,2) for x in range(10)]]
actual = rowop.add_row(a,2,1,1)
self.failUnless(actual == expected)
class subtract_row_tests(unittest.TestCase):
def test_one(self):
a = [[1]]
expected = [[0]]
actual = rowop.subtract_row(a,1,1,1)
self.failUnless(actual == expected)
def test_two(self):
a = [[1],[1]]
expected = [[0],[1]]
actual = rowop.subtract_row(a,2,1,1)
self.failUnless(actual == expected)
def test_three(self):
a = [[1, -1, rowop.F(-1,2)],[1,1,1]]
expected = [[0,-2,rowop.F(-3,2)],[1,1,1]]
actual = rowop.subtract_row(a,2,1,1)
self.failUnless(actual == expected)
class swap_row_tests(unittest.TestCase):
def test_one(self):
a = [[1],[0]]
expected = [[0],[1]]
actual = rowop.swap_rows(a,1,2)
self.failUnless(actual == expected)
def test_two(self):
a = [[1],[9],[0]]
expected = [[0],[9],[1]]
actual = rowop.swap_rows(a,1,3)
self.failUnless(actual == expected)
def test_three(self):
""" Same as test_two, but with flipped rows in input"""
a = [[1],[9],[0]]
expected = [[0],[9],[1]]
actual = rowop.swap_rows(a,3,1)
self.failUnless(actual == expected)
class scale_row_tests(unittest.TestCase):
def test_one(self):
a = [[1]]
expected = [[2]]
actual = rowop.scale_row(a, 1, 2)
self.failUnless(actual == expected)
def test_two(self):
a = [[1]]
expected = [[rowop.F(1,7)]]
actual = rowop.scale_row(a, 1, rowop.F(1,7))
self.failUnless(actual == expected)
class frac_to_string_tests(unittest.TestCase):
def test_one(self):
expected = "\\frac{2}{3}"
actual = rowop.frac_to_latex(rowop.F(2,3))
self.failUnless(actual == expected)
def test_two(self):
expected = "1"
actual = rowop.frac_to_latex(rowop.F(2,2))
self.failUnless(actual == expected)
def test_three(self):
expected = "\\frac{-2}{3}"
actual = rowop.frac_to_latex(rowop.F(-2,3))
self.failUnless(actual == expected)
def test_four(self):
expected = "-17"
actual = rowop.frac_to_latex(rowop.F(-17,1))
self.failUnless(actual == expected)
class op_string_tests(unittest.TestCase):
def test_one(self):
string_multiplier = ""
row1 = 1
row2 = 2
operation = "+"
expected = "\\mathbf{r}_1 + \\mathbf{r}_2 \\to \\mathbf{r}_2"
actual = rowop.create_op_string(string_multiplier, row1, row2, operation)
self.failUnless(actual == expected)
def test_two(self):
string_multiplier = ""
row1 = 2
row2 = 1
operation = "+"
expected = "\\mathbf{r}_2 + \\mathbf{r}_1 \\to \\mathbf{r}_1"
actual = rowop.create_op_string(string_multiplier, row1, row2, operation)
self.failUnless(actual == expected)
def test_three(self):
string_multiplier = "-1"
row1 = 1
row2 = 2
operation = "+"
expected = "-\\mathbf{r}_1 + \\mathbf{r}_2 \\to \\mathbf{r}_2"
actual = rowop.create_op_string(string_multiplier, row1, row2, operation)
self.failUnless(actual == expected)
def test_three_2(self):
string_multiplier = "1"
row1 = 1
row2 = 2
operation = "+"
expected = "\\mathbf{r}_1 + \\mathbf{r}_2 \\to \\mathbf{r}_2"
actual = rowop.create_op_string(string_multiplier, row1, row2, operation)
self.failUnless(actual == expected)
def test_four(self):
string_multiplier = rowop.frac_to_latex(rowop.F(-1,17))
row1 = 1
row2 = 2
operation = "+"
expected = "\\frac{-1}{17}\\mathbf{r}_1 + \\mathbf{r}_2 \\to \\mathbf{r}_2"
actual = rowop.create_op_string(string_multiplier, row1, row2, operation)
self.failUnless(actual == expected)
def test_five(self):
string_multiplier = rowop.frac_to_latex(rowop.F(2))
row1 = 1
# row2 is irrelevant here
row2 = -1
operation = "scale"
expected = "2\\mathbf{r}_1 \\to \\mathbf{r}_1"
actual = rowop.create_op_string(string_multiplier, row1, row2, operation)
self.failUnless(actual == expected)
def test_six(self):
string_multiplier = rowop.frac_to_latex(rowop.F(-1))
row1 = 1
# row2 is irrelevant here
row2 = -1
operation = "scale"
expected = "-\\mathbf{r}_1 \\to \\mathbf{r}_1"
actual = rowop.create_op_string(string_multiplier, row1, row2, operation)
self.failUnless(actual == expected)
def test_seven(self):
string_multiplier = rowop.frac_to_latex(rowop.F(1))
row1 = 2
# row2 is irrelevant here
row2 = -1
operation = "scale"
expected = "\\mathbf{r}_2 \\to \\mathbf{r}_2"
actual = rowop.create_op_string(string_multiplier, row1, row2, operation)
self.failUnless(actual == expected)
def test_eight(self):
string_multiplier = rowop.frac_to_latex(rowop.F(-1))
row1 = 1
# row2 is irrelevant here
row2 = -1
operation = "scale"
expected = "-\\mathbf{r}_1 \\to \\mathbf{r}_1"
actual = rowop.create_op_string(string_multiplier, row1, row2, operation)
self.failUnless(actual == expected)
def test_nine(self):
string_multiplier = "-1"
row1 = 1
row2 = 2
operation = "-"
expected = "-\\mathbf{r}_1 - \\mathbf{r}_2 \\to \\mathbf{r}_2"
actual = rowop.create_op_string(string_multiplier, row1, row2, operation)
self.failUnless(actual == expected)
def test_nine_2(self):
string_multiplier = "1"
row1 = 1
row2 = 2
operation = "-"
expected = "\\mathbf{r}_1 - \\mathbf{r}_2 \\to \\mathbf{r}_2"
actual = rowop.create_op_string(string_multiplier, row1, row2, operation)
self.failUnless(actual == expected)
def main():
unittest.main()
if __name__ == "__main__":
main()