Beispiel #1
0
def test_Tree_CalculateValuesSubTree(tree, tree_sum, tree_avg, tree_median):
    t = Tree(tree)
    assert t.get_sum(full_tree=False,
                     sub_tree=t.root.right) == tree_sum, "Incorrect sum"
    assert t.get_mean(full_tree=False,
                      sub_tree=t.root.right) == tree_avg, "Incorrect average"
    assert t.get_median(
        full_tree=False,
        sub_tree=t.root.right) == tree_median, "Incorrect median"
Beispiel #2
0
def test_Tree_RaisesStatisticsErrorOnEmptyTree(a):
    t = Tree(a)
    assert t.get_sum(full_tree=True) == 0, "Incorrect sum"
    with pytest.raises(statistics.StatisticsError):
        t.get_median(full_tree=True)
        t.get_mean(full_tree=True)
Beispiel #3
0
def test_Tree_CalculateValuesFullTree(tree, tree_sum, tree_avg, tree_median):
    t = Tree(tree)
    assert t.get_sum(full_tree=True) == tree_sum, "Incorrect sum"
    assert t.get_mean(full_tree=True) == tree_avg, "Incorrect average"
    assert t.get_median(full_tree=True) == tree_median, "Incorrect median"
Beispiel #4
0
def test_Tree_HandlesLoops():
    a = Node(5)
    t = Tree(Node(3, Node(3, a), a))
    assert t.get_sum(full_tree=True) == 11, "Incorrect sum"