Passed
Push — master ( eb090f...f3512f )
by Matěj
03:08 queued 11s
created

test_graph   A

Complexity

Total Complexity 22

Size/Duplication

Total Lines 213
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 22
eloc 107
dl 0
loc 213
rs 10
c 0
b 0
f 0

15 Functions

Rating   Name   Duplication   Size   Complexity  
B test_bad_tree() 0 29 8
A test_ChangeValueTree() 0 21 1
A test_node_operator_negate() 0 11 1
A test_treeRepr() 0 11 1
A tree_only_or() 0 6 1
A test_bigOvalTree() 0 28 1
A test_add_to_tree() 0 17 1
A test_node_value_negate() 0 11 1
A tree_only_and() 0 6 1
A tree_with_bad_value_of_value() 0 3 1
A tree_with_bad_value_of_operator() 0 3 1
A tree_with_bad_value_of_negation() 0 3 1
A bad_tree() 0 15 1
A tree_with_bad_type() 0 3 1
A test_UPPERCASETree() 0 6 1
1
import graph.oval_graph
2
import pytest
3
import tests.any_test_help
4
5
6
def test_bad_tree():
7
    with pytest.raises(ValueError) as e:
8
        bad_tree()
9
    assert str(
10
        e.value) == 'err- true, false, error, unknown. noteval, notappl have not child!'
11
12
    with pytest.raises(ValueError) as e:
13
        tree_only_and()
14
    assert str(e.value) == 'err- OR, XOR, ONE, AND have child!'
15
16
    with pytest.raises(ValueError) as e:
17
        tree_only_or()
18
    assert str(e.value) == 'err- OR, XOR, ONE, AND have child!'
19
20
    with pytest.raises(ValueError) as e:
21
        tree_with_bad_type()
22
    assert str(e.value) == 'err- unknown type'
23
24
    with pytest.raises(ValueError) as e:
25
        tree_with_bad_value_of_operator()
26
    assert str(e.value) == 'err- unknown operator'
27
28
    with pytest.raises(ValueError) as e:
29
        tree_with_bad_value_of_value()
30
    assert str(e.value) == 'err- unknown value'
31
32
    with pytest.raises(ValueError) as e:
33
        tree_with_bad_value_of_negation()
34
    assert str(e.value) == 'err- negation si bool (only True or False)'
35
36
# degenered trees
37
38
39
def bad_tree():
40
    """
41
         t
42
         |
43
        and
44
         |
45
         t
46
    """
47
    t = graph.oval_graph.OvalNode(
48
        1, "value", "true", False, [
49
            graph.oval_graph.OvalNode(
50
                2, "operator", "and", False, [
51
                    graph.oval_graph.OvalNode(
52
                        3, "value", "true", False)])])
53
    return
54
55
56
def tree_only_or():
57
    """
58
        or
59
    """
60
    Tree = graph.oval_graph.OvalNode(1, "operator", 'or', False)
61
    return
62
63
64
def tree_only_and():
65
    """
66
        and
67
    """
68
    Tree = graph.oval_graph.OvalNode(1, "operator", 'and', False)
69
    return
70
71
72
def tree_with_bad_value_of_operator():
73
    Tree = graph.oval_graph.OvalNode(1, "operator", 'nad', False)
74
    return
75
76
77
def tree_with_bad_value_of_value():
78
    Tree = graph.oval_graph.OvalNode(1, "value", 'and', False)
79
    return
80
81
82
def tree_with_bad_type():
83
    Tree = graph.oval_graph.OvalNode(1, "auto", 'and', False)
84
    return
85
86
87
def tree_with_bad_value_of_negation():
88
    Tree = graph.oval_graph.OvalNode(1, "value", 'true', "negovane_auto")
89
    return
90
91
# normal trees
92
93
94
def test_UPPERCASETree():
95
    t = graph.oval_graph.OvalNode(
96
        1, "OPERATOR", "AND", False, [
97
            graph.oval_graph.OvalNode(
98
                2, "VALUE", "TRUE", False), graph.oval_graph.OvalNode(
99
                3, "VALUE", "NOTAPPL", False)])
