コード例 #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)
コード例 #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()
コード例 #3
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
コード例 #4
0
 def test_init(self):
     collection = MpNumberCollection(json_path="tests/fixtures/5-10.json")
     tree = Tree(collection)
     assert tree.collection == collection
コード例 #5
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