Add unit tests across all game modules (42 tests)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-06 23:11:03 +01:00
parent 090f5d4a6d
commit 401f91b0fe
6 changed files with 511 additions and 9 deletions

View File

@@ -32,3 +32,27 @@ impl Enemy {
self.x + self.width
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn scroll_moves_enemy_left() {
let mut e = Enemy::new(200.0, 400.0, 40.0, 40.0);
e.scroll(200.0, 0.5);
assert!((e.x - 100.0).abs() < 1e-4);
}
#[test]
fn off_screen_when_right_edge_is_negative() {
let e = Enemy::new(-50.0, 400.0, 40.0, 40.0);
assert!(e.is_off_screen());
}
#[test]
fn not_off_screen_when_partially_visible() {
let e = Enemy::new(-20.0, 400.0, 40.0, 40.0);
assert!(!e.is_off_screen());
}
}