100
101
102
def test_bigOvalTree():
103
    Tree = graph.oval_graph.OvalNode(1, 'operator', 'and', False, [
104
        graph.oval_graph.OvalNode(2, 'value', "false", False),
105
        graph.oval_graph.OvalNode(3, 'operator', "xor", False, [
106
            graph.oval_graph.OvalNode(4, 'value', 'true', False),
107
            graph.oval_graph.OvalNode(5, 'operator', 'one', False, [
108
                graph.oval_graph.OvalNode(6, 'value', 'noteval', False),
109
                graph.oval_graph.OvalNode(7, 'value', 'true', False),
110
                graph.oval_graph.OvalNode(8, 'value', 'notappl', False)
111
            ]
112
            ),
113
            graph.oval_graph.OvalNode(9, 'value', 'error', False)
114
        ]
115
        ),
116
        graph.oval_graph.OvalNode(10, 'operator', 'or', False, [
117
            graph.oval_graph.OvalNode(11, 'value', "unknown", False),
118
            graph.oval_graph.OvalNode(12, 'value', "true", False)
119
        ]
120
        )
121
    ]
122
    )
123
124
    test_data_src = 'test_data/bigOvalTree.json'
125
    dict_of_tree = tests.any_test_help.any_get_test_data_json(test_data_src)
126
    tests.any_test_help.any_test_treeEvaluation_with_tree(Tree, "false")
127
    tests.any_test_help.any_test_tree_to_dict_of_tree(Tree, dict_of_tree)
128
    tests.any_test_help.find_any_node(Tree, 5)
129
    tests.any_test_help.any_test_dict_to_tree(dict_of_tree)
130
131
###################################################
132
133
134
def test_treeRepr():
135
    """
136
        and
137
         |
138
         f
139
    """
140
    Tree = graph.oval_graph.OvalNode(1, 'operator', 'and', False, [
141
        graph.oval_graph.OvalNode(2, 'value', "false", False)
142
    ]
143
    )
144
    assert str(Tree) == "and"
145
146
147
def test_add_to_tree():
148
    """
149
        and
150
         |
151
         f
152
    """
153
154
    test_data_src = 'test_data/add_to_tree.json'
155
    dict_of_tree = tests.any_test_help.any_get_test_data_json(test_data_src)
156
157
    Tree = graph.oval_graph.OvalNode(1, 'operator', 'and', False, [
158
        graph.oval_graph.OvalNode(2, 'value', "false", False)
159
    ]
160
    )
161
    Tree1 = graph.oval_graph.OvalNode(3, 'value', "true", False)
162
    Tree.add_to_tree(1, Tree1)
163
    assert Tree.save_tree_to_dict() == dict_of_tree
164
165
166
def test_ChangeValueTree():
167
    """
168
        and
169
        /|\
170
       t t or
171
          / \
172
         f   t
173
    """
174
    Tree = graph.oval_graph.OvalNode(1, 'operator', 'and', False, [
175
        graph.oval_graph.OvalNode(2, 'value', "true", False),
176
        graph.oval_graph.OvalNode(3, 'value', "false", False),
177
        graph.oval_graph.OvalNode(4, 'operator', 'or', False, [
178
            graph.oval_graph.OvalNode(5, 'value', "false", False),
179
            graph.oval_graph.OvalNode(6, 'value', "true", False)
180
        ]
181
        )
182
    ]
183
    )
184
185
    Tree.change_tree_value(3, "true")
186
    tests.any_test_help.any_test_treeEvaluation_with_tree(Tree, "true")
187
188
189
def test_node_operator_negate():
190
    """
191
        and
192
         |
193
         f
194
    """
195
    Tree = graph.oval_graph.OvalNode(1, 'operator', 'and', True, [
196
        graph.oval_graph.OvalNode(2, 'value', "false", False)
197
    ]
198
    )
199
    tests.any_test_help.any_test_treeEvaluation_with_tree(Tree, "true")
200
201
202
def test_node_value_negate():
203
    """
204
        and
205
         |
206
         f
207
    """
208
    Tree = graph.oval_graph.OvalNode(1, 'operator', 'and', False, [
209
        graph.oval_graph.OvalNode(2, 'value', "false", True)
210
    ]
211
    )
212
    tests.any_test_help.any_test_treeEvaluation_with_tree(Tree, "true")
213