Files
Verbatim/tests/physics_interactions.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

149 lines
6.7 KiB
Rust

use verbatim::ai::GameSession;
use verbatim::ai::AiAction;
fn setup() -> GameSession {
let mut s = GameSession::new_seeded(42);
s.init_empty();
s.clear_area(90, 90, 50, 50);
s
}
#[test]
fn lava_flows_down_on_stone() {
let mut s = setup();
s.perform_action(&AiAction::FillRect { x: 100, y: 125, w: 10, h: 1, material: "stone".into() });
s.perform_action(&AiAction::SetCell { x: 105, y: 115, material: "lava".into() });
s.perform_action(&AiAction::SetCell { x: 105, y: 116, material: "lava".into() });
s.step(15);
let lava_at_floor = s.count_material_in_region(103, 122, 5, 4, "lava");
assert!(lava_at_floor > 0, "lava should flow down to stone floor");
}
#[test]
fn lava_cools_to_stone_eventually() {
let mut s = setup();
s.perform_action(&AiAction::FillRect { x: 100, y: 125, w: 10, h: 1, material: "stone".into() });
s.perform_action(&AiAction::SetCell { x: 105, y: 120, material: "lava".into() });
s.perform_action(&AiAction::SetCell { x: 105, y: 121, material: "lava".into() });
s.perform_action(&AiAction::SetCell { x: 105, y: 122, material: "lava".into() });
s.perform_action(&AiAction::SetCell { x: 105, y: 123, material: "lava".into() });
s.perform_action(&AiAction::SetCell { x: 105, y: 124, material: "lava".into() });
s.step(200);
let stone_count = s.count_material_in_region(103, 120, 5, 6, "stone");
assert!(stone_count >= 3, "lava should cool to stone eventually, got {} stone", stone_count);
}
#[test]
fn fire_spreads_through_wood_line() {
let mut s = setup();
s.perform_action(&AiAction::FillRect { x: 100, y: 120, w: 20, h: 1, material: "stone".into() });
for x in 100..110 {
s.perform_action(&AiAction::SetCell { x, y: 119, material: "wood".into() });
}
s.perform_action(&AiAction::SetCell { x: 100, y: 119, material: "fire".into() });
s.step(40);
let wood_left = s.count_material_in_region(100, 118, 10, 3, "wood");
assert_eq!(wood_left, 0, "fire should spread through entire wood line");
}
#[test]
fn acid_does_not_dissolve_empty() {
let mut s = setup();
s.perform_action(&AiAction::FillRect { x: 100, y: 115, w: 10, h: 1, material: "stone".into() });
s.perform_action(&AiAction::FillRect { x: 104, y: 114, w: 3, h: 1, material: "stone".into() });
s.perform_action(&AiAction::FillRect { x: 104, y: 113, w: 1, h: 1, material: "stone".into() });
s.perform_action(&AiAction::FillRect { x: 106, y: 113, w: 1, h: 1, material: "stone".into() });
s.perform_action(&AiAction::SetCell { x: 105, y: 113, material: "acid".into() });
s.step(5);
let cell = s.get_cell(105, 113);
assert!(cell.material == "acid" || cell.material == "empty",
"acid may flow out but should not dissolve empty, got {}", cell.material);
}
#[test]
fn acid_dissolves_grass() {
let mut s = setup();
s.perform_action(&AiAction::FillRect { x: 100, y: 120, w: 10, h: 1, material: "stone".into() });
s.perform_action(&AiAction::SetCell { x: 104, y: 119, material: "grass".into() });
s.perform_action(&AiAction::SetCell { x: 105, y: 119, material: "acid".into() });
s.perform_action(&AiAction::SetCell { x: 104, y: 118, material: "acid".into() });
s.step(20);
assert_ne!(s.get_cell(104, 119).material, "grass", "acid should dissolve grass");
}
#[test]
fn acid_dissolves_dirt() {
let mut s = setup();
s.perform_action(&AiAction::FillRect { x: 100, y: 115, w: 10, h: 1, material: "stone".into() });
s.perform_action(&AiAction::SetCell { x: 104, y: 114, material: "dirt".into() });
s.perform_action(&AiAction::SetCell { x: 105, y: 114, material: "acid".into() });
s.perform_action(&AiAction::SetCell { x: 104, y: 113, material: "acid".into() });
s.step(30);
assert_ne!(s.get_cell(104, 114).material, "dirt", "acid should dissolve dirt");
}
#[test]
fn water_extinguishes_fire_indirectly() {
let mut s = setup();
s.perform_action(&AiAction::FillRect { x: 100, y: 120, w: 10, h: 1, material: "stone".into() });
s.perform_action(&AiAction::SetCell { x: 105, y: 119, material: "fire".into() });
s.perform_action(&AiAction::SetCell { x: 105, y: 118, material: "water".into() });
s.step(20);
assert_ne!(s.get_cell(105, 119).material, "fire", "water should extinguish fire");
}
#[test]
fn lava_and_water_produce_both_steam_and_stone() {
let mut s = setup();
s.perform_action(&AiAction::FillRect { x: 100, y: 125, w: 20, h: 1, material: "stone".into() });
s.perform_action(&AiAction::FillRect { x: 100, y: 95, w: 20, h: 1, material: "stone".into() });
s.perform_action(&AiAction::FillRect { x: 101, y: 115, w: 4, h: 3, material: "lava".into() });
s.perform_action(&AiAction::FillRect { x: 106, y: 115, w: 4, h: 3, material: "water".into() });
s.step(30);
let steam = s.count_material_in_region(100, 100, 20, 20, "steam");
assert!(steam > 0, "lava + water should produce steam");
}
#[test]
fn sand_falls_through_water() {
let mut s = setup();
s.perform_action(&AiAction::FillRect { x: 100, y: 125, w: 10, h: 1, material: "stone".into() });
s.perform_action(&AiAction::FillRect { x: 104, y: 118, w: 3, h: 7, material: "water".into() });
s.perform_action(&AiAction::SetCell { x: 105, y: 113, material: "sand".into() });
s.step(30);
let sand_at_bottom = s.get_cell(105, 124).material;
assert_eq!(sand_at_bottom, "sand", "sand should sink through water to bottom");
}
#[test]
fn fire_does_not_ignite_stone() {
let mut s = setup();
s.perform_action(&AiAction::SetCell { x: 104, y: 110, material: "stone".into() });
s.perform_action(&AiAction::SetCell { x: 105, y: 110, material: "fire".into() });
s.step(30);
assert_eq!(s.get_cell(104, 110).material, "stone", "fire should not ignite stone");
}
#[test]
fn fire_does_not_ignite_water() {
let mut s = setup();
s.perform_action(&AiAction::FillRect { x: 100, y: 115, w: 10, h: 1, material: "stone".into() });
s.perform_action(&AiAction::SetCell { x: 104, y: 114, material: "water".into() });
s.perform_action(&AiAction::SetCell { x: 105, y: 114, material: "fire".into() });
s.step(5);
let cell = s.get_cell(104, 114);
assert_ne!(cell.material, "fire", "water should never become fire, got {}", cell.material);
assert_ne!(cell.material, "wood", "water should never become wood");
}
#[test]
fn water_does_not_flow_through_dirt_wall() {
let mut s = setup();
s.perform_action(&AiAction::FillRect { x: 100, y: 125, w: 20, h: 1, material: "stone".into() });
s.perform_action(&AiAction::FillRect { x: 109, y: 120, w: 1, h: 5, material: "dirt".into() });
s.perform_action(&AiAction::FillRect { x: 100, y: 120, w: 9, h: 5, material: "water".into() });
s.step(30);
let right_water = s.count_material_in_region(110, 118, 5, 8, "water");
assert_eq!(right_water, 0, "water should not flow through dirt wall");
}