Files
Verbatim/tests/physics_sand.rs
T
Emil 61b5d551ae test: 109 Rust tests + 14 JSON scenarios, polish physics
Tests added:
- physics_materials.rs: 15 tests (fire, smoke, steam, grass, dirt, bone, wood, stone, lava temp)
- physics_interactions.rs: 12 tests (lava+water, fire spread, acid interactions, sand+water)
- player_controls.rs: 12 tests (move L/R, jump, double jump, rapid input, wait, continuous)
- collision_robust.rs: 10 tests (walls, ceiling, sliding, corridor, slope, dirt wall, unstick)
- ragdoll_death.rs: 7 tests (death transition, ragdoll fall, progressive damage, corpse)
- determinism.rs: 8 tests (same seed, replay exact, replay partial, recording, 100-tick)
- edge_cases.rs: 19 tests (boundary, stress 20 goblins, fill/clear/paint, gravity, camera)
- 6 new JSON scenarios (fire chain, lava pool, sand bury, entity fall, steam, acid wall)

Fixes:
- AABB resolve_aabb_y: add vertical overlap check (was pushing player down when jumping)
- AABB resolve_aabb_x: velocity-aware resolution (player was stuck against walls)
- check_on_ground: use fractional position check (was always true)
- jump_force 1.5 (was 0.8) for 27-body entity
- Gravity read from self.verlet (was from clone, SetGravity didn't work)
- u8 overflow in lava color (saturating_add)

109 Rust tests, 14 JSON scenarios, 0 warnings, 0 failures
2026-06-20 22:42:29 +03:00

52 lines
2.1 KiB
Rust

use verbatim::ai::GameSession;
use verbatim::ai::AiAction;
fn setup_empty() -> GameSession {
let mut s = GameSession::new_seeded(42);
s.init_empty();
s.clear_area(95, 95, 30, 40);
s
}
#[test]
fn sand_falls_down() {
let mut s = setup_empty();
s.perform_action(&AiAction::FillRect { x: 100, y: 115, w: 10, h: 1, material: "stone".into() });
s.perform_action(&AiAction::SetCell { x: 105, y: 105, material: "sand".into() });
s.step(10);
assert_eq!(s.get_cell(105, 105).material, "empty", "sand should have fallen from y=105");
assert_eq!(s.get_cell(105, 114).material, "sand", "sand should be resting on stone at y=114");
}
#[test]
fn sand_displaces_water() {
let mut s = setup_empty();
s.perform_action(&AiAction::FillRect { x: 100, y: 115, w: 10, h: 1, material: "stone".into() });
s.perform_action(&AiAction::FillRect { x: 100, y: 110, w: 10, h: 5, material: "water".into() });
s.perform_action(&AiAction::SetCell { x: 105, y: 105, material: "sand".into() });
s.step(20);
let sand_at_bottom = s.get_cell(105, 114).material == "sand";
assert!(sand_at_bottom, "sand should sink to bottom through water");
}
#[test]
fn sand_piles_on_stone() {
let mut s = setup_empty();
s.perform_action(&AiAction::FillRect { x: 100, y: 115, w: 10, h: 1, material: "stone".into() });
s.perform_action(&AiAction::SetCell { x: 105, y: 105, material: "sand".into() });
s.perform_action(&AiAction::SetCell { x: 105, y: 104, material: "sand".into() });
s.step(15);
let count = s.count_material_in_region(104, 112, 3, 4, "sand");
assert!(count >= 2, "both sand cells should have piled up, got {} sand cells", count);
}
#[test]
fn sand_does_not_fall_through_stone() {
let mut s = setup_empty();
s.perform_action(&AiAction::FillRect { x: 100, y: 110, w: 10, h: 1, material: "stone".into() });
s.perform_action(&AiAction::SetCell { x: 105, y: 105, material: "sand".into() });
s.step(10);
assert_eq!(s.get_cell(105, 109).material, "sand", "sand should rest on top of stone");
assert_eq!(s.get_cell(105, 110).material, "stone", "stone should remain");
}