88 lines
2.3 KiB
Rust
88 lines
2.3 KiB
Rust
use logic::battle::{get_lane_id, spawn_lane_of, LogicTilemap};
|
|
fn arena() -> LogicTilemap {
|
|
LogicTilemap::load(
|
|
std::path::Path::new("../../assets"),
|
|
"locations/goblin_arena.csv",
|
|
)
|
|
.expect("the goblin arena tilemap")
|
|
}
|
|
#[test]
|
|
fn arena_dimensions() {
|
|
let tm = arena();
|
|
assert_eq!((tm.width(), tm.height()), (36, 64));
|
|
}
|
|
#[test]
|
|
fn map_rows_full_width() {
|
|
let tm = arena();
|
|
assert_eq!(tm.tiles.len(), 64);
|
|
for (y, row) in tm.tiles.iter().enumerate() {
|
|
assert_eq!(row.len(), 36, "map row {y} is ragged");
|
|
}
|
|
}
|
|
#[test]
|
|
fn river_and_lanes() {
|
|
let tm = arena();
|
|
let tiles = || (0..tm.height()).flat_map(|y| (0..tm.width()).map(move |x| (x, y)));
|
|
assert_eq!(
|
|
tiles().filter(|(x, y)| tm.lane_bits(*x, *y) >= 1).count(),
|
|
692
|
|
);
|
|
assert_eq!(tiles().filter(|(x, y)| tm.is_water(*x, *y)).count(), 112);
|
|
}
|
|
#[test]
|
|
fn right_lane_pinch() {
|
|
let tm = arena();
|
|
for y in [31, 32] {
|
|
assert_eq!(
|
|
tm.lane_bits(27, y),
|
|
0,
|
|
"({},{y}) is off-lane at the pinch",
|
|
27
|
|
);
|
|
assert_eq!(
|
|
tm.lane_bits(30, y),
|
|
0,
|
|
"({},{y}) is off-lane at the pinch",
|
|
30
|
|
);
|
|
assert_eq!(tm.lane_bits(28, y), 2);
|
|
assert_eq!(tm.lane_bits(29, y), 2);
|
|
}
|
|
for y in [30, 33, 34, 40, 47] {
|
|
for x in 27..31 {
|
|
assert_eq!(tm.lane_bits(x, y), 2, "({x},{y}) is the right lane");
|
|
}
|
|
}
|
|
for y in 30..34 {
|
|
for x in 24..27 {
|
|
assert!(tm.is_water(x, y), "({x},{y}) should be river");
|
|
}
|
|
assert!(tm.is_water(31, y), "(31,{y}) should be river");
|
|
}
|
|
}
|
|
#[test]
|
|
fn right_bridge_right_lane() {
|
|
let tm = arena();
|
|
assert_eq!(get_lane_id(&tm, 12500, 14500), 2);
|
|
assert_eq!(get_lane_id(&tm, 10000, 14500), 2);
|
|
assert_eq!(get_lane_id(&tm, 11000, 14500), 2);
|
|
}
|
|
#[test]
|
|
fn left_bridge_left_lane() {
|
|
let tm = arena();
|
|
for (x, y) in [(6923, 8500), (7788, 8999), (7788, 8001)] {
|
|
assert_eq!(get_lane_id(&tm, x, y), 1, "({x},{y}) is on the left");
|
|
}
|
|
}
|
|
#[test]
|
|
fn spawn_clamps_before_lane() {
|
|
let tm = arena();
|
|
assert_eq!(
|
|
spawn_lane_of(&tm, -5000, 14500),
|
|
get_lane_id(&tm, 250, 14500)
|
|
);
|
|
assert_eq!(
|
|
spawn_lane_of(&tm, 999_999, 14500),
|
|
get_lane_id(&tm, 36 * 500 - 250, 14500)
|
|
);
|
|
}
|