1
|
|
|
""" |
2
|
|
|
Function for evaluate oval operators. |
3
|
|
|
""" |
4
|
|
|
|
5
|
|
|
|
6
|
1 |
|
def oval_operator_and(result): |
7
|
|
|
""" |
8
|
|
|
The AND operator produces a true result if every argument is true. If one or more arguments |
9
|
|
|
are false, the result of the AND is false. If one or more of the arguments are unknown, and |
10
|
|
|
if none of the arguments are false, then the AND operator produces a result of unknown. |
11
|
|
|
""" |
12
|
1 |
|
out_result = None |
13
|
1 |
|
if eq_zero(result, 'false_cnt')\ |
14
|
|
|
and greater_zero(result, 'true_cnt')\ |
15
|
|
|
and error_unknown_noteval_eq_zero(result): |
16
|
1 |
|
out_result = 'true' |
17
|
1 |
|
elif greater_zero(result, 'false_cnt'): |
18
|
1 |
|
out_result = 'false' |
19
|
|
|
else: |
20
|
1 |
|
out_result = error_unknown_noteval_for_operators_and_or(result, 'and') |
21
|
1 |
|
return out_result |
22
|
|
|
|
23
|
|
|
|
24
|
1 |
|
def oval_operator_one(result): |
25
|
|
|
""" |
26
|
|
|
The ONE operator produces a true result if one and only one argument is true. If there are |
27
|
|
|
more than argument is true (or if there are no true arguments), the result of the ONE |
28
|
|
|
is false. If one or more of the arguments are unknown, then the ONE operator produces |
29
|
|
|
a result of unknown. |
30
|
|
|
""" |
31
|
1 |
|
out_result = None |
32
|
1 |
|
if one_is_true(result): |
33
|
1 |
|
out_result = 'true' |
34
|
1 |
|
elif one_is_false(result) or one_is_false1(result): |
35
|
1 |
|
out_result = 'false' |
36
|
1 |
|
elif one_is_error(result): |
37
|
1 |
|
out_result = 'error' |
38
|
1 |
|
elif one_is_unknown(result): |
39
|
1 |
|
out_result = 'unknown' |
40
|
1 |
|
elif one_is_noteval(result): |
41
|
1 |
|
out_result = 'noteval' |
42
|
|
|
else: |
43
|
1 |
|
out_result = None |
44
|
1 |
|
return out_result |
45
|
|
|
|
46
|
|
|
|
47
|
1 |
|
def oval_operator_or(result): |
48
|
|
|
""" |
49
|
|
|
The OR operator produces a true result if one or more arguments is true. If every argument |
50
|
|
|
is false, the result of the OR is false. If one or more of the arguments are unknown and |
51
|
|
|
if none of arguments are true, then the OR operator produces a result of unknown. |
52
|
|
|
""" |
53
|
1 |
|
out_result = None |
54
|
1 |
|
if greater_zero(result, 'true_cnt'): |
55
|
1 |
|
out_result = 'true' |
56
|
1 |
|
elif eq_zero(result, 'true_cnt')\ |
57
|
|
|
and greater_zero(result, 'false_cnt')\ |
58
|
|
|
and error_unknown_noteval_eq_zero(result): |
59
|
1 |
|
out_result = 'false' |
60
|
|
|
else: |
61
|
1 |
|
out_result = error_unknown_noteval_for_operators_and_or(result, 'or') |
62
|
1 |
|
return out_result |
63
|
|
|
|
64
|
|
|
|
65
|
1 |
|
def oval_operator_xor(result): |
66
|
|
|
""" |
67
|
|
|
XOR is defined to be true if an odd number of its arguments are true, and false otherwise. |
68
|
|
|
If any of the arguments are unknown, then the XOR operator produces a result of unknown. |
69
|
|
|
""" |
70
|
1 |
|
out_result = None |
71
|
1 |
|
if (result['true_cnt'] % 2) == 1\ |
72
|
|
|
and eq_zero_unknown_noteval_notappl(result): |
73
|
1 |
|
out_result = 'true' |
74
|
1 |
|
elif (result['true_cnt'] % 2) == 0\ |
75
|
|
|
and eq_zero_unknown_noteval_notappl(result): |
76
|
1 |
|
out_result = 'false' |
77
|
1 |
|
elif greater_zero(result, 'error_cnt'): |
78
|
1 |
|
out_result = 'error' |
79
|
1 |
|
elif eq_zero(result, 'error_cnt')\ |
80
|
|
|
and greater_zero(result, 'unknown_cnt'): |
81
|
1 |
|
out_result = 'unknown' |
82
|
1 |
|
elif eq_zero(result, 'error_cnt')\ |
83
|
|
|
and eq_zero(result, 'unknown_cnt')\ |
84
|
|
|
and greater_zero(result, 'noteval_cnt'): |
85
|
1 |
|
out_result = 'noteval' |
86
|
|
|
else: |
87
|
1 |
|
out_result = None |
88
|
1 |
|
return out_result |
89
|
|
|
|
90
|
|
|
|
91
|
1 |
|
def error_unknown_noteval_for_operators_and_or(result, operator): |
92
|
1 |
|
out_result = None |
93
|
1 |
|
if and_or_eq_zero(operator, result)\ |
94
|
|
|
and greater_zero(result, 'error_cnt'): |
95
|
1 |
|
out_result = 'error' |
96
|
1 |
|
elif and_or_eq_zero(operator, result)\ |
97
|
|
|
and error_unknown_eq_zero(result): |
98
|
1 |
|
out_result = 'unknown' |
99
|
1 |
|
elif and_or_eq_zero(operator, result)\ |
100
|
|
|
and error_unknown_eq_noteval_greater_zero(result): |
101
|
1 |
|
out_result = 'noteval' |
102
|
|
|
else: |
103
|
1 |
|
out_result = None |
104
|
1 |
|
return out_result |
105
|
|
|
|
106
|
|
|
|
107
|
1 |
|
def and_or_eq_zero(operator, result): |
108
|
1 |
|
if operator == 'and': |
109
|
1 |
|
return eq_zero(result, 'false_cnt') |
110
|
1 |
|
if operator == 'or': |
111
|
1 |
|
return eq_zero(result, 'true_cnt') |
112
|
1 |
|
return None |
113
|
|
|
|
114
|
|
|
|
115
|
1 |
|
def eq_zero(result, cnt): |
116
|
1 |
|
if result[cnt] == 0: |
117
|
1 |
|
return True |
118
|
1 |
|
return False |
119
|
|
|
|
120
|
|
|
|
121
|
1 |
|
def eq_zero_duo(result, cnt0, cnt1): |
122
|
1 |
|
if result[cnt0] == 0 and result[cnt1] == 0: |
123
|
1 |
|
return True |
124
|
1 |
|
return False |
125
|
|
|
|
126
|
|
|
|
127
|
1 |
|
def greater_zero(result, cnt): |
128
|
1 |
|
if result[cnt] > 0: |
129
|
1 |
|
return True |
130
|
1 |
|
return False |
131
|
|
|
|
132
|
|
|
|
133
|
1 |
|
def eq_or_greater_zero(result, cnt): |
134
|
1 |
|
if result[cnt] >= 0: |
135
|
1 |
|
return True |
136
|
1 |
|
return False |
137
|
|
|
|
138
|
|
|
|
139
|
1 |
|
def eq_or_greater_zero_duo(result, cnt0, cnt1): |
140
|
1 |
|
if result[cnt0] >= 0 and result[cnt1] >= 0: |
141
|
1 |
|
return True |
142
|
1 |
|
return False |
143
|
|
|
|
144
|
|
|
|
145
|
1 |
|
def smaller_than_two(result, cnt): |
146
|
1 |
|
if result[cnt] < 2: |
147
|
1 |
|
return True |
148
|
1 |
|
return False |
149
|
|
|
|
150
|
|
|
|
151
|
1 |
|
def one_is_noteval(result): |
152
|
1 |
|
if smaller_than_two(result, 'true_cnt')\ |
153
|
|
|
and eq_or_greater_zero_duo(result, 'false_cnt', 'notappl_cnt')\ |
154
|
|
|
and eq_zero_duo(result, 'error_cnt', 'unknown_cnt')\ |
155
|
|
|
and greater_zero(result, 'noteval_cnt'): |
156
|
1 |
|
return True |
157
|
1 |
|
return False |
158
|
|
|
|
159
|
|
|
|
160
|
1 |
|
def one_is_unknown(result): |
161
|
1 |
|
if smaller_than_two(result, 'true_cnt')\ |
162
|
|
|
and eq_or_greater_zero(result, 'false_cnt')\ |
163
|
|
|
and eq_zero(result, 'error_cnt')\ |
164
|
|
|
and result['unknown_cnt'] >= 1\ |
165
|
|
|
and eq_or_greater_zero_duo(result, 'noteval_cnt', 'notappl_cnt'): |
166
|
1 |
|
return True |
167
|
1 |
|
return False |
168
|
|
|
|
169
|
|
|
|
170
|
1 |
|
def one_is_error(result): |
171
|
1 |
|
if smaller_than_two(result, 'true_cnt')\ |
172
|
|
|
and eq_or_greater_zero(result, 'false_cnt')\ |
173
|
|
|
and greater_zero(result, 'error_cnt')\ |
174
|
|
|
and eq_or_greater_zero_unknown_noteval_notappl(result): |
175
|
1 |
|
return True |
176
|
1 |
|
return False |
177
|
|
|
|
178
|
|
|
|
179
|
1 |
|
def one_is_false(result): |
180
|
1 |
|
if eq_zero(result, 'true_cnt')\ |
181
|
|
|
and eq_or_greater_zero(result, 'false_cnt')\ |
182
|
|
|
and error_unknown_noteval_eq_zero(result)\ |
183
|
|
|
and result['notappl_cnt'] >= 0: |
184
|
1 |
|
return True |
185
|
1 |
|
return False |
186
|
|
|
|
187
|
|
|
|
188
|
1 |
|
def one_is_false1(result): |
189
|
1 |
|
if result['true_cnt'] >= 2\ |
190
|
|
|
and eq_or_greater_zero_duo(result, 'false_cnt', 'error_cnt')\ |
191
|
|
|
and eq_or_greater_zero_unknown_noteval_notappl(result): |
192
|
1 |
|
return True |
193
|
1 |
|
return False |
194
|
|
|
|
195
|
|
|
|
196
|
1 |
|
def one_is_true(result): |
197
|
1 |
|
if result['true_cnt'] == 1\ |
198
|
|
|
and eq_or_greater_zero_duo(result, 'false_cnt', 'notappl_cnt')\ |
199
|
|
|
and error_unknown_noteval_eq_zero(result): |
200
|
1 |
|
return True |
201
|
1 |
|
return False |
202
|
|
|
|
203
|
|
|
|
204
|
1 |
|
def eq_or_greater_zero_unknown_noteval_notappl(result): |
205
|
1 |
|
if eq_or_greater_zero(result, 'unknown_cnt')\ |
206
|
|
|
and eq_or_greater_zero(result, 'noteval_cnt')\ |
207
|
|
|
and eq_or_greater_zero(result, 'notappl_cnt'): |
208
|
1 |
|
return True |
209
|
1 |
|
return False |
210
|
|
|
|
211
|
|
|
|
212
|
1 |
|
def eq_zero_unknown_noteval_notappl(result): |
213
|
1 |
|
if eq_zero(result, 'error_cnt')\ |
214
|
|
|
and eq_zero(result, 'unknown_cnt')\ |
215
|
|
|
and eq_zero(result, 'noteval_cnt'): |
216
|
1 |
|
return True |
217
|
1 |
|
return False |
218
|
|
|
|
219
|
|
|
|
220
|
1 |
|
def error_unknown_noteval_eq_zero(result): |
221
|
1 |
|
if eq_zero(result, 'error_cnt')\ |
222
|
|
|
and eq_zero(result, 'unknown_cnt')\ |
223
|
|
|
and eq_zero(result, 'noteval_cnt'): |
224
|
1 |
|
return True |
225
|
1 |
|
return False |
226
|
|
|
|
227
|
|
|
|
228
|
1 |
|
def error_unknown_eq_noteval_greater_zero(result): |
229
|
1 |
|
if eq_zero(result, 'error_cnt')\ |
230
|
|
|
and eq_zero(result, 'unknown_cnt')\ |
231
|
|
|
and greater_zero(result, 'noteval_cnt'): |
232
|
1 |
|
return True |
233
|
1 |
|
return False |
234
|
|
|
|
235
|
|
|
|
236
|
1 |
|
def error_unknown_eq_zero(result): |
237
|
1 |
|
if eq_zero(result, 'error_cnt')\ |
238
|
|
|
and greater_zero(result, 'unknown_cnt'): |
239
|
1 |
|
return True |
240
|
|
|
return False |
241
|
|
|
|