コード例 #1
0
def main(args: dict):
    """This is main function in project"""
    print("start main")
    if "help" in args:
        print_help()
        return None

    if "table" in args:
        table = load_table(args["table"])
    else:
        table = dict()
        for i in range(1, 16):
            table[(i * 10, 32)] = 1

    print(table)

    if "tree" in args:
        if args["tree"] == "avl":
            build_avl_tree(table)
        elif args["tree"] == "bct":
            build_binary_compressed_tree(table)
        elif args["tree"] == "bt":
            build_binary_tree(table)
        else:
            print_help()
    else:
        print_help()
 def test_build_binary_tree(self):
     array = [-10, 9, 20, None, None, 15, 7]
     root = build_binary_tree(array)
     in_order_array = []
     in_order(root, in_order_array)
     array.remove(None)
     self.assertEqual(self.list_equal([-10, 9, 20, 15, 7], in_order_array),
                      True)
 def test_build_binary_tree02(self):
     array = [5, 4, 8, 11, None, 13, 4, 7, 2, None, None, None, 1]
     root = build_binary_tree(array)
     in_order_array = []
     in_order(root, in_order_array)
     array.remove(None)
     self.assertEqual(
         self.list_equal([5, 4, 11, 7, 2, 8, 13, 4, 1], in_order_array),
         True)
 def test_maxPathSum(self):
     root = build_binary_tree([-10, 9, 20, None, None, 15, 7])
     self.assertEqual(Solution().maxPathSum(root), 42)
 def test_maxPathSum03(self):
     root = build_binary_tree(
         [5, 4, 8, 11, None, 13, 4, 7, 2, None, None, None, 1])
     self.assertEqual(Solution().maxPathSum(root), 48)
 def test_maxPathSum02(self):
     root = build_binary_tree([1, -2, -3, 1, 3, -2, None, -1])
     self.assertEqual(Solution().maxPathSum(root), 3)
 def test_maxPathSum01(self):
     root = build_binary_tree([-2, -1])
     self.assertEqual(Solution().maxPathSum(root), -1)
 def test_level_order01(self):
     array = [5, 4, 8, 1]
     root = build_binary_tree(array)
     self.assertEqual(
         self.list_equal([[5], [4, 8], [1]], level_order(root)), True)