/
RuleTest.py
221 lines (182 loc) · 6.74 KB
/
RuleTest.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
219
220
221
import unittest
from Rule import Rule, RuleException
from Game import Equation
class ParsingTest(unittest.TestCase):
def test_rule_txt_as_none(self):
exceptions = (RuleException)
with self.assertRaises(exceptions):
Rule.parse(None)
def test_rule_txt_as_empty_string(self):
exceptions = (RuleException)
self.assertEqual([], Rule.parse(""))
def test_rule_txt_with_invalid_element_01(self):
exceptions = (RuleException)
with self.assertRaises(exceptions):
txt_rule = "L5s>=20".splitlines()
Rule.parse(txt_rule)
def test_rule_txt_with_invalid_element_02(self):
exceptions = (RuleException)
with self.assertRaises(exceptions):
txt_rule = "12>=20".splitlines()
Rule.parse(txt_rule)
def test_rule_txt_with_missing_element(self):
exceptions = (RuleException)
with self.assertRaises(exceptions):
txt_rule = " >=20".splitlines()
Rule.parse(txt_rule)
def test_rule_txt_with_invalid_operand_01(self):
exceptions = (RuleException)
with self.assertRaises(exceptions):
txt_rule = "L1!=20".splitlines()
Rule.parse(txt_rule)
def test_rule_txt_with_invalid_operand_02(self):
exceptions = (RuleException)
with self.assertRaises(exceptions):
txt_rule = "L1<>20".splitlines()
Rule.parse(txt_rule)
def test_rule_txt_with_missing_operand(self):
exceptions = (RuleException)
with self.assertRaises(exceptions):
txt_rule = "L120".splitlines()
Rule.parse(txt_rule)
def test_rule_txt_with_invalid_value_01(self):
exceptions = (RuleException)
with self.assertRaises(exceptions):
txt_rule = "L1>=L2".splitlines()
Rule.parse(txt_rule)
def test_rule_txt_with_invalid_value_02(self):
exceptions = (RuleException)
with self.assertRaises(exceptions):
txt_rule = "L1>=10.6".splitlines()
Rule.parse(txt_rule)
def test_rule_txt_with_missing_value(self):
exceptions = (RuleException)
with self.assertRaises(exceptions):
txt_rule = "L1>=".splitlines()
Rule.parse(txt_rule)
def test_rule_txt_with_one_rule(self):
txt_rule = "L1>=20".splitlines()
exp_result = [("L1", ">=", 20)]
self.assertEqual(exp_result, Rule.parse(txt_rule))
def test_rule_txt_with_two_rules(self):
txt_rule = "L1>=20\n" \
"L2=3".splitlines()
exp_result = [("L1", ">=", 20),
("L2", "=", 3)]
self.assertEqual(exp_result, Rule.parse(txt_rule))
def test_rule_txt_with_three_rules(self):
txt_rule = "L1>=20\n" \
"L2=3\n" \
"W<=90".splitlines()
exp_result = [("L1", ">=", 20),
("L2", "=", 3),
("W", "<=", 90)]
self.assertEqual(exp_result, Rule.parse(txt_rule))
def test_rule_txt_with_one_rule_and_spaces(self):
txt_rule = "L1 >= 20".splitlines()
exp_result = [("L1", ">=", 20)]
self.assertEqual(exp_result, Rule.parse(txt_rule))
class ValidateRules_W(unittest.TestCase):
def test_W_01(self):
txt_rule = "L1>0\n" \
"L1<10\n" \
"L2>0\n" \
"L2<10\n" \
"W<=90".splitlines()
rules = Rule.parse(txt_rule)
exceptions = (RuleException)
with self.assertRaises(exceptions):
Equation.validate_rules_for_w(rules)
def test_W_01m(self):
txt_rule = "L1>0\n" \
"L1<10\n" \
"L2>0\n" \
"L2<10\n" \
"W<10\n" \
"W<=90".splitlines()
rules = Rule.parse(txt_rule)
exceptions = (RuleException)
with self.assertRaises(exceptions):
Equation.validate_rules_for_w(rules)
def test_W_02(self):
txt_rule = "L1>0\n" \
"L1<10\n" \
"L2>0\n" \
"L2<10\n" \
"W>90".splitlines()
rules = Rule.parse(txt_rule)
exceptions = (RuleException)
with self.assertRaises(exceptions):
Equation.validate_rules_for_w(rules)
def test_W_02m(self):
txt_rule = "L1>0\n" \
"L1<10\n" \
"L2>0\n" \
"L2<10\n" \
"W>=10\n" \
"W>90".splitlines()
rules = Rule.parse(txt_rule)
exceptions = (RuleException)
with self.assertRaises(exceptions):
Equation.validate_rules_for_w(rules)
def test_W_03(self):
txt_rule = "L1>0\n" \
"L1<10\n" \
"L2>0\n" \
"L2<10\n" \
"W==90".splitlines()
rules = Rule.parse(txt_rule)
Equation.validate_rules_for_w(rules)
def test_W_03m(self):
txt_rule = "L1>0\n" \
"L1<10\n" \
"L2>0\n" \
"L2<10\n" \
"W=5\n" \
"W==90".splitlines()
rules = Rule.parse(txt_rule)
exceptions = (RuleException)
with self.assertRaises(exceptions):
Equation.validate_rules_for_w(rules)
def test_W_04(self):
txt_rule = "L1>0\n" \
"L1<10\n" \
"L2>0\n" \
"L2<10\n" \
"W<20\n" \
"W>90".splitlines()
rules = Rule.parse(txt_rule)
exceptions = (RuleException)
with self.assertRaises(exceptions):
Equation.validate_rules_for_w(rules)
def test_W_05(self):
txt_rule = "L1>0\n" \
"L1<10\n" \
"L2>0\n" \
"L2<10\n" \
"W==20\n" \
"W>90".splitlines()
rules = Rule.parse(txt_rule)
exceptions = (RuleException)
with self.assertRaises(exceptions):
Equation.validate_rules_for_w(rules)
def test_W_05b(self):
txt_rule = "L1>0\n" \
"L1<10\n" \
"L2>0\n" \
"L2<10\n" \
"W==20\n" \
"W<=90".splitlines()
rules = Rule.parse(txt_rule)
exceptions = (RuleException)
with self.assertRaises(exceptions):
Equation.validate_rules_for_w(rules)
def test_W_06(self):
txt_rule = "L1>0\n" \
"L1<10\n" \
"L2>0\n" \
"L2<10\n" \
"W>20\n" \
"W<90".splitlines()
rules = Rule.parse(txt_rule)
Equation.validate_rules_for_w(rules)