Exemple #1
0
 def test_to_list(self):
     bst = BST().from_list(self.bst_data)
     arr = []
     arr = bst.to_list()
     self.assertIsNotNone(arr)
     self.assertListEqual(sorted(arr), sorted(self.bst_data),
                          'to list test')
Exemple #2
0
 def test_search(self):
     bst = BST().from_list(self.bst_data)
     # test is found result
     result = bst_search(bst.root, 64)
     self.assertIsNotNone(result)
     self.assertEqual(result.value, 64)
     # test is not found result
     result = bst_search(bst.root, 66)
     self.assertIsNone(result)
Exemple #3
0
 def test_next_larger(self):
     bst = BST().from_list(self.bst_data)
     # test go right by tree
     result = bst_next_larger(bst.root, 65)
     self.assertIsNotNone(result)
     self.assertEqual(result.value, 79)
     # test go right by  tree
     result = bst_next_larger(bst.root, 44)
     self.assertIsNotNone(result)
     self.assertEqual(result.value, 46)
     # test go left right by tree
     result = bst_next_larger(bst.root, 63)
     self.assertIsNotNone(result)
     self.assertEqual(result.value, 64, 'test go left right by tree')
     result = bst_next_larger(bst.root, 82)
     self.assertIsNotNone(result)
     self.assertEqual(result.value, 83, 'test go left right by tree')
Exemple #4
0
 def test_next_smaller(self):
     if __print_trees__:
         print('test_next_smaller >>>>')
     bst = BST().from_list(self.bst_data)
     # test go right by tree
     result = bst_next_smaller(bst.root, 65)
     self.assertIsNotNone(result)
     self.assertEqual(result.value, 64)
     # test go right by  tree
     result = bst_next_smaller(bst.root, 44)
     self.assertIsNotNone(result)
     self.assertEqual(result.value, 43)
     # test go left right by tree
     result = bst_next_smaller(bst.root, 63)
     self.assertIsNotNone(result)
     self.assertEqual(result.value, 49, 'test go left right by tree')
     result = bst_next_smaller(bst.root, 82)
     self.assertIsNotNone(result)
     self.assertEqual(result.value, 81, 'test go left right by tree')
     if __print_trees__:
         print('<<<< test_next_smaller')
Exemple #5
0
 def test_min(self):
     bst = BST().from_list(self.bst_data)
     min_value = bst_min(bst.root)
     self.assertEqual(min_value, min(self.bst_data))
Exemple #6
0
 def test_max(self):
     bst = BST().from_list(self.bst_data)
     max_value = bst_max(bst.root)
     self.assertEqual(max_value, max(self.bst_data))
Exemple #7
0
 def test_count_of_less_or_equal(self):
     bst = BST().from_list(self.bst_data)
     count = bst_count(bst.root, 45)
     self.assertEqual(count, 2)
     count = bst_count(bst.root, 79)
     self.assertEqual(count, 6)
Exemple #8
0
 def test_bst_find_smaller(self):
     bst = BST().from_list(self.bst_data)
     node = bst_find_smaller(bst.root, 45)
     self.assertEqual(node.value, 43)
Exemple #9
0
 def setUp(self):
     self.bst_data = [49, 46, 79, 43, 64, 83, 40, 81, 87]
     bst = BST().from_list(self.bst_data)
     if __print_trees__:
         bst_print(bst.root)