def test_with_children_false(self): self.assertFalse(solution(BinaryNode.parse_tree("[[second_level_diff_1]" "root" "[second_level_diff_2]]"))) self.assertFalse( solution( BinaryNode.parse_tree( "[[[third_level_structure_diff]second_level_same]" "root" "[[third_level_structure_diff]second_level_same]]" ) ) ) self.assertFalse( solution( BinaryNode.parse_tree( "[[second_level_same[third_level_same[forth_level_diff_1]]]" "root" "[[[forth_level_diff_2]third_level_same]second_level_same]" ) ) ) self.assertFalse( solution( BinaryNode.parse_tree( "[[[[forth_level_structure_diff]third_level_same]second_level_same]" "root" "[second_level_same[[forth_level_structure_diff]third_level_same]]]" ) ) )
def test_int(self): min_bst_queue = MinBSTQueue(BinaryNode.parse_tree("[[1[[2]3[4]]]5[6]]", int)) self.assertEqual(min_bst_queue.get().value, 1) self.assertEqual(min_bst_queue.get().value, 2) self.assertEqual(min_bst_queue.get().value, 3) self.assertEqual(min_bst_queue.get().value, 4) self.assertEqual(min_bst_queue.get().value, 5) self.assertEqual(min_bst_queue.get().value, 6)
def test_with_children_true(self): self.assertTrue(solution(BinaryNode.parse_tree("[[second_level_same]" "root" "[second_level_same]]"))) self.assertTrue( solution( BinaryNode.parse_tree( "[[[third_level_same]second_level_same]" "root" "[second_level_same[third_level_same]]]" ) ) ) self.assertTrue( solution( BinaryNode.parse_tree( "[[[third_level_same[forth_level_same]]second_level_same]" "root" "[second_level_same[[forth_level_same]third_level_same]]]" ) ) )
def test_complete_binary_tree(self): tree = BinaryNode.parse_tree("[[[5]3[4]]5[[6]12[2]]]", int) self.assertEqual("54623125", solution(tree))
def test_binary_tree(self): tree = BinaryNode.parse_tree("[[[3]2[[5]4]]1[[4[5]]2[3]]]", int) self.assertEqual("553443221", solution(tree))
def test_one_node(self): min_bst_queue = MinBSTQueue(BinaryNode.parse_tree("[1]", int)) self.assertEqual(min_bst_queue.get().value, 1)
def test_no_right(self): min_bst_queue = MinBSTQueue(BinaryNode.parse_tree("[[1]2]", int)) self.assertEqual(min_bst_queue.get().value, 1) self.assertEqual(min_bst_queue.get().value, 2)
def test_no_left(self): binary_tree = BinaryNode.parse_tree("[1[2]]", int) min_bst_queue = MinBSTQueue(binary_tree) self.assertEqual(min_bst_queue.get().value, 1) self.assertEqual(min_bst_queue.get().value, 2)
def test_non_symmetric_tree(self): tree = BinaryNode.parse_tree("[[1[[2]3[4]]]5]", int) solution(tree) tree2 = BinaryNode.parse_tree("[5[[[4]3[2]]1]]", int) self.assertEqual(tree, tree2)
def test_symmetric_tree(self): tree = BinaryNode.parse_tree("[[[3]2[[5]4]]1[[4[5]]2[3]]]", int) solution(tree) tree2 = BinaryNode.parse_tree("[[[3]2[[5]4]]1[[4[5]]2[3]]]", int) self.assertEqual(tree, tree2)
def test_many(self): tree = BinaryNode.parse_tree("[[1[[5]3[4]]]5[6[11]]]", int) sol = solution(tree, 10) self.assertEqual(10, sol[0].value + sol[1].value)
def test_no_sol(self): tree = BinaryNode.parse_tree("[[1[[5]3[4]]]5[6[12]]]", int) sol = solution(tree, 12) self.assertIsNone(sol)