test(maze): 88% coverage

This commit is contained in:
2024-12-25 21:24:55 +02:00
parent 012d1e5cca
commit 43a669dee8
3 changed files with 175 additions and 179 deletions

View File

@@ -93,15 +93,6 @@ fn maze_connectivity() {
}
}
#[test]
fn generator_type() {
let maze = assert_ok!(MazeBuilder::new()
.with_radius(3)
.with_generator(GeneratorType::RecursiveBacktracking)
.build());
claims::assert_gt!(maze.len(), 0);
}
#[test]
fn maze_boundaries() {
let radius = 3;

68
tests/maze.rs Normal file
View File

@@ -0,0 +1,68 @@
use hexlab::prelude::*;
#[test]
fn hex_maze_creation_and_basic_operations() {
let mut maze = HexMaze::new();
assert!(maze.is_empty());
let center = Hex::ZERO;
maze.add_tile(center);
assert_eq!(maze.len(), 1);
assert!(!maze.is_empty());
let tile = maze.get_tile(&center);
assert!(tile.is_some());
assert_eq!(tile.unwrap().pos(), center);
}
#[test]
fn hex_maze_wall_operations() {
let mut maze = HexMaze::new();
let center = Hex::ZERO;
maze.add_tile(center);
// Add walls
for direction in EdgeDirection::ALL_DIRECTIONS {
maze.add_wall(center, direction);
}
let walls = maze.get_walls(&center).unwrap();
assert_eq!(walls.count(), 6);
// Remove walls
for direction in EdgeDirection::ALL_DIRECTIONS {
maze.remove_tile_wall(&center, direction);
}
let walls = maze.get_walls(&center).unwrap();
assert_eq!(walls.count(), 0);
}
#[test]
fn hex_maze_multiple_tiles() {
let mut maze = HexMaze::new();
let tiles = [Hex::ZERO, Hex::new(1, -1), Hex::new(0, 1), Hex::new(-1, 1)];
for &tile in &tiles {
maze.add_tile(tile);
}
assert_eq!(maze.len(), tiles.len());
for &tile in &tiles {
assert!(maze.get_tile(&tile).is_some());
}
}
#[test]
fn hex_maze_edge_cases() {
let mut maze = HexMaze::new();
let non_existent = Hex::new(10, 10);
// Operations on non-existent tiles should not panic
maze.add_wall(non_existent, EdgeDirection::FLAT_NORTH);
maze.remove_tile_wall(&non_existent, EdgeDirection::FLAT_NORTH);
assert!(maze.get_tile(&non_existent).is_none());
assert!(maze.get_walls(&non_existent).is_none());
}