예제 #1
0
    def test_decrement_pointer(self):
        """
        Test that executing a '<' command decrements the pointer
        by the correct amount.
        There is no need to test wrapping, as it is accomodated
        by modify_pointer.
        """

        program = Program(2)
        program.modify_pointer(1)
        program.execute_one("<")
        self.assertEqual(program.pointer, 0,
                         "Pointer should be decremented by 1")
예제 #2
0
    def test_modify_pointer(self):
        """
        Test that modify pointer increments and decrements
        the pointer by the correct amount, and wraps around
        by the correct number of cells.
        """

        program = Program(3)
        program.modify_pointer(2)
        self.assertEqual(program.pointer, 2,
                         "Pointer should be incremented by 2")
        program.modify_pointer(-2)
        self.assertEqual(program.pointer, 0,
                         "Pointer should be decremented by 2")
        program.modify_pointer(3)
        self.assertEqual(program.pointer, 0,
                         "Pointer should be incremented by 3 and wrap around")