Esempio n. 1
0
def print_tree(root: int = typer.Argument(
    default=None,
    help="Which root should be printed?",
), ):
    collection = MpNumberCollection(json_path="output/0-475.json")
    tree = Tree(collection)
    if root is not None:
        tree.print(root=root)
    tree.print_summary(root=root)
Esempio n. 2
0
    def test_print(self):
        with patch("sys.stdout", new=StringIO()) as fake_out:
            collection = MpNumberCollection(
                json_path="tests/fixtures/5-10.json")
            tree = Tree(collection)
            tree.print(root=42)

            assert "1176" in fake_out.getvalue()

            tree.print(root=0)
            assert "20" in fake_out.getvalue()
Esempio n. 3
0
 def test_init(self):
     collection = MpNumberCollection(json_path="tests/fixtures/5-10.json")
     tree = Tree(collection)
     assert tree.collection == collection
Esempio n. 4
0
 def test_get_max_mp(self):
     collection = MpNumberCollection(json_path="tests/fixtures/0-475.json")
     tree = Tree(collection)
     assert tree.get_max_mp(root=20) == 10
     assert tree.get_max_mp() == 11
Esempio n. 5
0
    def test_add_child(self):
        collection = MpNumberCollection()
        tree = Tree(collection)
        tree.add_child(15)
        five_root = tree.get_node(5)
        assert five_root.children[0].name == 15

        tree.add_child(1176)
        eight_root = tree.get_node(8)
        assert eight_root.children[0].name == 42

        tree.add_child(177147)

        implicit_node = tree.get_node(1372)
        assert implicit_node.name == 1372
        assert implicit_node.parent.name == 42

        root_42 = tree.get_node(42)
        assert len(root_42.children) == 2
Esempio n. 6
0
 def test_get_mp_list(self):
     assert Tree.get_mp_list(18432) == [8, 18, 192, 18432]
     assert Tree.get_mp_list(0) == [0]
Esempio n. 7
0
 def test_get_digit_product(self):
     assert Tree.get_digit_product(81) == 8
     assert Tree.get_digit_product(2231) == 12
     assert Tree.get_digit_product(88341) == 768