"""Unit tests for the pure Galaxian LFSR starfield transform.""" import pytest from galemu.video import ( STARFIELD_STAR_COUNT, StarDescriptor, build_starfield, scroll_starfield, ) def test_starfield_source_is_complete_and_deterministic() -> None: first = build_starfield() second = build_starfield() assert first == second assert len(first) == STARFIELD_STAR_COUNT == 252 assert first[:4] == ( StarDescriptor(x=502, y=0, color=6), StarDescriptor(x=142, y=1, color=40), StarDescriptor(x=354, y=2, color=33), StarDescriptor(x=237, y=3, color=54), ) def test_starfield_scroll_wraps_and_applies_the_twinkle_gate() -> None: stars = ( StarDescriptor(x=0, y=1, color=1), StarDescriptor(x=511, y=0, color=2), ) visible = scroll_starfield(stars * 126, 1) assert visible[:2] == ( StarDescriptor(x=0, y=1, color=1), StarDescriptor(x=0, y=1, color=2), ) assert len(visible) == 252 @pytest.mark.parametrize("scroll_position", [-1, -512]) def test_starfield_rejects_negative_scroll_positions(scroll_position: int) -> None: with pytest.raises(ValueError, match="starfield scroll position must be non-negative"): scroll_starfield(build_starfield(), scroll_position) def test_starfield_rejects_invalid_source_descriptors() -> None: stars = (StarDescriptor(x=512, y=0, color=1),) * STARFIELD_STAR_COUNT with pytest.raises(ValueError, match="source stars must have valid"): scroll_starfield(stars, 0)