Ejemplo n.º 1
0
    def test_next_step_pc_larger_than_rom_InvalidPcException(self):
        # arrange
        sut = Vm()
        sut.rom = [7, 7, 7]
        sut.program_count = 4

        # act
        action = sut.next_step

        # assert
        self.assertRaises(InvalidPcException, action)
Ejemplo n.º 2
0
    def test_jump_invalid_target(self):
        # arrange
        sut = Vm()
        sut.program_count = 1
        sut.rom = [sut.OPC_NOP, sut.OPC_JUMP, 3]

        # act
        action = sut.next_step

        # assert
        self.assertRaises(InvalidPcException, action)
Ejemplo n.º 3
0
    def test_next_step_pc_negative_InvalidPcException(self):
        # arrange
        sut = Vm()
        sut.rom = [7, 7, 7]
        sut.program_count = -1

        # act
        action = sut.next_step

        # assert
        self.assertRaises(InvalidPcException, action)
Ejemplo n.º 4
0
    def test_jump(self):
        # arrange
        sut = Vm()
        sut.program_count = 1
        sut.rom = [sut.OPC_NOP, sut.OPC_JUMP, 0]

        # act
        sut.next_step()

        # assert
        self.assertEqual(sut.program_count, 0)
Ejemplo n.º 5
0
    def test_jumpa_invalid_target(self):
        # arrange
        sut = Vm()
        sut.rom = [sut.OPC_NOP, sut.OPC_NOP, sut.OPC_JUMPA]
        sut.accumulator = 5
        sut.program_count = 2

        # act
        action = sut.next_step

        # assert
        self.assertRaises(InvalidPcException, action)
Ejemplo n.º 6
0
    def test_jumpa(self):
        # arrange
        sut = Vm()
        sut.rom = [sut.OPC_NOP, sut.OPC_NOP, sut.OPC_JUMPA]
        sut.accumulator = 1
        sut.program_count = 2

        # act
        sut.next_step()

        # assert
        self.assertEqual(sut.program_count, 1)
Ejemplo n.º 7
0
    def test_jumpn_invalid_target_dont_fail(self):
        # arrange
        sut = Vm()
        sut.accumulator = 4
        sut.rom = [sut.OPC_NOP, sut.OPC_JUMPN, 4, sut.OPC_NOP]
        sut.program_count = 1

        # act
        sut.next_step()

        # assert
        self.assertEqual(sut.program_count, 3)
Ejemplo n.º 8
0
    def test_jumpn_invalid_target_fail(self):
        # arrange
        sut = Vm()
        sut.accumulator = -4
        sut.rom = [sut.OPC_NOP, sut.OPC_JUMPN, 4, sut.OPC_NOP]
        sut.program_count = 1

        # act
        action = sut.next_step

        # assert
        self.assertRaises(InvalidPcException, action)
Ejemplo n.º 9
0
    def test_jumpn_dont_jump(self):
        # arrange
        sut = Vm()
        sut.accumulator = 1
        sut.rom = [sut.OPC_NOP, sut.OPC_JUMPN, 0, sut.OPC_NOP]
        sut.program_count = 1

        # act
        sut.next_step()

        # assert
        self.assertEqual(sut.program_count, 3)
Ejemplo n.º 10
0
    def test_ldpc(self):
        # arrange
        sut = Vm()
        sut.rom = [sut.OPC_NOP, sut.OPC_LDPC, sut.OPC_NOP]
        sut.program_count = 1
        sut.accumulator = -4

        # act
        sut.next_step()

        # assert
        self.assertEqual(sut.accumulator, 1)
        self.assertEqual(sut.program_count, 2)