Exemple #1
0
def test_add_one():

    fruits = BinarySearchTree()
    fruits.add('apples')
    expected = 'apples'
    actual = fruits.root.value
    assert expected == actual
def test_post_order():
    tree = BinarySearchTree()
    tree.add(10)
    tree.add(9)
    tree.add(11)
    actual = tree.post_order()
    excepted = [9, 11, 10]
    assert actual == excepted
Exemple #3
0
def test_height_three():
    numbers = BinarySearchTree()
    numbers.add(10)

    numbers.add(9)
    numbers.add(11)
    actual = numbers.find_height()
    assert 1 == actual
Exemple #4
0
def test_height_four():
    numbers = BinarySearchTree()
    numbers.add(10)
    numbers.add(9)
    numbers.add(11)
    numbers.add(13)
    actual = numbers.find_height()
    assert 2 == actual
def test_traverse_pre_order():
    tree = BinarySearchTree()
    tree.add('bananas')
    tree.add('apples')
    tree.add('cucumbers')

    items = list(tree.traverse_pre_order())

    assert items == ['bananas', 'apples', 'cucumbers']
def test_traverse_breath_first():
    tree = BinarySearchTree()
    tree.add('apples')
    tree.add('cucumbers')
    tree.add('bananas')

    items = list(tree.traverse_breath_first())

    assert items == ['apples', 'cucumbers', 'bananas']
Exemple #7
0
def test_fizzbuzz_two():
    numbers = BinarySearchTree()
    numbers.add(43)
    numbers.add(60)
    numbers.add(-3)
    numbers.add(42)
    expected = ['fizz', 'fizz', 43, 'fizzbuzz']
    numbers.fizzbuzz()
    actual = numbers.fizzbuzz()
    assert expected == actual
def test_traverse_for_loop_post_order():
    tree = BinarySearchTree()
    tree.add('apples')
    tree.add('cucumbers')
    tree.add('bananas')

    items = []

    for item in tree.traverse_breath_first():
        items.append(item)

    assert items == ['apples', 'cucumbers', 'bananas']
def test_add_left_right():
    tree = BinarySearchTree()
    tree.add(10)
    tree.add(9)
    tree.add(11)
    result = [tree.root.left.value, tree.root.right.value]
    actual = result
    expected = [9, 11]
    assert actual == expected
def test_in_order():
    tree = BinarySearchTree()
    tree.add('A')
    tree.add('B')
    tree.add('C')
    actual = tree.in_order()
    excepted = ['A', 'B', 'C']
    assert actual == excepted
Exemple #11
0
def test_breadth_two():
    fruits = BinarySearchTree()
    fruits.add(67)
    fruits.add(62)
    fruits.add(65)
    fruits.add(90)
    expected = [67, 62, 90, 65]
    actual = fruits.breath_first()
    assert expected == actual
def test_max_one():
   nums = BinarySearchTree()
   nums.add(67)
   nums.add(62)
   nums.add(65)
   nums.add(90)
   expected = 90
   actual =nums.find_max_value()
   assert expected == actual
Exemple #13
0
def test_add_one_left_one_right():
    fruits = BinarySearchTree()
    fruits.add('bananas')
    fruits.add('apples')
    fruits.add('carrots')
    expected = 'bananas'
    actual = fruits.root.value
    assert expected == actual
    expected = 'apples'
    actual = fruits.root.child_left.value
    assert expected == actual
    expected = 'carrots'
    actual = fruits.root.child_right.value
    assert expected == actual
Exemple #14
0
def test_height_two():
    numbers = BinarySearchTree()
    numbers.add(50)
    numbers.add(100)
    numbers.add(200)
    numbers.add(150)
    # numbers.add(5)
    # numbers.add(35)
    # numbers.add(13)
    # numbers.add(43)
    # numbers.add(4)
    # numbers.add(159)
    # numbers.add(33)
    # numbers.add(322)
    # numbers.add(543)
    # numbers.add(352)
    # numbers.add(123)
    # numbers.add(443)
    actual = numbers.find_height()
    assert 3 == actual
Exemple #15
0
def test_breadth_one():
    fruits = BinarySearchTree()
    fruits.add('bananas')
    fruits.add('apples')
    fruits.add('carrots')
    fruits.add('mango')
    fruits.add('pear')
    fruits.add('cake')
    fruits.add('cookies')
    fruits.add('beer')
    fruits.add('whiskey')
    expected = [
        'bananas', 'apples', 'carrots', 'cake', 'mango', 'beer', 'cookies',
        'pear', 'whiskey'
    ]
    actual = fruits.breath_first()
    assert expected == actual
