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 result['true_cnt'] == 1\ |
33
|
|
|
and eq_or_greater_zero_duo(result,'false_cnt','notappl_cnt')\ |
|
|
|
|
34
|
|
|
and error_unknown_noteval_eq_zero(result): |
35
|
1 |
|
out_result = 'true' |
36
|
1 |
|
elif result['true_cnt'] >= 2\ |
37
|
|
|
and eq_or_greater_zero_duo(result, 'false_cnt', 'error_cnt')\ |
38
|
|
|
and eq_or_greater_zero_unknown_noteval_notappl(result): |
39
|
1 |
|
out_result = 'false' |
40
|
1 |
|
elif eq_zero(result, 'true_cnt')\ |
41
|
|
|
and eq_or_greater_zero(result, 'false_cnt')\ |
42
|
|
|
and error_unknown_noteval_eq_zero(result)\ |
43
|
|
|
and result['notappl_cnt'] >= 0: |
44
|
1 |
|
out_result = 'false' |
45
|
1 |
|
elif smaller_than_two(result, 'true_cnt')\ |
46
|
|
|
and eq_or_greater_zero(result, 'false_cnt')\ |
47
|
|
|
and greater_zero(result, 'error_cnt')\ |
48
|
|
|
and eq_or_greater_zero_unknown_noteval_notappl(result): |
49
|
1 |
|
out_result = 'error' |
50
|
1 |
|
elif smaller_than_two(result, 'true_cnt')\ |
51
|
|
|
and eq_or_greater_zero(result, 'false_cnt')\ |
52
|
|
|
and eq_zero(result, 'error_cnt')\ |
53
|
|
|
and result['unknown_cnt'] >= 1\ |
54
|
|
|
and eq_or_greater_zero_duo(result, 'noteval_cnt','notappl_cnt'): |
|
|
|
|
55
|
1 |
|
out_result = 'unknown' |
56
|
1 |
|
elif smaller_than_two(result, 'true_cnt')\ |
57
|
|
|
and eq_or_greater_zero_duo(result, 'false_cnt','notappl_cnt')\ |
|
|
|
|
58
|
|
|
and eq_zero_duo(result, 'error_cnt', 'unknown_cnt')\ |
59
|
|
|
and greater_zero(result, 'noteval_cnt'): |
60
|
1 |
|
out_result = 'noteval' |
61
|
|
|
else: |
62
|
1 |
|
out_result = None |
63
|
1 |
|
return out_result |
64
|
|
|
|
65
|
|
|
|
66
|
1 |
|
def oval_operator_or(result): |
67
|
|
|
""" |
68
|
|
|
The OR operator produces a true result if one or more arguments is true. If every argument |
69
|
|
|
is false, the result of the OR is false. If one or more of the arguments are unknown and |
70
|
|
|
if none of arguments are true, then the OR operator produces a result of unknown. |
71
|
|
|
""" |
72
|
1 |
|
out_result = None |
73
|
1 |
|
if greater_zero(result, 'true_cnt'): |
74
|
1 |
|
out_result = 'true' |
75
|
1 |
|
elif eq_zero(result, 'true_cnt')\ |
76
|
|
|
and greater_zero(result, 'false_cnt')\ |
77
|
|
|
and error_unknown_noteval_eq_zero(result): |
78
|
1 |
|
out_result = 'false' |
79
|
|
|
else: |
80
|
1 |
|
out_result = error_unknown_noteval_for_operators_and_or(result, 'or') |
81
|
1 |
|
return out_result |
82
|
|
|
|
83
|
|
|
|
84
|
1 |
|
def oval_operator_xor(result): |
85
|
|
|
""" |
86
|
|
|
XOR is defined to be true if an odd number of its arguments are true, and false otherwise. |
87
|
|
|
If any of the arguments are unknown, then the XOR operator produces a result of unknown. |
88
|
|
|
""" |
89
|
1 |
|
out_result = None |
90
|
1 |
|
if (result['true_cnt'] % 2) == 1\ |
91
|
|
|
and eq_zero_unknown_noteval_notappl(result): |
92
|
1 |
|
out_result = 'true' |
93
|
1 |
|
elif (result['true_cnt'] % 2) == 0\ |
94
|
|
|
and eq_zero_unknown_noteval_notappl(result): |
95
|
1 |
|
out_result = 'false' |
96
|
1 |
|
elif greater_zero(result, 'error_cnt'): |
97
|
1 |
|
out_result = 'error' |
98
|
1 |
|
elif eq_zero(result, 'error_cnt')\ |
99
|
|
|
and greater_zero(result, 'unknown_cnt'): |
100
|
1 |
|
out_result = 'unknown' |
101
|
1 |
|
elif eq_zero(result, 'error_cnt')\ |
102
|
|
|
and eq_zero(result, 'unknown_cnt')\ |
103
|
|
|
and greater_zero(result, 'noteval_cnt'): |
104
|
1 |
|
out_result = 'noteval' |
105
|
|
|
else: |
106
|
1 |
|
out_result = None |
107
|
1 |
|
return out_result |
108
|
|
|
|
109
|
|
|
|
110
|
1 |
|
def error_unknown_noteval_for_operators_and_or(result, operator): |
111
|
1 |
|
out_result = None |
112
|
1 |
|
if and_or_eq_zero(operator, result)\ |
113
|
|
|
and greater_zero(result, 'error_cnt'): |
114
|
1 |
|
out_result = 'error' |
115
|
1 |
|
elif and_or_eq_zero(operator, result)\ |
116
|
|
|
and error_unknown_eq_zero(result): |
117
|
1 |
|
out_result = 'unknown' |
118
|
1 |
|
elif and_or_eq_zero(operator, result)\ |
119
|
|
|
and error_unknown_eq_noteval_greater_zero(result): |
120
|
1 |
|
out_result = 'noteval' |
121
|
|
|
else: |
122
|
1 |
|
out_result = None |
123
|
1 |
|
return out_result |
124
|
|
|
|
125
|
|
|
|
126
|
1 |
|
def and_or_eq_zero(operator, result): |
127
|
1 |
|
if operator == 'and': |
128
|
1 |
|
return eq_zero(result, 'false_cnt') |
129
|
1 |
|
if operator == 'or': |
130
|
1 |
|
return eq_zero(result, 'true_cnt') |
131
|
1 |
|
return None |
132
|
|
|
|
133
|
|
|
|
134
|
1 |
|
def eq_zero(result, cnt): |
135
|
1 |
|
if result[cnt] == 0: |
136
|
1 |
|
return True |
137
|
1 |
|
return False |
138
|
|
|
|
139
|
|
|
|
140
|
1 |
|
def eq_zero_duo(result, cnt0, cnt1): |
141
|
1 |
|
if result[cnt0] == 0 and result[cnt1] == 0: |
142
|
1 |
|
return True |
143
|
|
|
return False |
144
|
|
|
|
145
|
|
|
|
146
|
1 |
|
def greater_zero(result, cnt): |
147
|
1 |
|
if result[cnt] > 0: |
148
|
1 |
|
return True |
149
|
1 |
|
return False |
150
|
|
|
|
151
|
|
|
|
152
|
1 |
|
def eq_or_greater_zero(result, cnt): |
153
|
1 |
|
if result[cnt] >= 0: |
154
|
1 |
|
return True |
155
|
1 |
|
return False |
156
|
|
|
|
157
|
1 |
|
def eq_or_greater_zero_duo(result, cnt0, cnt1): |
158
|
1 |
|
if result[cnt0] >= 0 and result[cnt1] >= 0: |
159
|
1 |
|
return True |
160
|
1 |
|
return False |
161
|
|
|
|
162
|
|
|
|
163
|
|
|
|
164
|
1 |
|
def smaller_than_two(result, cnt): |
165
|
1 |
|
if result[cnt] < 2: |
166
|
1 |
|
return True |
167
|
1 |
|
return False |
168
|
|
|
|
169
|
|
|
|
170
|
1 |
|
def eq_or_greater_zero_unknown_noteval_notappl(result): |
171
|
1 |
|
if eq_or_greater_zero(result, 'unknown_cnt')\ |
172
|
|
|
and eq_or_greater_zero(result, 'noteval_cnt')\ |
173
|
|
|
and eq_or_greater_zero(result, 'notappl_cnt'): |
174
|
1 |
|
return True |
175
|
1 |
|
return False |
176
|
|
|
|
177
|
|
|
|
178
|
1 |
|
def eq_zero_unknown_noteval_notappl(result): |
179
|
1 |
|
if eq_zero(result, 'error_cnt')\ |
180
|
|
|
and eq_zero(result, 'unknown_cnt')\ |
181
|
|
|
and eq_zero(result, 'noteval_cnt'): |
182
|
1 |
|
return True |
183
|
1 |
|
return False |
184
|
|
|
|
185
|
|
|
|
186
|
1 |
|
def error_unknown_noteval_eq_zero(result): |
187
|
1 |
|
if eq_zero(result, 'error_cnt')\ |
188
|
|
|
and eq_zero(result, 'unknown_cnt')\ |
189
|
|
|
and eq_zero(result, 'noteval_cnt'): |
190
|
1 |
|
return True |
191
|
1 |
|
return False |
192
|
|
|
|
193
|
|
|
|
194
|
1 |
|
def error_unknown_eq_noteval_greater_zero(result): |
195
|
1 |
|
if eq_zero(result, 'error_cnt')\ |
196
|
|
|
and eq_zero(result, 'unknown_cnt')\ |
197
|
|
|
and greater_zero(result, 'noteval_cnt'): |
198
|
1 |
|
return True |
199
|
1 |
|
return False |
200
|
|
|
|
201
|
|
|
|
202
|
1 |
|
def error_unknown_eq_zero(result): |
203
|
1 |
|
if eq_zero(result, 'error_cnt')\ |
204
|
|
|
and greater_zero(result, 'unknown_cnt'): |
205
|
1 |
|
return True |
206
|
|
|
return False |
207
|
|
|
|