use condor_grid::{Grid, Path, Point, SearchOutcome, SearchStats};
type GridOutcome = SearchOutcome<Path, SearchStats>;
pub fn expect_found_path<'a>(outcome: &'a GridOutcome, algorithm: &str, fixture: &str) -> &'a Path {
assert!(
outcome.is_found(),
"{algorithm} should find the {fixture} fixture"
);
outcome
.path()
.unwrap_or_else(|| panic!("{algorithm} should return a path for the {fixture} fixture"))
}
pub fn assert_exact_path_cost(
result: &GridOutcome,
expected_cost: usize,
algorithm: &str,
fixture: &str,
) {
assert_eq!(
result.cost(),
Some(expected_cost),
"{algorithm} should preserve exact cost for the {fixture} fixture"
);
}
pub fn assert_no_path(outcome: &GridOutcome, algorithm: &str, fixture: &str) {
assert!(
!outcome.is_found(),
"{algorithm} should report no path for the {fixture} fixture"
);
assert!(
outcome.path().is_none(),
"{algorithm} should not return a bogus path"
);
assert_eq!(
outcome.cost(),
None,
"{algorithm} should not report a path cost"
);
}
pub fn assert_path_valid(
grid: &Grid,
path: &[Point],
start: Point,
goal: Point,
algorithm: &str,
fixture: &str,
) {
assert_eq!(
path.first(),
Some(&start),
"{algorithm} path should start at request start"
);
assert_eq!(
path.last(),
Some(&goal),
"{algorithm} path should end at request goal"
);
for step in path {
assert!(
grid.contains(*step),
"{algorithm} returned an out-of-bounds step"
);
assert!(
grid.is_walkable(*step),
"{algorithm} returned a blocked step"
);
}
for pair in path.windows(2) {
let dx = pair[0].x.abs_diff(pair[1].x);
let dy = pair[0].y.abs_diff(pair[1].y);
assert_eq!(
dx + dy,
1,
"{algorithm} path for {fixture} must use cardinal moves"
);
}
}