Exemple #1
0
def test_node_find_existing(name_to_find, expected_bracket_string):
    bracket_tree = "A(CD(Arr(CD)))(E(F)(G))(CD)(H(D)(MN))"
    bt = parse(bracket_tree)

    found = bt.find(name_to_find)
    assert found is not None
    assert found.bracket_representation() == expected_bracket_string
Exemple #2
0
def test_node_add_find_valid():
    bt = parse("H(D(A(C)))(MN)")
    assert bt is not None

    c = bt.find("C")
    assert c is not None

    c.add_child("A(H(K))")
    assert c.bracket_representation() == "C(A(H(K)))"
    assert bt.bracket_representation() == "H(D(A(C(A(H(K))))))(MN)"

    c.add_child("B(C)(D)")
    assert c.bracket_representation() == "C(A(H(K)))(B(C)(D))"
    assert bt.bracket_representation() == "H(D(A(C(A(H(K)))(B(C)(D)))))(MN)"

    bt.add_child("A")
    assert bt.bracket_representation() == "H(D(A(C(A(H(K)))(B(C)(D)))))(MN)(A)"
 def add_child(self, bracket_tree: str) -> None:
     self.children.append(parser.parse(bracket_tree))
Exemple #4
0
def test_node_add_invalid(test_case):
    bt = parse("H(D)(MN)")
    with pytest.raises(ParseException):
        bt.add_child(test_case["bracketTree"])
Exemple #5
0
def test_node_add_valid():
    bt = parse("H(D)(MN)")

    bt.add_child("A(H)(K)(L)")
    assert bt.bracket_representation() == "H(D)(MN)(A(H)(K)(L))"
Exemple #6
0
def test_node_find_non_existing(name_to_find):
    bt = parse("H(D)(MN)")

    found = bt.find(name_to_find)
    assert found is None
Exemple #7
0
def test_node_count_leaves(test_case):
    n = parse(test_case["bracketTree"])
    assert n.count_leaves() == test_case["numLeaves"]
Exemple #8
0
def test_node_parse_invalid_bracket_tree(test_case):
    with pytest.raises(ParseException):
        parse(test_case["bracketTree"])
Exemple #9
0
def test_node_parse_valid_bracket_tree(test_case):
    n = parse(test_case["bracketTree"])
    assert n is not None
    assert n.bracket_representation() == test_case["bracketTree"]