Skip to content

Commit

Permalink
Add unit test for slow pathfinding vs get_aggressive_path
Browse files Browse the repository at this point in the history
  • Loading branch information
JesseEmond committed Oct 5, 2024
1 parent 7a8a104 commit ac697c5
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion bot/src/pathfinding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,43 @@ pub fn get_aggressive_path(grid: &Grid, from: &Pos, to: &Pos) -> Vec<Pos> {
}
}
path.reverse();
assert_eq!(path, pathfinder_state.get_path(grid, to));
path
}

// TODO: Unit test that slow pathfinder & fast pathfinders return the same nodes
#[cfg(test)]
mod tests {
use super::*;
use super::super::grid::make_grid;

#[test]
fn test_slow_pathfinder_same_path_as_get_aggressive_path() {
let grid = make_grid(vec![
"######################",
"# #",
"# ######## ######## #",
"# # # #",
"# #### ### # #### # #",
"# #### # #### # #",
"# #### ### # #### # #",
"# # # #",
"# #### ### # # #### #",
"# # # # # # # #",
"# # ### # # # #",
"# # # #",
"# ######## ######## #",
"# #",
"######################",
]);
let from = Pos { x: 5, y: 1 };
let to = Pos { x: 18, y: 13 };

let mut pathfinder = SlowAggressivePathfinder::new(&grid);
let path = pathfinder.pathfind(&grid, &from, &Some(to))
.get_path(&grid, &to);
assert_eq!(path, get_aggressive_path(&grid, &from, &to));
}

// TODO: unit test that slow pathfinder's final path == fast one
// TODO: unit test that fast pathfinder per-step has same outputs as slow
}

0 comments on commit ac697c5

Please sign in to comment.