fix(walls): pass tests

This commit is contained in:
Kristofers Solo 2024-12-28 18:04:17 +02:00
parent 2b3a375c4f
commit d66e4c4bb2
8 changed files with 31 additions and 31 deletions

2
Cargo.lock generated
View File

@ -2375,7 +2375,7 @@ checksum = "dfa686283ad6dd069f105e5ab091b04c62850d3e4cf5d67debad1933f55023df"
[[package]] [[package]]
name = "hexlab" name = "hexlab"
version = "0.5.1" version = "0.5.2"
dependencies = [ dependencies = [
"bevy", "bevy",
"bevy_reflect", "bevy_reflect",

View File

@ -1,7 +1,7 @@
[package] [package]
name = "hexlab" name = "hexlab"
authors = ["Kristofers Solo <dev@kristofers.xyz>"] authors = ["Kristofers Solo <dev@kristofers.xyz>"]
version = "0.5.1" version = "0.5.2"
edition = "2021" edition = "2021"
description = "A hexagonal maze generation and manipulation library" description = "A hexagonal maze generation and manipulation library"
repository = "https://github.com/kristoferssolo/hexlab" repository = "https://github.com/kristoferssolo/hexlab"

View File

@ -100,7 +100,7 @@ mod test {
for dir in EdgeDirection::ALL_DIRECTIONS { for dir in EdgeDirection::ALL_DIRECTIONS {
let neighbor = current + dir; let neighbor = current + dir;
if let Some(walls) = maze.get_walls(&current) { if let Some(walls) = maze.get_walls(&current) {
if !walls.contains(&dir) && maze.get(&neighbor).is_some() { if !walls.contains(dir) && maze.get(&neighbor).is_some() {
to_visit.push(neighbor); to_visit.push(neighbor);
} }
} }

View File

@ -45,8 +45,8 @@
//! //!
//! let mut walls = Walls::empty(); //! let mut walls = Walls::empty();
//! assert!(!walls.insert(EdgeDirection::FLAT_NORTH)); //! assert!(!walls.insert(EdgeDirection::FLAT_NORTH));
//! assert!(walls.contains(&EdgeDirection::FLAT_NORTH)); //! assert!(walls.contains(EdgeDirection::FLAT_NORTH));
//! assert!(!walls.contains(&EdgeDirection::FLAT_SOUTH)); //! assert!(!walls.contains(EdgeDirection::FLAT_SOUTH));
//!``` //!```
mod builder; mod builder;
pub mod errors; pub mod errors;

View File

@ -149,7 +149,7 @@ impl Maze {
/// ///
/// maze.add_tile_wall(&coord, EdgeDirection::FLAT_NORTH); /// maze.add_tile_wall(&coord, EdgeDirection::FLAT_NORTH);
/// let walls = maze.get_walls(&coord).unwrap(); /// let walls = maze.get_walls(&coord).unwrap();
/// assert!(walls.contains(&EdgeDirection::FLAT_NORTH)); /// assert!(walls.contains(EdgeDirection::FLAT_NORTH));
/// ``` /// ```
#[inline] #[inline]
#[must_use] #[must_use]
@ -252,7 +252,7 @@ impl Maze {
/// ///
/// // Check that the wall was added /// // Check that the wall was added
/// let walls = maze.get_walls(&Hex::ZERO).unwrap(); /// let walls = maze.get_walls(&Hex::ZERO).unwrap();
/// assert!(walls.contains(&EdgeDirection::FLAT_NORTH)); /// assert!(walls.contains(EdgeDirection::FLAT_NORTH));
/// assert_eq!(walls.count(), 1); /// assert_eq!(walls.count(), 1);
/// ///
/// // Adding the same wall again should return true (no change) /// // Adding the same wall again should return true (no change)
@ -300,7 +300,7 @@ impl Maze {
/// maze.remove_tile_wall(&coord, EdgeDirection::FLAT_NORTH); /// maze.remove_tile_wall(&coord, EdgeDirection::FLAT_NORTH);
/// ///
/// let walls = maze.get_walls(&coord).unwrap(); /// let walls = maze.get_walls(&coord).unwrap();
/// assert!(!walls.contains(&EdgeDirection::FLAT_NORTH)); /// assert!(!walls.contains(EdgeDirection::FLAT_NORTH));
/// ``` /// ```
pub fn remove_tile_wall( pub fn remove_tile_wall(
&mut self, &mut self,

View File

@ -115,7 +115,7 @@ impl Walls {
#[inline] #[inline]
pub fn insert<T>(&mut self, direction: T) -> bool pub fn insert<T>(&mut self, direction: T) -> bool
where where
T: Into<Self> + Copy, T: Into<Self>,
{ {
let mask = direction.into().0; let mask = direction.into().0;
let was_present = self.0 & mask != 0; let was_present = self.0 & mask != 0;
@ -152,7 +152,7 @@ impl Walls {
#[inline] #[inline]
pub fn remove<T>(&mut self, direction: T) -> bool pub fn remove<T>(&mut self, direction: T) -> bool
where where
T: Into<Self> + Copy, T: Into<Self>,
{ {
let mask = direction.into().0; let mask = direction.into().0;
let was_present = self.0 & mask != 0; let was_present = self.0 & mask != 0;
@ -174,13 +174,13 @@ impl Walls {
/// let mut walls = Walls::empty(); /// let mut walls = Walls::empty();
/// walls.insert(EdgeDirection::FLAT_NORTH); /// walls.insert(EdgeDirection::FLAT_NORTH);
/// ///
/// assert!(walls.contains(&EdgeDirection::FLAT_NORTH)); /// assert!(walls.contains(EdgeDirection::FLAT_NORTH));
/// assert!(!walls.contains(&EdgeDirection::FLAT_SOUTH)); /// assert!(!walls.contains(EdgeDirection::FLAT_SOUTH));
/// ``` /// ```
#[inline] #[inline]
pub fn contains<T>(&self, direction: T) -> bool pub fn contains<T>(&self, direction: T) -> bool
where where
T: Into<Self> + Copy, T: Into<Self>,
{ {
self.0 & direction.into().0 != 0 self.0 & direction.into().0 != 0
} }
@ -319,7 +319,7 @@ impl Walls {
/// let mut walls = Walls::empty(); /// let mut walls = Walls::empty();
/// walls.fill([EdgeDirection::FLAT_NORTH ,EdgeDirection::FLAT_SOUTH, EdgeDirection::FLAT_SOUTH_EAST]); /// walls.fill([EdgeDirection::FLAT_NORTH ,EdgeDirection::FLAT_SOUTH, EdgeDirection::FLAT_SOUTH_EAST]);
/// ///
/// assert!(walls.contains(&EdgeDirection::FLAT_SOUTH)); /// assert!(walls.contains(EdgeDirection::FLAT_SOUTH));
/// assert_eq!(walls.count(), 3); /// assert_eq!(walls.count(), 3);
/// ``` /// ```
#[inline] #[inline]
@ -427,7 +427,7 @@ mod test {
fn insert_single_wall() { fn insert_single_wall() {
let mut walls = Walls::empty(); let mut walls = Walls::empty();
walls.insert(EdgeDirection::FLAT_NORTH); walls.insert(EdgeDirection::FLAT_NORTH);
assert!(walls.contains(&EdgeDirection::FLAT_NORTH)); assert!(walls.contains(EdgeDirection::FLAT_NORTH));
assert_eq!(walls.count(), 1); assert_eq!(walls.count(), 1);
} }
@ -436,7 +436,7 @@ mod test {
fn remove_existing_wall() { fn remove_existing_wall() {
let mut walls = Walls::new(); let mut walls = Walls::new();
assert!(walls.remove(EdgeDirection::FLAT_NORTH)); assert!(walls.remove(EdgeDirection::FLAT_NORTH));
assert!(!walls.contains(&EdgeDirection::FLAT_NORTH)); assert!(!walls.contains(EdgeDirection::FLAT_NORTH));
} }
#[test] #[test]
@ -452,14 +452,14 @@ mod test {
fn toggle_wall() { fn toggle_wall() {
let mut walls = Walls::empty(); let mut walls = Walls::empty();
assert!(!walls.toggle(EdgeDirection::FLAT_NORTH)); assert!(!walls.toggle(EdgeDirection::FLAT_NORTH));
assert!(walls.contains(&EdgeDirection::FLAT_NORTH)); assert!(walls.contains(EdgeDirection::FLAT_NORTH));
} }
#[test] #[test]
fn toggle_removes_wall() { fn toggle_removes_wall() {
let mut walls = Walls::new(); let mut walls = Walls::new();
assert!(walls.toggle(EdgeDirection::FLAT_NORTH)); assert!(walls.toggle(EdgeDirection::FLAT_NORTH));
assert!(!walls.contains(&EdgeDirection::FLAT_NORTH)); assert!(!walls.contains(EdgeDirection::FLAT_NORTH));
} }
// fill // fill
@ -467,8 +467,8 @@ mod test {
fn fill_adds_multiple_walls() { fn fill_adds_multiple_walls() {
let mut walls = Walls::empty(); let mut walls = Walls::empty();
walls.fill([EdgeDirection::FLAT_NORTH, EdgeDirection::FLAT_SOUTH]); walls.fill([EdgeDirection::FLAT_NORTH, EdgeDirection::FLAT_SOUTH]);
assert!(walls.contains(&EdgeDirection::FLAT_NORTH)); assert!(walls.contains(EdgeDirection::FLAT_NORTH));
assert!(walls.contains(&EdgeDirection::FLAT_SOUTH)); assert!(walls.contains(EdgeDirection::FLAT_SOUTH));
assert_eq!(walls.count(), 2); assert_eq!(walls.count(), 2);
} }
@ -477,31 +477,31 @@ mod test {
let mut walls = Walls::empty(); let mut walls = Walls::empty();
walls.insert(EdgeDirection::FLAT_NORTH); walls.insert(EdgeDirection::FLAT_NORTH);
walls.fill([EdgeDirection::FLAT_SOUTH, EdgeDirection::FLAT_SOUTH_EAST]); walls.fill([EdgeDirection::FLAT_SOUTH, EdgeDirection::FLAT_SOUTH_EAST]);
assert!(walls.contains(&EdgeDirection::FLAT_NORTH)); assert!(walls.contains(EdgeDirection::FLAT_NORTH));
assert!(walls.contains(&EdgeDirection::FLAT_SOUTH)); assert!(walls.contains(EdgeDirection::FLAT_SOUTH));
assert!(walls.contains(&EdgeDirection::FLAT_SOUTH_EAST)); assert!(walls.contains(EdgeDirection::FLAT_SOUTH_EAST));
assert_eq!(walls.count(), 3); assert_eq!(walls.count(), 3);
} }
#[test] #[test]
fn from_edge_direction_conversion() { fn from_edge_direction_conversion() {
let walls: Walls = EdgeDirection::FLAT_NORTH.into(); let walls: Walls = EdgeDirection::FLAT_NORTH.into();
assert!(walls.contains(&EdgeDirection::FLAT_NORTH)); assert!(walls.contains(EdgeDirection::FLAT_NORTH));
assert_eq!(walls.count(), 1); assert_eq!(walls.count(), 1);
} }
#[test] #[test]
fn from_u8_conversion() { fn from_u8_conversion() {
let walls: Walls = 0u8.into(); let walls: Walls = 0u8.into();
assert!(walls.contains(&EdgeDirection::FLAT_SOUTH_EAST)); assert!(walls.contains(EdgeDirection::FLAT_SOUTH_EAST));
assert_eq!(walls.count(), 1); assert_eq!(walls.count(), 1);
} }
#[test] #[test]
fn from_array_conversion() { fn from_array_conversion() {
let walls: Walls = [EdgeDirection::FLAT_NORTH, EdgeDirection::FLAT_SOUTH].into(); let walls: Walls = [EdgeDirection::FLAT_NORTH, EdgeDirection::FLAT_SOUTH].into();
assert!(walls.contains(&EdgeDirection::FLAT_NORTH)); assert!(walls.contains(EdgeDirection::FLAT_NORTH));
assert!(walls.contains(&EdgeDirection::FLAT_SOUTH)); assert!(walls.contains(EdgeDirection::FLAT_SOUTH));
assert_eq!(walls.count(), 2); assert_eq!(walls.count(), 2);
} }
@ -532,8 +532,8 @@ mod test {
]; ];
let walls: Walls = directions.into_iter().collect(); let walls: Walls = directions.into_iter().collect();
assert_eq!(walls.count(), 2); assert_eq!(walls.count(), 2);
assert!(walls.contains(&EdgeDirection::FLAT_NORTH)); assert!(walls.contains(EdgeDirection::FLAT_NORTH));
assert!(walls.contains(&EdgeDirection::FLAT_SOUTH)); assert!(walls.contains(EdgeDirection::FLAT_SOUTH));
} }
#[test] #[test]

View File

@ -73,7 +73,7 @@ fn maze_connectivity() {
.filter(|&&dir| { .filter(|&&dir| {
let neighbor = pos + dir; let neighbor = pos + dir;
if let Some(walls) = maze.get_walls(&pos) { if let Some(walls) = maze.get_walls(&pos) {
!walls.contains(&dir) && maze.get(&neighbor).is_some() !walls.contains(dir) && maze.get(&neighbor).is_some()
} else { } else {
false false
} }

View File

@ -36,7 +36,7 @@ fn generator_type(
for dir in EdgeDirection::ALL_DIRECTIONS { for dir in EdgeDirection::ALL_DIRECTIONS {
let neighbor = current + dir; let neighbor = current + dir;
if let Some(walls) = maze.get_walls(&current) { if let Some(walls) = maze.get_walls(&current) {
if !walls.contains(&dir) && maze.get(&neighbor).is_some() { if !walls.contains(dir) && maze.get(&neighbor).is_some() {
to_visit.push(neighbor); to_visit.push(neighbor);
} }
} }