예제 #1
0
    def test_part_one(self):
        "Test part one example of Password object"

        # 1. Create Password object from text
        myobj = password.Password(text=aoc_11.from_text(PART_ONE_TEXT))

        # 2. Check the part one result
        self.assertEqual(myobj.part_one(verbose=False), PART_ONE_RESULT)
예제 #2
0
    def test_part_two(self):
        "Test part two example of Solver object"

        # 1. Create Solver object from text
        myobj = solver.Solver(part2=True, text=aoc_11.from_text(PART_TWO_TEXT))

        # 2. Check the part two result
        self.assertEqual(myobj.part_two(verbose=False), PART_TWO_RESULT)
예제 #3
0
    def test_text_init(self):
        "Test the Conway object creation from text"

        # 1. Create Conway object from text
        myobj = conway.Conway(text=aoc_11.from_text(EXAMPLE_TEXT))

        # 2. Make sure it has the expected values
        self.assertEqual(myobj.part2, False)
        self.assertEqual(len(myobj.text), 10)
        self.assertEqual(myobj.rows, 10)
        self.assertEqual(myobj.cols, 10)
        self.assertEqual(myobj.rnds, 0)
        self.assertEqual(myobj.limit, 4)
        self.assertEqual(len(myobj.seats), 71)
        self.assertEqual(len(myobj.current), 0)
        self.assertEqual(myobj.previous, None)

        # 3. Test methods
        self.assertEqual(str(myobj), EXAMPLE_TEXT.strip())
        myobj.fill_all_seats()
        self.assertEqual(myobj.rnds, 1)
        self.assertEqual(len(myobj.seats), 71)
        self.assertEqual(len(myobj.current), 71)
        self.assertEqual(myobj.count_occupied(), 71)
        self.assertEqual(myobj.unchanged(), False)
        self.assertEqual(str(myobj), ROUND_ONE)

        myobj.next_round()
        self.assertEqual(myobj.rnds, 2)
        self.assertEqual(len(myobj.seats), 71)
        self.assertEqual(len(myobj.current), 20)
        self.assertEqual(myobj.count_occupied(), 20)
        self.assertEqual(myobj.unchanged(), False)
        self.assertEqual(str(myobj), ROUND_TWO)

        myobj.next_round()
        self.assertEqual(myobj.rnds, 3)
        self.assertEqual(myobj.unchanged(), False)
        self.assertEqual(str(myobj), ROUND_THREE)

        myobj.next_round()
        self.assertEqual(myobj.rnds, 4)
        self.assertEqual(myobj.unchanged(), False)
        self.assertEqual(str(myobj), ROUND_FOUR)

        myobj.next_round()
        self.assertEqual(myobj.rnds, 5)
        self.assertEqual(myobj.unchanged(), False)
        self.assertEqual(str(myobj), ROUND_FIVE)
        self.assertEqual(myobj.count_occupied(), 37)

        myobj.next_round()
        self.assertEqual(myobj.rnds, 6)
        self.assertEqual(myobj.unchanged(), True)
        self.assertEqual(str(myobj), ROUND_FIVE)
        self.assertEqual(myobj.count_occupied(), 37)
예제 #4
0
    def test_text_init(self):
        "Test the Solver object creation from text"

        # 1. Create Solver object from text
        myobj = solver.Solver(text=aoc_11.from_text(EXAMPLE_TEXT))

        # 2. Make sure it has the expected values
        self.assertEqual(myobj.part2, False)
        self.assertEqual(len(myobj.text), 4)

        # 3. Check methods
        self.assertEqual(myobj.number_moves(), 11)
예제 #5
0
    def test_text_init(self):
        "Test the Fuelcell object creation from text"

        # 1. Create Fuelcell object from text
        myobj = fuelcell.Fuelcell(text=aoc_11.from_text(EXAMPLE_TEXT))

        # 2. Make sure it has the expected values
        self.assertEqual(myobj.part2, False)
        self.assertEqual(len(myobj.text), 1)
        self.assertEqual(myobj.width, 300)
        self.assertEqual(myobj.height, 300)
        self.assertEqual(myobj.serial, 8)
        self.assertEqual(len(myobj.cells), myobj.width * myobj.height)
        self.assertEqual(myobj.cell_at(3, 5), 4)
예제 #6
0
    def test_goal_init(self):
        "Test the State object creation from goal text"

        # 1. Create Generators object from text
        myobj = state.State(text=aoc_11.from_text(GOAL_TEXT))

        # 2. Make sure it has the expected values
        self.assertEqual(myobj.part2, False)
        self.assertEqual(len(myobj.text), 5)
        self.assertEqual(str(myobj.lift), "The elevator is on floor 4 of 4.")
        self.assertEqual(len(myobj.floors), 4)
        self.assertEqual(len(myobj.items), 4)

        # 3. Check methods
        self.assertEqual(myobj.is_goal(), True)
        self.assertEqual(myobj.is_safe(), True)
