def test_add_and_count_direct():
    tree = OrbitTree('O')
    tree.add('O', 'A')
    tree.add('O', 'B')
    tree.add('A', 'AA')

    direct_orbits_count = tree.count_direct_orbits()
    assert_equal(direct_orbits_count, 3)

    tree.add('A', 'AAA')
    tree.add('B', 'C')

    direct_orbits_count = tree.count_direct_orbits()
    assert_equal(direct_orbits_count, 5)
def test_find_path_between_for_given_map():
    tree = OrbitTree('COM')
    tree.add('COM', 'B')
    tree.add('B', 'G')
    tree.add('G', 'H')
    tree.add('B', 'C')
    tree.add('C', 'D')
    tree.add('D', 'I')
    tree.add('D', 'E')
    tree.add('E', 'J')
    tree.add('J', 'K')
    tree.add('K', 'L')
    tree.add('E', 'F')
    tree.add('K', 'US')
    tree.add('I', 'SAN')

    path = tree.find_shortest_path_between('US', 'SAN')
    assert_equal(path, 4)
def test_LCA_for_given_map():
    tree = OrbitTree('COM')
    tree.add('COM', 'B')
    tree.add('B', 'G')
    tree.add('G', 'H')
    tree.add('B', 'C')
    tree.add('C', 'D')
    tree.add('D', 'I')
    tree.add('D', 'E')
    tree.add('E', 'J')
    tree.add('J', 'K')
    tree.add('K', 'L')
    tree.add('E', 'F')
    tree.add('K', 'US')
    tree.add('I', 'SAN')

    lca = tree.find_LCA('US', 'SAN')
    assert_equal(lca.data, 'D')
def test_for_given_map():
    tree = OrbitTree('COM')
    tree.add('COM', 'B')
    tree.add('B', 'G')
    tree.add('G', 'H')
    tree.add('B', 'C')
    tree.add('C', 'D')
    tree.add('D', 'I')
    tree.add('D', 'E')
    tree.add('E', 'J')
    tree.add('J', 'K')
    tree.add('K', 'L')
    tree.add('E', 'F')

    total_orbits = tree.count_direct_orbits() + tree.count_indirect_orbits()
    assert_equal(total_orbits, 42)
def build_tree(tree: OrbitTree, id: str, tuples: [tuple]):
    next_nodes = next_to_append(id, tuples)
    for n in next_nodes:
        tree.add(n[0], n[1])
        build_tree(tree, n[1], tuples)