Browse Source

Add tests for bit and CPU instructions

master
Forest Belton 3 years ago
parent
commit
53b7bd0402
2 changed files with 71 additions and 0 deletions
  1. +47
    -0
      tests/insn/test_bit.py
  2. +24
    -0
      tests/insn/test_cpu.py

+ 47
- 0
tests/insn/test_bit.py View File

@ -0,0 +1,47 @@
import pytest
from tests.insn.helpers import *
@pytest.mark.parametrize("n,r", [(n, r) for n in range(8) for r in R8])
def test_set_n_r(n, r):
cpu = CPU()
SET_N_R(n, r).exec(cpu)
assert cpu.get_reg8(r) == 1 << n
assert cpu.cycles == 8
@pytest.mark.parametrize("n", range(8))
def test_set_n_hl(n):
cpu = CPU()
cpu.set_reg16(R16.HL, 0x1234)
SET_N_HL(n).exec(cpu)
assert cpu.get_mem8(0x1234) == 1 << n
assert cpu.cycles == 16
@pytest.mark.parametrize("n,r", [(n, r) for n in range(8) for r in R8])
def test_res_n_r(n, r):
cpu = CPU()
cpu.set_reg8(r, 0xFF)
RES_N_R(n, r).exec(cpu)
assert cpu.get_reg8(r) == 0xFF - (1 << n)
assert cpu.cycles == 8
@pytest.mark.parametrize("n", range(8))
def test_res_n_hl(n):
cpu = CPU()
cpu.set_reg16(R16.HL, 0x1234)
cpu.set_mem8(0x1234, 0xFF)
RES_N_HL(n).exec(cpu)
assert cpu.get_mem8(0x1234) == 0xFF - (1 << n)
assert cpu.cycles == 16

+ 24
- 0
tests/insn/test_cpu.py View File

@ -0,0 +1,24 @@
from tests.insn.helpers import *
def test_ccf():
cpu = CPU()
CCF().exec(cpu)
assert cpu.carry == 1
assert cpu.cycles == 4
CCF().exec(cpu)
assert cpu.carry == 0
assert cpu.cycles == 8
def test_scf():
cpu = CPU()
SCF().exec(cpu)
assert cpu.carry == 1
assert cpu.cycles == 4

Loading…
Cancel
Save