Files
horizon-airdef/crates/horizon-world/tests/placement_bounds.rs
T
Ludovic Marie cb19660fbe Build Horizon Rust parity foundations and differential validation
Add version-bound core, world data, geometry, generation and feature implementations with native client/server comparison tools and scoped evidence reports. Apply Horizon project branding.

Workspace tests, Clippy and 147 Python tests passed. Full 51-family survival and expanded provider comparisons are still running; complete gameplay parity and a playable Rust client remain unfinished. Private game artifacts and the isolated simple-block placement work are excluded.
2026-10-06 11:24:51 +02:00

59 lines
1.9 KiB
Rust

use horizon_core::random::LegacyRandom;
use horizon_world::{
heightmap::HeightmapType,
worldgen::{
anchor::WorldGenerationContext,
placement::{
LayerBlock, PlacementContext, PlacementError, PlacementModifier, PlacementQueryError,
},
value_provider::IntProvider,
},
};
#[test]
fn negative_cuboid_extent_skips_empty_loops_even_with_huge_other_extents() {
let modifier = PlacementModifier::Cuboid {
xz_size: IntProvider::Constant(i32::MAX),
y_size: IntProvider::Constant(-1),
include_edges: true,
include_interior: true,
};
let result = modifier.modify(
WorldGenerationContext::new(0, 16, 8),
&mut LegacyRandom::new(0),
[0, 0, 0],
|_, _| -> Result<(), ()> { panic!("empty cuboid emitted") },
);
assert!(result.is_ok());
}
struct UnboundedColumn {
reads: usize,
}
impl PlacementContext for UnboundedColumn {
fn generation(&self) -> WorldGenerationContext {
WorldGenerationContext::new(-64, 384, 63)
}
fn min_y(&mut self) -> Result<i32, PlacementQueryError> {
Ok(-64)
}
fn height(&mut self, _: HeightmapType, _: i32, _: i32) -> Result<i32, PlacementQueryError> {
Ok(i32::MAX)
}
fn layer_block(&mut self, _: [i32; 3]) -> Result<LayerBlock, PlacementQueryError> {
self.reads += 1;
Ok(LayerBlock::Empty)
}
}
#[test]
fn layered_scans_bound_work_when_world_queries_return_extreme_heights() {
let mut context = UnboundedColumn { reads: 0 };
let result = PlacementModifier::CountOnEveryLayer(IntProvider::Constant(1)).modify_in(
&mut context,
&mut LegacyRandom::new(0),
[0, 0, 0],
|_, _| -> Result<(), ()> { panic!("empty column emitted") },
);
assert!(matches!(result, Err(PlacementError::WorkLimit)));
assert!(context.reads > 0 && context.reads <= 65536);
}