Beispiel #1
0
    def test_text_init(self):
        """Test UOMap object creation with text"""

        #         G - H       J - K - L
        #        /           /
        # COM - B - C - D - E - F
        #                \
        #                 I

        # 1. Create Wire obhect with values
        mymap = uomap.UOMap(text=TEXT)

        # 2. Check methods
        self.assertEqual(len(mymap.nodes()), 12)
        self.assertTrue(uomap.COM in mymap.dag)
        self.assertTrue('A' not in mymap.nodes())
        self.assertTrue('B' in mymap.nodes())
        self.assertTrue('C' in mymap.nodes())
        self.assertTrue('D' in mymap.nodes())
        self.assertEqual(mymap.direct_links(), 11)
        self.assertEqual(mymap.orbits('B'), 1)
        self.assertEqual(mymap.orbits('C'), 2)
        self.assertEqual(mymap.orbits('D'), 3)
        self.assertEqual(mymap.orbits('E'), 4)
        self.assertEqual(mymap.orbits('F'), 5)
        self.assertEqual(mymap.orbits('G'), 2)
        self.assertEqual(mymap.orbits('H'), 3)
        self.assertEqual(mymap.orbits('I'), 4)
        self.assertEqual(mymap.orbits('J'), 5)
        self.assertEqual(mymap.orbits('K'), 6)
        self.assertEqual(mymap.orbits('L'), 7)
        self.assertEqual(mymap.total_orbits(), 42)
Beispiel #2
0
    def test_part_two(self):
        """Test part2 minimum_transfers"""

        #                           YOU
        #                          /
        #         G - H       J - K - L
        #        /           /
        # COM - B - C - D - E - F
        #                \
        #                 I - SAN

        # 1. Create Wire obhect with values
        mymap = uomap.UOMap(text=TEXT + PART2)

        # 2. Check methods
        self.assertEqual(len(mymap.nodes()), 14)
        self.assertTrue('YOU' in mymap.nodes())
        self.assertTrue('SAN' in mymap.nodes())
        self.assertEqual(mymap.find_shortest_path(uomap.COM, 'I'),
                         ['COM', 'B', 'C', 'D', 'I'])
        self.assertEqual(mymap.find_shortest_path(uomap.COM, 'K'),
                         ['COM', 'B', 'C', 'D', 'E', 'J', 'K'])
        self.assertEqual(mymap.minimum_transfers('I', 'K'), 4)
        self.assertEqual(mymap.minimum_transfers(uomap.YOU, uomap.SANTA), 4)
        self.assertEqual(mymap.minimum_transfers(uomap.SANTA, uomap.YOU), 4)
Beispiel #3
0
    def test_empty_init(self):
        """Test default UOMap object creation"""

        # 1. Create default UOMap object
        mymap = uomap.UOMap()

        # 2. Check methods
        self.assertEqual(len(mymap.nodes()), 0)
        self.assertEqual(mymap.direct_links(), 0)
        self.assertEqual(mymap.total_orbits(), 0)
Beispiel #4
0
def part_two(args, input_lines):
    "Process part two of the puzzle"

    # 1. Create the Universal Orbital Map
    mymap = uomap.UOMap(text=input_lines)
    if args.verbose:
        print("The map has %d orbital bodies" % len(mymap.bodies()))

    # 2. Get the minimal number of orbital transfer from me to Santa
    solution = mymap.minimum_transfers(uomap.YOU, uomap.SANTA)
    if solution is not None:
        print("%d orbitital transfers required" % (solution))
    else:
        print("Unable to determine orbital transfer")

    # 3. Return result
    return solution is not None
Beispiel #5
0
def part_one(args, input_lines):
    "Process part one of the puzzle"

    # 1. Create the Universal Orbital Map
    mymap = uomap.UOMap(text=input_lines)
    if args.verbose:
        print("The map has %d orbital bodies" % len(mymap.bodies()))

    # 2. Get the total number of direct and indirect orbits
    solution = mymap.total_orbits()
    if solution is not None:
        print("The map has %d orbits" % (solution))
    else:
        print("Unable to determine total orbits")

    # 3. Return result
    return solution is not None