Add unit tests across all game modules (42 tests)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
24
src/enemy.rs
24
src/enemy.rs
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user