Files
games/crates/apps/game-snake-poc-wasm/unit_tests/runtime.rs
2026-09-20 13:58:13 +02:00

53 lines
2.0 KiB
Rust

// file: crates/apps/game-snake-poc-wasm/unit_tests/runtime.rs
// version: 2
#[test]
fn direction_is_queued_without_advancing_simulation() {
let mut game = crate::SnakeWasmGame::new();
let before_x = game.rectangle_x(1);
let before_y = game.rectangle_y(1);
game.up();
assert_eq!(game.rectangle_x(1), before_x);
assert_eq!(game.rectangle_y(1), before_y);
game.tick();
assert_eq!(game.rectangle_x(1), before_x);
assert!(game.rectangle_y(1) < before_y);
}
#[test]
fn scene_and_status_are_exposed_for_canvas_host() {
let game = crate::SnakeWasmGame::new();
assert_eq!(game.score(), 0);
assert_eq!(game.length(), 3);
assert_eq!(game.rectangle_count(), 4);
assert!(game.rectangle_width(0) > 0.0);
assert!(game.rectangle_height(0) > 0.0);
assert_eq!(game.rectangle_x(99), -1.0);
assert_eq!(game.rectangle_y(99), -1.0);
}
#[test]
fn browser_runtime_provenance_preserves_static_and_observed_dimensions() {
let mut game = crate::SnakeWasmGame::new();
assert_eq!(game.provenance_platform_family(), "web");
assert_eq!(game.provenance_execution_model(), "wasm");
assert_eq!(game.provenance_runtime_host(), "browser");
assert_eq!(game.provenance_device_class(), "unknown");
assert_eq!(game.provenance_input_profile(), "unknown");
assert!(game.configure_runtime_provenance("phone", "touch"));
assert_eq!(game.provenance_device_class(), "phone");
assert_eq!(game.provenance_input_profile(), "touch");
assert_eq!(game.provenance_platform_family(), "web");
assert_eq!(game.provenance_execution_model(), "wasm");
assert_eq!(game.provenance_runtime_host(), "browser");
}
#[test]
fn invalid_runtime_provenance_labels_are_rejected_without_mutation() {
let mut game = crate::SnakeWasmGame::new();
assert!(game.configure_runtime_provenance("desktop", "keyboard-mouse"));
assert!(!game.configure_runtime_provenance("console", "telepathy"));
assert_eq!(game.provenance_device_class(), "desktop");
assert_eq!(game.provenance_input_profile(), "keyboard-mouse");
}