def test_p4_true(self): self.tree.root = BTNode(1) self.tree.root.left = BTNode(2) self.tree.root.right = BTNode(3) self.tree.root.left.left = BTNode(4) self.tree.root.left.right = BTNode(5) self.assertTrue(p4(self.tree.root))
def p2(arr, tree): if len(arr) > 2: mid = len(arr) / 2 mid = int(mid) left = arr[:mid] tree.add(BTNode(arr.pop(mid))) right = arr[mid:] p2(left, tree) p2(right, tree) else: if len(arr) == 2: tree.add(BTNode(arr.pop())) tree.add(BTNode(arr.pop())) elif len(arr) == 1: tree.add(BTNode(arr.pop()))
def test_p5_notBst(self): self.tree.root = BTNode(5) self.tree.root.left = BTNode(10) self.tree.root.left.left = BTNode(1) self.tree.root.left.right = BTNode(3) self.tree.root.right = BTNode(7) self.tree.root.right.left = BTNode(6) self.tree.root.right.right = BTNode(8) self.assertFalse(p5(self.tree))
def test_p5_bst(self): self.tree.root = BTNode(5) self.tree.root.left = BTNode(2) self.tree.root.left.left = BTNode(1) self.tree.root.left.right = BTNode(3) self.tree.root.right = BTNode(7) self.tree.root.right.left = BTNode(6) self.tree.root.right.right = BTNode(8) self.assertTrue(p5(self.tree))
def test_p4_false(self): self.tree.root = BTNode(1) self.tree.root.left = BTNode(2) self.tree.root.right = BTNode(3) self.tree.root.left.left = BTNode(4) self.tree.root.left.right = BTNode(5) self.tree.root.left.left.left = BTNode(8) self.assertFalse(p4(self.tree.root))
def test_p3_D2(self): self.tree.add(BTNode(5)) self.tree.add(BTNode(2)) self.tree.add(BTNode(7)) self.assertEqual(len(p3(self.tree)), 2)
def test_p3(self): self.tree.add(BTNode(5)) for x in range(10): self.tree.add(BTNode(x)) self.assertEqual(len(p3(self.tree)), 6)