Exemplo n.º 1
0
    def test_part_two(self):
        "Test part two example of Rooms object"

        # 1. Create Rooms object from text
        myobj = rooms.Rooms(part2=True, text=aoc_20.from_text(PART_TWO_TEXT))

        # 2. Check the part two result
        self.assertEqual(myobj.part_two(verbose=False), PART_TWO_RESULT)
Exemplo n.º 2
0
    def test_part_one(self):
        "Test part one example of Rooms object"

        # 1. Create Rooms object from text
        myobj = rooms.Rooms(text=aoc_20.from_text(PART_ONE_TEXT))

        # 2. Check the part one result
        self.assertEqual(myobj.part_one(verbose=False), PART_ONE_RESULT)
Exemplo n.º 3
0
    def test_empty_init(self):
        "Test the default Rooms creation"

        # 1. Create default Rooms object
        myobj = rooms.Rooms()

        # 2. Make sure it has the default values
        self.assertEqual(myobj.part2, False)
        self.assertEqual(myobj.text, None)
        self.assertEqual(myobj.regex, None)
        self.assertEqual(myobj.doors, None)
Exemplo n.º 4
0
    def test_value_init(self):
        "Test the Node object creation with location and doors"

        # 1. Create Node object from values
        myrooms = rooms.Rooms(text=aoc_20.from_text(EXAMPLE_ONE_TEXT))
        myobj = path.Node(location=rooms.START, doors=myrooms.doors)

        # 2. Make sure it has the expected values
        self.assertEqual(myobj.location, rooms.START)
        self.assertEqual(myobj.previous, None)
        self.assertEqual(myobj.doors, myrooms.doors)
        self.assertEqual(myobj.steps, 0)
        self.assertEqual(myobj.adjacent, [None, None, None, -1])
Exemplo n.º 5
0
def part_two(args, input_lines):
    "Process part two of the puzzle"

    # 1. Create the puzzle solver
    solver = rooms.Rooms(part2=True, text=input_lines)

    # 2. Determine the solution for part two
    solution = solver.part_two(verbose=args.verbose, limit=args.limit)
    if solution is None:
        print("There is no solution")
    else:
        print("The solution for part two is %s" % (solution))

    # 3. Return result
    return solution is not None
Exemplo n.º 6
0
    def test_examples(self):
        "Test all of the examples"

        # 1. Loop for all of the examples
        for example in EXAMPLES:

            # 2. Created the Rooms object from text
            myobj = rooms.Rooms(text=aoc_20.from_text(example['text']))
            self.assertEqual(myobj.regex, example['text'].strip())

            # 3. Check the map
            self.assertEqual(str(myobj), example['str'].strip())

            # 4. Check the doors
            mypath = path.Path(start=rooms.START, doors=myobj.doors)
            self.assertEqual(mypath.furthest(), example['doors'])
Exemplo n.º 7
0
    def test_value_init(self):
        "Test the Path object creation with values"

        # 1. Create Node object from values
        myrooms = rooms.Rooms(text=aoc_20.from_text(EXAMPLE_ONE_TEXT))
        myobj = path.Path(start=rooms.START, doors=myrooms.doors)

        # 2. Make sure it has the expected values
        self.assertEqual(myobj.start, rooms.START)
        self.assertEqual(myobj.doors, myrooms.doors)
        self.assertNotEqual(myobj.node, None)
        self.assertEqual(myobj.node.location, myobj.start)
        self.assertEqual(myobj.node.doors, myrooms.doors)
        self.assertTrue(myobj.nodes, 4)
        self.assertEqual(len(myobj.queue), 0)
        self.assertEqual(myobj.furthest(), EXAMPLE_ONE_DOORS)
Exemplo n.º 8
0
    def test_example_two(self):
        "Test the Rooms object creation from text"

        # 1. Create Rooms object from text
        myobj = rooms.Rooms(text=aoc_20.from_text(EXAMPLE_TWO_TEXT))

        # 2. Make sure it has the expected values
        self.assertEqual(myobj.part2, False)
        self.assertEqual(len(myobj.text), 1)
        self.assertEqual(myobj.regex, EXAMPLE_TWO_TEXT.strip())
        self.assertEqual(len(myobj.doors), 15 * 2)
        dims = myobj.dimensions()
        self.assertEqual(dims['N'], -2)
        self.assertEqual(dims['S'], 1)
        self.assertEqual(dims['E'], 1)
        self.assertEqual(dims['W'], -2)
        self.assertEqual(str(myobj), EXAMPLE_TWO_STR.strip())