"""Unit tests for pure Galaxian palette-PROM decoding.""" import pytest from galemu.video import PALETTE_PROM_SIZE, decode_palette_entry, decode_palette_prom @pytest.mark.parametrize( ("encoded", "expected"), [ (0x00, (0x00, 0x00, 0x00)), (0x07, (0xFF, 0x00, 0x00)), (0x38, (0x00, 0xFF, 0x00)), (0xC0, (0x00, 0x00, 0xFF)), (0xFF, (0xFF, 0xFF, 0xFF)), (0x56, (0xDE, 0x47, 0x55)), ], ) def test_palette_entry_uses_the_documented_resistor_weights( encoded: int, expected: tuple[int, int, int], ) -> None: assert decode_palette_entry(encoded) == expected @pytest.mark.parametrize("value", [-1, 0x100]) def test_palette_entry_rejects_non_byte_values(value: int) -> None: with pytest.raises(ValueError, match="palette PROM value must be a byte"): decode_palette_entry(value) def test_palette_prom_preserves_address_order() -> None: prom = bytes(range(PALETTE_PROM_SIZE)) palette = decode_palette_prom(prom) assert len(palette) == PALETTE_PROM_SIZE assert palette[0] == (0x00, 0x00, 0x00) assert palette[7] == (0xFF, 0x00, 0x00) assert palette[31] == decode_palette_entry(31) @pytest.mark.parametrize("size", [0, PALETTE_PROM_SIZE - 1, PALETTE_PROM_SIZE + 1]) def test_palette_prom_requires_the_board_prom_size(size: int) -> None: with pytest.raises(ValueError, match="expected a 32-byte palette PROM"): decode_palette_prom(bytes(size))