def test_tree_init():
    # act
    stree = solver.SolverTree()

    # assert
    assert stree.weights == {}
    assert stree.connections == {}
def arrange_stree_in():
    stree = solver.SolverTree()

    for line in IN.split('\n'):
        stree.add(*solver.parse_line(line))

    return stree
def test_tree_add__full():
    # arrange
    stree = solver.SolverTree()

    # act
    for bottom, weight, top in [('pbga', 66, []),
                                ('xhth', 57, []),
                                ('ebii', 61, []),
                                ('havc', 66, []),
                                ('ktlj', 57, []),
                                ('fwft', 72, ['ktlj', 'cntj', 'xhth']),
                                ('qoyq', 66, []),
                                ('padx', 45, ['pbga', 'havc', 'qoyq']),
                                ('tknk', 41, ['ugml', 'padx', 'fwft']),
                                ('jptl', 61, []),
                                ('ugml', 68, ['gyxo', 'ebii', 'jptl']),
                                ('gyxo', 61, []),
                                ('cntj', 57, [])]:
        stree.add(bottom, weight, top)

    # assert
    assert stree.weights == {'pbga': 66, 'xhth': 57, 'ebii': 61, 'havc': 66,
                             'ktlj': 57, 'fwft': 72, 'qoyq': 66, 'padx': 45,
                             'tknk': 41, 'jptl': 61, 'ugml': 68, 'gyxo': 61,
                             'cntj': 57}
    assert stree.connections == {'tknk': [{'ugml': [{'gyxo': []}, {'ebii': []}, {'jptl': []}]},
                                          {'padx': [{'pbga': []}, {'havc': []}, {'qoyq': []}]},
                                          {'fwft': [{'ktlj': []}, {'cntj': []}, {'xhth': []}]}]}
    assert stree.is_tree_connected() is True
    assert stree.get_root() == 'tknk'
def test_tree_add__first_add(bottom, weight, top, weights, connections):
    # arrange
    stree = solver.SolverTree()

    # act
    stree.add(bottom, weight, top)

    # assert
    assert stree.weights == weights
    assert stree.connections == connections
def test_tree_add__first_and_second_add_2():
    # arrange
    stree = solver.SolverTree()

    # act
    stree.add('tknk', 41, ['ugml', 'padx', 'fwft'])
    stree.add('fwft', 72, ['ktlj', 'cntj', 'xhth'])

    # assert
    assert stree.weights == {'tknk': 41, 'fwft': 72}
    assert stree.connections == {'tknk': ['ugml', 'padx', {'fwft': ['ktlj', 'cntj', 'xhth']}]}
def test_tree_not_connected():
    # arrange
    stree = solver.SolverTree()

    # act
    stree.add('a', 1, [])
    stree.add('b', 1, [])

    # assert
    assert stree.is_tree_connected() is False
    assert stree.get_root() is None
def test_tree_add__other_adds():
    # arrange
    stree = solver.SolverTree()

    # act
    stree.add('a', 1, ['b', 'c'])
    stree.add('b', 2, ['d', 'e'])
    stree.add('d', 3, ['f', 'g'])

    # assert
    assert stree.weights == {'a': 1, 'b': 2, 'd': 3}
    assert stree.connections == {'a': [{'b': [{'d': ['f', 'g']}, 'e']}, 'c']}