Passed
Branch codeStyle (b8cf76)
by Jan
01:52
created

graph.evaluate.smaller_than_two()   A

Complexity

Conditions 2

Size

Total Lines 4
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

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