Exemplo n.º 1
0
 def test_delete_big(self):
     inserts = [1000, 500, 1500, 250, 750, 625, 825, 626]
     my_tree = splayTree.SplayTree()
     for x in inserts:
         my_tree.insert(splayTree.Node(x))
     my_tree.delete(500)
     parent = my_tree.root.leftChild.rightChild.leftChild.parent.key
     self.assertEqual(parent, 750)
Exemplo n.º 2
0
 def test_find_removed_big_found(self):
     x = splayTree.SplayTree()
     x.insert(splayTree.Node(10))
     x.insert(splayTree.Node(20))
     x.insert(splayTree.Node(2))
     x.insert(splayTree.Node(15))
     x.insert(splayTree.Node(8))
     x.insert(splayTree.Node(3))
     x.insert(splayTree.Node(1))
     x.insert(splayTree.Node(18))
     x.insert(splayTree.Node(5))
     x.insert(splayTree.Node(13))
     x.insert(splayTree.Node(19))
     x.delete(15)
     self.assertEqual(x._find_msg(20), 'Found')
Exemplo n.º 3
0
 def test_isRightChild_true(self):
     x = splayTree.SplayTree()
     x.insert(splayTree.Node(key=1))
     x.insert(splayTree.Node(key=2))
     self.assertTrue(x.root.rightChild.isRightChild())
Exemplo n.º 4
0
 def testRangeSum_a(self):
     x = splayTree.SplayTree()
     l = [87, 35, 81, 23, 13, 84, 41, 5, 31, 30]
     for e in l:
         x.insert(splayTree.Node(e))
     self.assertEqual(x.rangeSearch(10, 30).treeSum(), 66)
Exemplo n.º 5
0
 def test_treeSum_empty(self):
     x = splayTree.SplayTree()
     self.assertEqual(x.treeSum(), 0)
Exemplo n.º 6
0
 def test_treeSum(self):
     x = splayTree.SplayTree()
     l = [87, 35, 81, 23, 13, 84, 41, 5, 31, 30]
     for e in l:
         x.insert(splayTree.Node(e))
     self.assertEqual(x.treeSum(), 430)
Exemplo n.º 7
0
 def test_find_modi_empty_tree(self):
     x = splayTree.SplayTree()
     self.assertFalse(x._find_modi(10))
Exemplo n.º 8
0
 def test_find_modi_missing(self):
     x = splayTree.SplayTree()
     l = [87, 35, 81, 23, 13, 84, 41, 5, 31, 30]
     for e in l:
         x.insert(splayTree.Node(e))
     self.assertEqual(x._find_modi(key=85).key, 84)
Exemplo n.º 9
0
 def test_find_root(self):
     x = splayTree.SplayTree()
     x.insert(splayTree.Node(1))
     self.assertEqual(x._find_msg(1), 'Found')
Exemplo n.º 10
0
 def test_find_removed(self):
     x = splayTree.SplayTree()
     x.insert(splayTree.Node(1))
     x.delete(key=1)
     self.assertEqual(x._find_msg(1), 'Not found')
Exemplo n.º 11
0
 def test_find_empty(self):
     x = splayTree.SplayTree()
     self.assertEqual(x._find_msg(1), 'Not found')
Exemplo n.º 12
0
 def test_insert_node_left_left(self):
     x = splayTree.SplayTree()
     x.insert(splayTree.Node(key=3))
     x.insert(splayTree.Node(key=2))
     x.insert(splayTree.Node(key=1))
     self.assertEqual(x.root.leftChild.leftChild.key, 1)
Exemplo n.º 13
0
 def test_insert_node_left(self):
     ## assert node is inserted to left child of root  ---------------------
     x = splayTree.SplayTree()
     x.insert(splayTree.Node(key=2))
     x.insert(splayTree.Node(key=1))
     self.assertEqual(x.root.leftChild.key, 1)
Exemplo n.º 14
0
 def test_insert_key(self):
     x = splayTree.SplayTree()
     x.insert(splayTree.Node(key=1))
     self.assertEqual(x.root.key, 1)
Exemplo n.º 15
0
 def test_insert(self):
     x = splayTree.SplayTree()
     x.insert(splayTree.Node(key=1))
     self.assertFalse(x.root is None)