def test_from_three_distinct_values(self): expected_bst = BST(2, BST(1), BST(3)) self.assertEqual(BST.from_values([1, 2, 3]), expected_bst) self.assertEqual(BST.from_values([3, 2, 1]), expected_bst) self.assertEqual(BST.from_values([2, 1, 3]), expected_bst) self.assertEqual(BST.from_values([2, 1, 3, 3]), expected_bst) expected_bst = BST(10, BST(5), BST(42)) self.assertEqual(BST.from_values([10, 42, 5]), expected_bst)
def test_from_seven_distinct_values(self): expected_bst = BST(4, BST(2, BST(1), BST(3)), BST(6, BST(5), BST(7))) self.assertEqual(BST.from_values([1, 2, 3, 4, 5, 6, 7 ]), expected_bst)
def test_from_five_distinct_values(self): expected_bst = BST(3, BST(2, BST(1)), BST(5, BST(4))) self.assertEqual(BST.from_values([1, 2, 3, 4, 5]), expected_bst)
def test_from_two_distinct_value(self): expected_bst = BST(2, BST(1)) self.assertEqual(BST.from_values([1, 2]), expected_bst) self.assertEqual(BST.from_values([2, 1]), expected_bst) self.assertEqual(BST.from_values([1, 2, 1]), expected_bst)
def test_from_one_value(self): self.assertEqual(BST.from_values([1]), BST(1))
def test_from_empty(self): self.assertEqual(BST.from_values([]), BST())