def test_bt_one_root():
    bt_one = Node(150)
    bt_one.left = Node(100)
    bt_one.right = Node(250)
    bt_one.left.left = Node(75)
    bt_one.left.right = Node(160)
    bt_one.right.left = Node(200)
    bt_one.right.right = Node(350)
    bt_one.left.right.left = Node(125)
    bt_one.left.right.right = Node(175)
    bt_one.right.right.left = Node(300)
    bt_one.right.right.right = Node(500)

    bt_two = Node(42)
    bt_two.left = Node(100)
    bt_two.right = Node(600)
    bt_two.left.left = Node(15)
    bt_two.left.right = Node(160)
    bt_two.right.left = Node(200)
    bt_two.right.right = Node(350)
    bt_two.left.right.left = Node(125)
    bt_two.left.right.right = Node(175)
    bt_two.right.right.left = Node(4)
    bt_two.right.right.right = Node(500)

    actual = tree_intersection(bt_two, bt_two)
    expected = [100, 160, 125, 175, 200, 350, 500]
    assert actual == expected
コード例 #2
0
def test_sort_1():
    node1 = TNode(1)
    node1.left = TNode(2)
    node1.right = TNode(3)
    tree_1 = BinaryTree(node1)

    node1 = TNode(3)
    node1.left = TNode(4)
    node1.right = TNode(5)
    tree_2 = BinaryTree(node1)

    actual = tree_intersection(tree_1, tree_2)
    expected = [3]

    assert set(actual) == set(expected)
コード例 #3
0
def test_tree_intersect_with_tree_with_tree():
    t = BinaryTree(Node(26))
    t.root.left = Node(1)
    t.root.right = Node(17)
    t.root.left.left = Node(5)
    t.root.left.right = Node(5)
    t.root.right.left = Node(12)

    t2 = BinaryTree(Node('B'))
    t2.root.left = Node(12)
    t2.root.right = Node(12)
    t2.root.left.left = Node("D")
    t2.root.left.right = Node(1)
    t2.root.right.left = Node("F")

    actual = tree_intersection(t, t2)
    expected = [1, 12]
    assert actual == expected
コード例 #4
0
def test_tree_intersect_with_tree_with_tree():
    t = BinaryTree(Node("A"))
    t.root.left = Node("B")
    t.root.right = Node("C")
    t.root.left.left = Node("D")
    t.root.left.right = Node("E")
    t.root.right.left = Node("F")

    t2 = BinaryTree(Node('B'))
    t2.root.left = Node("B")
    t2.root.right = Node("C")
    t2.root.left.left = Node("D")
    t2.root.left.right = Node("E")
    t2.root.right.left = Node("F")

    actual = tree_intersection(t, t2)
    expected = ['B', 'D', 'E', 'C', 'F']
    assert actual == expected
コード例 #5
0
def test_sort_2():
    node1 = TNode(1)
    node1.left = TNode(2)
    node1.right = TNode(3)
    node1.right.left = TNode(5)
    node1.right.right = TNode(4)
    node1.left.right = TNode(6)
    node1.left.left = TNode(7)
    tree_1 = BinaryTree(node1)

    node1 = TNode(7)
    node1.left = TNode(11)
    node1.right = TNode(2)
    node1.right.left = TNode(3)
    node1.right.right = TNode(9)
    node1.left.right = TNode(1)
    node1.left.left = TNode(13)
    tree_2 = BinaryTree(node1)

    actual = tree_intersection(tree_1, tree_2)
    expected = [1, 2, 3, 7]

    assert set(actual) == set(expected)
コード例 #6
0
def test_empty_tree_intersect_with_tree_with_one_node():
    t = BinaryTree()
    t2 = BinaryTree(Node('A'))
    actual = tree_intersection(t, t2)
    expected = []
    assert actual == expected
コード例 #7
0
def test_tree_intersection(bn1, bn2):
    result = ["100", "160", "125", "175", "200", "350", "500"]
    assert tree_intersection(bn1, bn2) == result
コード例 #8
0
def test_tree_intersection_both_empty():
    assert tree_intersection(BinaryTree(), BinaryTree()) == []
コード例 #9
0
def test_tree_intersection_one_empty(bn1):
    assert tree_intersection(bn1, BinaryTree()) == []