/
test_bst.py
24 lines (22 loc) · 1.02 KB
/
test_bst.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
''' Test the binary search tree '''
from binarysearchtree import BinarySearchTree, Node
import unittest
class TestBST(unittest.TestCase):
'''Runs the simple examples from the activate state recipe.'''
names = 'bob joe Jane jack Mary sue Ed Zoey ann'.split()
def setUp(self):
self.bst = BinarySearchTree(self.names, str.upper)
def test_insert(self):
self.assertEquals(self.bst.minimum(), 'ann')
def test_minimum(self):
self.assertEquals(self.bst.maximum(), 'Zoey')
def test_values(self):
expected_list = ['ann', 'bob', 'Ed', 'jack', 'Jane', 'joe', 'Mary', 'sue', 'Zoey']
for expected, result in zip(expected_list, self.bst.values()):
self.assertEquals(expected, result)
def test_values_reversed(self):
expected_list = ['Zoey', 'sue', 'Mary', 'joe', 'Jane', 'jack', 'Ed', 'bob', 'ann']
for expected, result in zip(expected_list, self.bst.values(True)):
self.assertEquals(expected, result)
if __name__ == '__main__':
unittest.main()