diff --git a/examples/bsp_interior.rs b/examples/bsp_interior.rs new file mode 100644 index 0000000..4fa4ece --- /dev/null +++ b/examples/bsp_interior.rs @@ -0,0 +1,10 @@ +use rand::prelude::*; +use mapgen::*; + + +fn main() { + let mut rng = StdRng::seed_from_u64(907647352); + let gen = BspInterior::new(); + let map = gen.modify_map(&mut rng, &Map::new(80, 50)); + println!("{:}", &map); +} \ No newline at end of file diff --git a/examples/bsp_rooms.rs b/examples/bsp_rooms.rs new file mode 100644 index 0000000..cf3ca9b --- /dev/null +++ b/examples/bsp_rooms.rs @@ -0,0 +1,12 @@ +use std::time::{SystemTime, UNIX_EPOCH}; +use rand::prelude::*; +use mapgen::*; + + +fn main() { + let system_time = SystemTime::now().duration_since(UNIX_EPOCH).expect("Can't access system time"); + let mut rng = StdRng::seed_from_u64(system_time.as_millis() as u64); + let gen = BspRooms::new(); + let map = gen.modify_map(&mut rng, &Map::new(80, 50)); + println!("{:}", &map); +} \ No newline at end of file diff --git a/src/filter/bsp_interior.rs b/src/filter/bsp_interior.rs index 8999b9a..aeb05fe 100644 --- a/src/filter/bsp_interior.rs +++ b/src/filter/bsp_interior.rs @@ -105,4 +105,30 @@ impl BspInterior { if half_height > self.min_room_size { self.add_subrects(v2, rng, rects); } } } +} + + +/// ------------------------------------------------------------------------------------------------ +/// Module unit tests +/// ------------------------------------------------------------------------------------------------ +#[cfg(test)] +mod tests { + use super::*; + use crate::{TileType, Map}; + + #[test] + fn no_corridors_on_borders() { + let mut rng = StdRng::seed_from_u64(907647352); + let gen = BspInterior::new(); + let map = gen.modify_map(&mut rng, &Map::new(80, 50)); + for i in 0..80 { + assert_eq!(map.at(i, 0), TileType::Wall); + assert_eq!(map.at(i, 49), TileType::Wall); + } + for j in 0..50 { + assert_eq!(map.at(0, j), TileType::Wall); + assert_eq!(map.at(79, j), TileType::Wall); + } + } + } \ No newline at end of file diff --git a/src/filter/bsp_rooms.rs b/src/filter/bsp_rooms.rs index 56fbff1..c459f4a 100644 --- a/src/filter/bsp_rooms.rs +++ b/src/filter/bsp_rooms.rs @@ -131,4 +131,29 @@ impl BspRooms { can_build } +} + +/// ------------------------------------------------------------------------------------------------ +/// Module unit tests +/// ------------------------------------------------------------------------------------------------ +#[cfg(test)] +mod tests { + use super::*; + use crate::map::Map; + + #[test] + fn no_corridors_on_borders() { + let mut rng = StdRng::seed_from_u64(907647352); + let gen = BspRooms::new(); + let map = gen.modify_map(&mut rng, &Map::new(80, 50)); + for i in 0..80 { + assert_eq!(map.at(i, 0), TileType::Wall); + assert_eq!(map.at(i, 49), TileType::Wall); + } + for j in 0..50 { + assert_eq!(map.at(0, j), TileType::Wall); + assert_eq!(map.at(79, j), TileType::Wall); + } + } + } \ No newline at end of file