Files
Tirsvad aa77784075 Add collision detection, finish line and level up
Task: MIL-005#1
Task: MIL-005#2
Task: MIL-005#3
Task: MIL-005#4
2026-10-13 13:59:35 +08:00

32 lines
873 B
Python

"""Tests for the pure collision rule."""
from collision import is_colliding
from constants import CAR_HEIGHT, CAR_LENGTH, PLAYER_HALF_SIZE
REACH_X = CAR_LENGTH / 2 + PLAYER_HALF_SIZE
REACH_Y = CAR_HEIGHT / 2 + PLAYER_HALF_SIZE
def test_hit_when_player_overlaps_car() -> None:
assert is_colliding(5, 3, 0, 0)
def test_no_hit_when_beyond_car_half_length_horizontally() -> None:
assert not is_colliding(REACH_X + 1, 0, 0, 0)
def test_no_hit_when_a_lane_away_vertically() -> None:
assert not is_colliding(0, CAR_HEIGHT * 2, 0, 0)
def test_no_hit_when_exactly_at_horizontal_boundary() -> None:
assert not is_colliding(REACH_X, 0, 0, 0)
def test_no_hit_when_exactly_at_vertical_boundary() -> None:
assert not is_colliding(0, REACH_Y, 0, 0)
def test_hit_just_inside_the_boundary() -> None:
assert is_colliding(REACH_X - 1, REACH_Y - 1, 0, 0)