mirror of
https://github.com/donnemartin/interactive-coding-challenges
synced 2026-01-11 20:08:04 +00:00
binary tree implementation
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
from nose.tools import assert_equal
|
||||
|
||||
class TestBinaryTree(BinaryTree):
|
||||
class TestBinaryTree(object):
|
||||
|
||||
def test_insert_traversals (self):
|
||||
myTree = BinaryTree()
|
||||
@@ -10,16 +10,23 @@ class TestBinaryTree(BinaryTree):
|
||||
[myTree2.insert(num) for num in range (1, 100, 10)]
|
||||
|
||||
print("Test: insert checking with in order traversal")
|
||||
assert_equal(myTree.printInOrder(), [7, 10, 25, 30, 38, 40, 50, 60, 70, 80])
|
||||
assert_equal(myTree2.printInOrder(), [1, 11, 21, 31, 41, 51, 61, 71, 81, 91])
|
||||
expectVal = [7, 10, 25, 30, 38, 40, 50, 60, 70, 80]
|
||||
assert_equal(myTree.printInOrder(), expectVal)
|
||||
expectVal = [1, 11, 21, 31, 41, 51, 61, 71, 81, 91]
|
||||
assert_equal(myTree2.printInOrder(), expectVal)
|
||||
|
||||
print("Test: insert checking with post order traversal")
|
||||
assert_equal(myTree.printPostOrder(), [7, 25, 10, 38, 40, 30, 60, 80, 70, 50])
|
||||
assert_equal(myTree2.printPostOrder(), [91, 81, 71, 61, 51, 41, 31, 21, 11, 1])
|
||||
expectVal = [7, 25, 10, 38, 40, 30, 60, 80, 70, 50]
|
||||
assert_equal(myTree.printPostOrder(), expectVal)
|
||||
expectVal = [91, 81, 71, 61, 51, 41, 31, 21, 11, 1]
|
||||
assert_equal(myTree2.printPostOrder(), expectVal)
|
||||
|
||||
|
||||
print("Test: insert checking with pre order traversal")
|
||||
assert_equal(myTree.printPreOrder(), [50, 30, 10, 7, 25, 40, 38, 70, 60, 80])
|
||||
assert_equal(myTree2.printPreOrder(), [1, 11, 21, 31, 41, 51, 61, 71, 81, 91])
|
||||
expectVal = [50, 30, 10, 7, 25, 40, 38, 70, 60, 80]
|
||||
assert_equal(myTree.printPreOrder(), expectVal)
|
||||
expectVal = [1, 11, 21, 31, 41, 51, 61, 71, 81, 91]
|
||||
assert_equal(myTree2.printPreOrder(), expectVal)
|
||||
|
||||
|
||||
print("Success: test_insert_traversals")
|
||||
|
||||
Reference in New Issue
Block a user