All checks were successful
CI / Check / Test (push) Successful in 3m40s
Co-authored-by: Copilot <copilot@github.com>
63 lines
1.7 KiB
Rust
63 lines
1.7 KiB
Rust
#![allow(dead_code)]
|
|
|
|
use domain::{Color, Dimensions, DomainError, Point2D, ScreensaverScene, Sprite, Vector2D};
|
|
|
|
pub const LOGO: Dimensions = size(200, 100);
|
|
pub const ROOMY: Dimensions = size(800, 600);
|
|
pub const TINY: Dimensions = size(50, 50);
|
|
|
|
pub const SNUG: Dimensions = size(LOGO.width() + 2, LOGO.height() + 2);
|
|
pub const EDGE_ONLY: Dimensions = size(LOGO.width() + 2, ROOMY.height());
|
|
|
|
pub const SPEED: Vector2D = velocity(3.0, 2.0);
|
|
pub const RED: Color = Color {
|
|
r: 255,
|
|
g: 0,
|
|
b: 0,
|
|
a: 255,
|
|
};
|
|
|
|
pub const fn size(width: u32, height: u32) -> Dimensions {
|
|
match Dimensions::new(width, height) {
|
|
Some(size) => size,
|
|
None => panic!("test dimensions must be non-zero"),
|
|
}
|
|
}
|
|
|
|
const fn velocity(dx: f32, dy: f32) -> Vector2D {
|
|
match Vector2D::new(dx, dy) {
|
|
Some(velocity) => velocity,
|
|
None => panic!("test velocity must be finite"),
|
|
}
|
|
}
|
|
|
|
pub fn point(x: f32, y: f32) -> Point2D {
|
|
Point2D::new(x, y).expect("test point must be finite")
|
|
}
|
|
|
|
pub fn try_scene(logo: Dimensions, bounds: Dimensions) -> Result<ScreensaverScene, DomainError> {
|
|
ScreensaverScene::new(logo, SPEED, RED, bounds)
|
|
}
|
|
|
|
pub fn scene_in(bounds: Dimensions) -> ScreensaverScene {
|
|
try_scene(LOGO, bounds).expect("LOGO must fit the test bounds")
|
|
}
|
|
|
|
pub fn advance(scene: &mut ScreensaverScene, bounds: Dimensions, frames: u32) {
|
|
for _ in 0..frames {
|
|
scene.tick(bounds);
|
|
}
|
|
}
|
|
|
|
pub fn sprite_count(scene: &ScreensaverScene) -> usize {
|
|
scene.sprites().count()
|
|
}
|
|
|
|
pub fn logo_sprite(scene: &ScreensaverScene) -> Sprite {
|
|
scene.sprites().next().expect("the logo is always present")
|
|
}
|
|
|
|
pub fn bottom_right(bounds: Dimensions) -> Point2D {
|
|
point(bounds.width() as f32, bounds.height() as f32)
|
|
}
|