def test_max(self): n1 = Node(2) n2 = Node(3) n3 = Node(4) n1.add_right(n2) n2.add_right(n3) self.assertEqual(n1.max(), n3)
def test_is_leaf(self): n1 = Node(2) self.assertTrue(n1.isLeaf()) n1.add_left(Node(34)) self.assertFalse(n1.isLeaf()) n1.add_right(Node(5)) self.assertFalse(n1.isLeaf())
def test_get_successor(self): n1 = Node(2) n2 = Node(3) n3 = Node(4) n1.add_left(n2) n2.add_right(n3) self.assertEqual(n3.getSuccessor(), n1)
def test_on_left(self): n1 = Node(2) n2 = Node(3) n3 = Node(4) n1.add_left(n2) n1.add_right(n3) self.assertTrue(n1.on_left(n2)) self.assertFalse(n1.on_left(n3))
def test_disconnect_right(self): n1 = Node(2) n2 = Node(3) n1.add_right(n2) self.assertEqual(n2.parent, n1) self.assertEqual(n1.right, n2) n1.disconnect_right() self.assertIsNone(n2.parent) self.assertIsNone(n1.right)
def test_get_pred_succ_while_no_condition(self): n1 = Node(2) n2 = Node(3) n3 = Node(4) n4 = Node(5) n1.add_left(n2) n1.add_right(n3) n3.add_left(n4) succresults = n2.getSuccessor_while(lambda x: True) self.assertEqual(succresults, [n1,n4,n3]) predresults = n3.getPredecessor_while(lambda x: True) self.assertEqual(predresults, [n4,n1,n2]) neighbours = n1.getNeighbours_while(lambda x: True) self.assertEqual(neighbours, [n2,n4,n3])
def test_rotate_left(self): n0 = Node(1) n1 = Node(2) n2 = Node(3) n3 = Node(4) n4 = Node(5) n0.add_right(n1) n1.add_left(n2) n1.add_right(n3) n3.add_left(n4) setAsRoot, newHead = n1.rotate_left() #self.assertTrue(setAsRoot) self.assertEqual(newHead, n3) self.assertEqual(n1.right, n4) self.assertEqual(n4.parent, n1) self.assertEqual(n0.right, newHead)
def test_add_right(self): n1 = Node(2) n2 = Node(3) self.assertIsNone(n1.right) n1.add_right(n2) self.assertEqual(n1.right, n2)
def test_get_successor_basic_2(self): n1 = Node(2) n2 = Node(3) n1.add_right(n2) self.assertEqual(n1.getSuccessor(), n2)
def test_get_predecessor_basic_2(self): n1 = Node(2) n2 = Node(3) n1.add_right(n2) self.assertEqual(n2.getPredecessor(), n1)