Exemple #16
0
def test_fizzbuzz_one():
    numbers = BinarySearchTree()
    numbers.add(1)
    numbers.add(3)
    numbers.add(28)
    numbers.add(90)
    numbers.add(10)
    numbers.add(18)
    numbers.add(21)
    numbers.add(65)
    numbers.add(100)
    expected = [
        1, 'fizz', 'buzz', 'fizz', 'fizz', 28, 'buzz', 'fizzbuzz', 'buzz'
    ]
    numbers.fizzbuzz()
    actual = numbers.fizzbuzz()
    assert expected == actual
def test_three():
    tree1 = BinarySearchTree()
    tree2 = BinarySearchTree()
    tree1.add(10)
    tree1.add(14)
    tree1.add(16)
    tree1.add(12)
    tree1.add(9)
    tree1.add(23)
    tree1.add(13)
    tree2.add(0)
    tree2.add(1)
    tree2.add(2)
    tree2.add(3)
    tree2.add(4)
    tree2.add(5)
    tree2.add(6)
    actual = tree_intersection(tree1, tree2)
    assert [] == actual
    assert len(actual) == 0
def test_empty_tree():
    tree = BinarySearchTree()
    actual = tree.root
    expected = None
    assert actual == expected
def test_tree_single_node():
    tree = BinarySearchTree()
    tree.add('A')
    actual = tree.root.value
    expected = 'A'
    assert actual == expected
Exemple #20
0
def test_height_one():
    numbers = BinarySearchTree()
    numbers.add(10)
    numbers.add(9)
    numbers.add(8)
    numbers.add(7)
    numbers.add(3)
    numbers.add(35)
    numbers.add(12)
    numbers.add(43)
    actual = numbers.find_height()
    assert 5 == actual
Exemple #21
0
def test_instantion():
    """Can successfully instantiate an empty linked list
   """
    assert BinarySearchTree()
def test_one():
    tree1 = BinarySearchTree()
    tree2 = BinarySearchTree()
    tree1.add(10)
    tree1.add(14)
    tree1.add(16)
    tree1.add(12)
    tree1.add(9)
    tree1.add(23)
    tree1.add(13)
    tree2.add(10)
    tree2.add(14)
    tree2.add(16)
    tree2.add(12)
    tree2.add(9)
    tree2.add(23)
    tree2.add(13)
    actual = tree_intersection(tree1, tree2)
    expected = [10, 9, 12, 13, 14, 16, 23]
    assert expected == actual
    assert (24 in expected) == False
def test_max_value():
    tree = BinarySearchTree()
    tree.add(10)
    tree.add(20)
    tree.add(9)
    tree.add(11)
    tree.add(5)
    assert tree.maximum_value() == 20
Exemple #24
0
def test_fizzbuzz_empty():
    numbers = BinarySearchTree()
    actual = numbers.fizzbuzz()
    assert actual == None
Exemple #25
0
def test_cotains_true():
    fruits = BinarySearchTree()
    fruits.add('bananas')
    fruits.add('apples')
    fruits.add('carrots')
    fruits.add('mango')
    fruits.add('pear')
    fruits.add('cake')
    fruits.add('cookies')
    fruits.add('beer')
    fruits.add('whiskey')
    expected = True
    actual = fruits.contains('whiskey')
    assert expected == actual
def test_breadth_one():
    fruits = BinarySearchTree()
    fruits.add('bananas')
    fruits.add('apples')
    fruits.add('carrots')
    fruits.add('mango')
    fruits.add('pear')
    fruits.add('cake')
    fruits.add('cookies')
    fruits.add('beer')
    fruits.add('whiskey')
    expected = [
        'bananas', 'apples', 'carrots', 'cake', 'mango', 'beer', 'cookies',
        'pear', 'whiskey'
    ]

    items = []

    for item in fruits.traverse_breath_first():
        items.append(item)
    assert expected == items
Exemple #27
0
def test_pre_order():
    fruits = BinarySearchTree()
    fruits.add('bananas')
    fruits.add('apples')
    fruits.add('carrots')
    fruits.add('mango')
    fruits.add('pear')
    fruits.add('cake')
    fruits.add('cookies')
    fruits.add('beer')
    fruits.add('whiskey')
    expected = [
        'bananas', 'apples', 'beer', 'cake', 'carrots', 'cookies', 'mango',
        'pear', 'whiskey'
    ]
    actual = fruits.pre_order()
    assert expected == actual
def test_two():
    tree1 = BinarySearchTree()
    tree2 = BinarySearchTree()
    tree1.add('tim')
    tree1.add('tom')
    tree1.add('chris')
    tree1.add('jack')
    tree1.add('joe')
    tree1.add('pat')
    tree2.add('pat')
    tree2.add('pam')
    tree2.add('wer')
    tree2.add('jan')
    tree2.add('tom')
    tree2.add('tyler')
    tree2.add('bill')
    actual = tree_intersection(tree1, tree2)
    expected = ['pat', 'pam', 'tom']
    assert expected == actual
    assert ('chris' in expected) == False