From 53b7bd040284aa672c761affcb9b2cb2370ef55b Mon Sep 17 00:00:00 2001 From: Forest Belton Date: Sat, 24 Jul 2021 13:05:17 -0400 Subject: [PATCH] Add tests for bit and CPU instructions --- tests/insn/test_bit.py | 47 ++++++++++++++++++++++++++++++++++++++++++ tests/insn/test_cpu.py | 24 +++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 tests/insn/test_bit.py create mode 100644 tests/insn/test_cpu.py diff --git a/tests/insn/test_bit.py b/tests/insn/test_bit.py new file mode 100644 index 0000000..2c2613a --- /dev/null +++ b/tests/insn/test_bit.py @@ -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 diff --git a/tests/insn/test_cpu.py b/tests/insn/test_cpu.py new file mode 100644 index 0000000..3c5dec1 --- /dev/null +++ b/tests/insn/test_cpu.py @@ -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