Exemple #1
0
    def test_increment_cell(self):
        """
        Test that executing a '+' operation increments the cell
        at the pointer by the correct amount.
        """

        program = Program(1)
        program.execute_one("+")
        self.assertEqual(program.cell, 1, "Cell should be incremented to 1")
Exemple #2
0
    def test_decrement_cell(self):
        """
        Test that executing a '-' operation decrements the cell
        at the pointer by the correct amount.
        """

        program = Program(1)
        program.cell = 1
        program.execute_one("-")
        self.assertEqual(program.cell, 0, "Cell should be decremented to 0")
Exemple #3
0
    def test_loop(self):
        """
        Test that a simple loop will repeat until the end condition
        is met. The cell at the pointer should have a non-zero value
        before the loop and be zero when after the loop.
        """

        program = Program(1)
        program.cell = 3
        program.execute_one(["-"])
        self.assertEqual(program.pointer, 0, "Pointer should be reduced to 0")
Exemple #4
0
    def test_increment_pointer(self):
        """
        Test that executing a '>' command increments the pointer
        by the correct amount.
        There is no need to test wrapping, as it is accomodated
        by modify_pointer.
        """

        program = Program(2)
        program.execute_one(">")
        self.assertEqual(program.pointer, 1,
                         "Pointer should be incremented by 1")