Run FOV tests with both algorithms
@@ -52,7 +52,7 @@ impl FieldOfViewAlg {
#[cfg(test)]
mod tests {
- use crate::prelude::*;
+ use crate::prelude::FieldOfViewAlg;
use bracket_algorithm_traits::prelude::{Algorithm2D, BaseMap};
use bracket_geometry::prelude::{BresenhamCircle, Point};
use std::cmp::max;
@@ -62,6 +62,10 @@ mod tests {
const TESTMAP_W: usize = 20;
const TESTMAP_H: usize = 20;
const TESTMAP_TILES: usize = (TESTMAP_W * TESTMAP_H) as usize;
+ const ALGORITHS: [FieldOfViewAlg; 2] = [
+ FieldOfViewAlg::RecursiveShadowcasting,
+ FieldOfViewAlg::SymmetricShadowcasting,
+ ];
struct Map {
pub tiles: Vec<bool>,
@@ -102,17 +106,20 @@ mod tests {
fn fov_dupes() {
let map = Map::new();
- let visible = field_of_view(Point::new(10, 10), 8, &map);
+ for alg in ALGORITHS {
+ let visible = alg.field_of_view(Point::new(10, 10), 8, &map);
assert!(has_unique_elements(&visible));
}
+ }
// Tests that the bounds-checking trait is applying properly to field-of-view checks
#[test]
fn fov_bounds_check() {
let map = Map::new();
- let visible = field_of_view(Point::new(2, 2), 8, &map);
+ for alg in ALGORITHS {
+ let visible = alg.field_of_view(Point::new(2, 2), 8, &map);
for t in visible.iter() {
assert!(t.x >= 0);
@@ -121,6 +128,7 @@ mod tests {
assert!(t.y < TESTMAP_H as i32 - 1);
}
}
+ }
// Tests that the FOV scan does not miss any interior points
#[test]
@@ -129,7 +137,8 @@ mod tests {
let map = Map::new();
let dimensions = map.dimensions();
let c = Point::new(10, 10);
- let visible = field_of_view(c, radius, &map);
+ for alg in ALGORITHS {
+ let visible = alg.field_of_view(c, radius, &map);
// let max_radius_sq: i32 = visible.iter().fold(0, |max_r2, p| {
let max_radius_sq: i32 = BresenhamCircle::new(c, radius).fold(0, |max_r2, p| {
let r2 = (p.x - c.x) * (p.x - c.x) + (p.y - c.y) * (p.y - c.y);
@@ -162,6 +171,7 @@ mod tests {
}
}
}
+ }
#[test]
fn fov_corridor() {
@@ -176,7 +186,8 @@ mod tests {
map.tiles[idx] = true;
}
- let visible = field_of_view(c, radius, &map);
+ for alg in ALGORITHS {
+ let visible = alg.field_of_view(c, radius, &map);
for i in 1..radius * 2 - 2 {
let pos = Point::new(c.x - radius + i, c.y);
assert!(visible.contains(&pos));
@@ -187,3 +198,4 @@ mod tests {
}
}
}
+}