예제 #7
0
    def test_text_init(self):
        "Test the Flashers object creation from text"

        # 1. Create Flashers object from text
        myobj = flashers.Flashers(text=aoc_11.from_text(EXAMPLE_TEXT))

        # 2. Make sure it has the expected values
        self.assertEqual(myobj.part2, False)
        self.assertEqual(len(myobj.text), 10)
        self.assertEqual(len(myobj.octos), 100)
        self.assertEqual(myobj.flashes, 0)
        self.assertEqual(myobj.step, 0)
        self.assertEqual(str(myobj).strip(), EXAMPLE_TEXT.strip())

        # 3. Check methods
        self.assertEqual(len(myobj.neighbors((0, 0))), 3)
        self.assertEqual(len(myobj.neighbors((1, 0))), 5)
        self.assertEqual(len(myobj.neighbors((1, 1))), 8)

        self.assertEqual(myobj.single_step(), 0)
        self.assertEqual(len(myobj.octos), 100)
        self.assertEqual(myobj.flashes, 0)
        self.assertEqual(myobj.step, 1)
        self.assertEqual(str(myobj).strip(), STEP_ONE.strip())

        self.assertEqual(myobj.single_step(), 35)
        self.assertEqual(len(myobj.octos), 100)
        self.assertEqual(myobj.flashes, 35)
        self.assertEqual(myobj.step, 2)
        self.assertEqual(str(myobj).strip(), STEP_TWO.strip())

        self.assertEqual(myobj.run_until(10), 204)
        self.assertEqual(len(myobj.octos), 100)
        self.assertEqual(myobj.flashes, 204)
        self.assertEqual(myobj.step, 10)
        self.assertEqual(str(myobj).strip(), STEP_TEN.strip())

        self.assertEqual(myobj.run_until(100), 1656)
        self.assertEqual(len(myobj.octos), 100)
        self.assertEqual(myobj.flashes, 1656)
        self.assertEqual(myobj.step, 100)
        self.assertEqual(str(myobj).strip(), STEP_100.strip())

        self.assertEqual(myobj.all_flash(), 195)
예제 #8
0
    def test_text_init(self):
        "Test the State object creation from text"

        # 1. Create Generators object from text
        myobj = state.State(text=aoc_11.from_text(EXAMPLE_TEXT))

        # 2. Make sure it has the expected values
        self.assertEqual(myobj.part2, False)
        self.assertEqual(len(myobj.text), 5)
        self.assertEqual(str(myobj.lift), "The elevator is on floor 1 of 4.")
        self.assertEqual(len(myobj.floors), 4)
        self.assertEqual(len(myobj.items), 4)

        # 3. Check methods
        self.assertEqual(myobj.is_safe(), True)
        self.assertEqual(str(myobj), EXAMPLE_TEXT.strip())
        self.assertEqual(myobj.trace(), EXAMPLE_TRACE.strip())
        self.assertEqual(myobj.directions(), ['U'])
        self.assertEqual(myobj.is_goal(), False)
        myclone = myobj.clone()
        self.assertEqual(myobj, myclone)
        self.assertEqual(hash(myobj), hash(myclone))
        moves = myobj.legal_moves()
        self.assertEqual(len(moves), 1)
        self.assertEqual(moves[0][0], 'U')
        self.assertEqual(len(moves[0][1]), 1)
        # print(moves[0][1][0])
        self.assertEqual(moves[0][1][0],
                         item.Item(text='hydrogen-compatible microchip'))
        myobj2 = myobj.execute_move(moves[0])
        self.assertEqual(str(myobj2.lift), "The elevator is on floor 2 of 4.")
        self.assertEqual(str(myobj2), TEXT_AFTER_ONE_MOVE.strip())
        self.assertEqual(myobj2.trace(), TRACE_AFTER_ONE_MOVE.strip())
        self.assertEqual(myobj2.is_goal(), False)
        self.assertEqual(myobj2.is_safe(), True)
        move2 = ('U', myobj2.floors[1].element_items("hydrogen"))
        self.assertEqual(move2[0], 'U')
        self.assertEqual(len(move2[1]), 2)
        myobj3 = myobj2.execute_move(move2)
        self.assertEqual(str(myobj3.lift), "The elevator is on floor 3 of 4.")
        self.assertEqual(myobj3.trace(), TRACE_AFTER_TWO_MOVES.strip())
        self.assertEqual(myobj3.is_goal(), False)
        self.assertEqual(myobj3.is_safe(), True)
예제 #9
0
    def test_text_init(self):
        "Test the Password object creation from text"

        # 1. Create Password object from text
        myobj = password.Password(text=aoc_11.from_text(EXAMPLE_TEXT))

        # 2. Make sure it has the expected values
        self.assertEqual(myobj.part2, False)
        self.assertEqual(len(myobj.text), 1)

        # 3. Check methods
        self.assertEqual(myobj.valid_password("hijklmmn"), False)
        self.assertEqual(myobj.valid_password("abbceffg"), False)
        self.assertEqual(myobj.valid_password("abbcegjk"), False)
        self.assertEqual(myobj.valid_password("abcdffaa"), True)
        self.assertEqual(myobj.valid_password("ghjaabcc"), True)

        self.assertEqual(myobj.next_password(), "abcdffaa")
        myobj.current = "ghijklmn"
        self.assertEqual(myobj.next_password(), "ghjaabcc")
예제 #10
0
    def clone(self):
        "Make a copy of the state"

        # 1. Return a copy
        return State(text=aoc_11.from_text(str(self)), part2=self.part2)