예제 #1
0
 def test_program_error_different_movements(self):
     tape = Tape()
     tape.set_string("0101")
     str_program = "S0, 0, 1, R, S0;S0, 0, 1, L, S0"
     with self.assertRaises(InvalidInstructionPair):
         program = Program(tape)
         program.build(str_program)
예제 #2
0
 def test_program_with_log1(self):
     tape = Tape()
     tape.set_string("0101")
     str_program = "S0, 0, 1, R, S0;S0, 1, 0, L, S2"
     program = Program(tape)
     program.build(str_program)
     with self.assertRaises(StopProgram):
         program.run(log=False)
예제 #3
0
    def test_program_error_identical_instructions(self):
        tape = Tape()
        tape.set_string("0101")
        str_program = "S0, 0, 1, R, S0;S1, 0, 1, L, S0;S0, 0, 1, R, S0"
        trozos = str_program.split(";")

        with self.assertRaises(InvalidInstructionPair):
            program = Program(tape)
            program.build(str_program)
예제 #4
0
 def test_tape_with_move_left(self):
     tape = Tape()
     tape.set_string("0101")
     tape.set_current_pos(3)
     tape.move_left()
     str_tape = str(tape)
     self.assertEqual("01>0<1", str_tape)
예제 #5
0
    def test_program1(self):
        tape = Tape()
        tape.set_string("0101")
        str_program = "S0, 0, 1, R, S0;S0, 1, 0, L, S0"
        program = Program(tape)
        program.build(str_program)
        program.execute_next_instruction()

        self.assertEqual(program.get_tape_string(), "1101")

        program.execute_next_instruction()
        self.assertEqual(program.get_tape_string(), "1001")

        with self.assertRaises(InvalidTapePositionError):
            program.execute_next_instruction()
예제 #6
0
 def test_load_external_program(self):
     filepath = os.path.join("examples", "increment_number.txt")
     tape = Tape()
     tape.set_string("000111")
     for i in range(0, 5):
         tape.move_right()
     program = Program(tape)
     program.load_file_program(filepath)
     with self.assertRaises(StopProgram):
         program.run()
예제 #7
0
 def test_program2(self):
     tape = Tape()
     tape.set_string("0101")
     str_program = "\nS0, 0, 1, R, S0;S0, 1, 0, L, S0;"
     program = Program(tape)
     program.build(str_program)
예제 #8
0
 def test_tape_with_move_right(self):
     tape = Tape()
     tape.set_string("0101")
     tape.move_right()
     str_tape = str(tape)
     self.assertEqual("0>1<01", str_tape)
예제 #9
0
 def test_tape1(self):
     tape = Tape()
     tape.set_string("0101")
     str_tape = str(tape)
     self.assertEqual(">0<101", str_tape)