mirror of
https://github.com/kristoferssolo/hexlab.git
synced 2026-03-22 00:26:26 +00:00
test(walls): 93% coverage
This commit is contained in:
@@ -1,15 +1,13 @@
|
||||
mod backtrack;
|
||||
use crate::HexMaze;
|
||||
use backtrack::generate_backtracking;
|
||||
#[cfg(feature = "bevy_reflect")]
|
||||
use bevy::prelude::*;
|
||||
use hexx::Hex;
|
||||
|
||||
#[allow(clippy::module_name_repetitions)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
#[cfg_attr(feature = "bevy_reflect", derive(Reflect))]
|
||||
#[cfg_attr(feature = "bevy", derive(Component))]
|
||||
#[cfg_attr(feature = "bevy", reflect(Component))]
|
||||
#[cfg_attr(feature = "bevy_reflect", derive(bevy_reflect::Reflect))]
|
||||
#[cfg_attr(feature = "bevy", derive(bevy::Component))]
|
||||
#[cfg_attr(feature = "bevy", reflect(bevy::Component))]
|
||||
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
|
||||
pub enum GeneratorType {
|
||||
#[default]
|
||||
|
||||
19
src/maze.rs
19
src/maze.rs
@@ -1,8 +1,6 @@
|
||||
use super::{HexTile, Walls};
|
||||
#[cfg(feature = "bevy_reflect")]
|
||||
use bevy::prelude::*;
|
||||
#[cfg(feature = "bevy_reflect")]
|
||||
use bevy::utils::HashMap;
|
||||
use bevy_utils::HashMap;
|
||||
use hexx::{EdgeDirection, Hex};
|
||||
#[cfg(not(feature = "bevy_reflect"))]
|
||||
use std::collections::HashMap;
|
||||
@@ -14,9 +12,9 @@ use std::ops::{Deref, DerefMut};
|
||||
/// of tiles and their associated walls.
|
||||
#[allow(clippy::module_name_repetitions)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
#[cfg_attr(feature = "bevy_reflect", derive(Reflect))]
|
||||
#[cfg_attr(feature = "bevy", derive(Component))]
|
||||
#[cfg_attr(feature = "bevy", reflect(Component))]
|
||||
#[cfg_attr(feature = "bevy_reflect", derive(bevy_reflect::Reflect))]
|
||||
#[cfg_attr(feature = "bevy", derive(bevy::Component))]
|
||||
#[cfg_attr(feature = "bevy", reflect(bevy::Component))]
|
||||
#[derive(Debug, Clone, Default, PartialEq, Eq)]
|
||||
pub struct HexMaze(HashMap<Hex, HexTile>);
|
||||
|
||||
@@ -56,7 +54,6 @@ impl HexMaze {
|
||||
///
|
||||
/// assert_eq!(maze.len(), 1);
|
||||
/// assert!(!maze.is_empty());
|
||||
/// assert!(!maze.get_tile(&coord).is_some());
|
||||
/// ```
|
||||
pub fn add_tile(&mut self, coords: Hex) {
|
||||
let tile = HexTile::new(coords);
|
||||
@@ -80,8 +77,9 @@ impl HexMaze {
|
||||
/// maze.add_tile(coord);
|
||||
///
|
||||
/// maze.add_wall(coord, EdgeDirection::FLAT_NORTH);
|
||||
/// let walls = maze.get_walls(&coord).unwrap();
|
||||
/// assert!(walls.contains(EdgeDirection::FLAT_NORTH));
|
||||
/// let walls = maze.get_walls(&coord);
|
||||
/// assert!(walls.is_some());
|
||||
/// assert!(walls.unwrap().contains(EdgeDirection::FLAT_NORTH));
|
||||
/// ```
|
||||
pub fn add_wall(&mut self, coord: Hex, direction: EdgeDirection) {
|
||||
if let Some(tile) = self.0.get_mut(&coord) {
|
||||
@@ -104,7 +102,8 @@ impl HexMaze {
|
||||
/// let coord = Hex::ZERO;
|
||||
/// maze.add_tile(coord);
|
||||
///
|
||||
/// assert!(!maze.get_tile(&coord).is_some());
|
||||
/// assert!(maze.get_tile(&coord).is_some());
|
||||
/// assert!(maze.get_tile(&Hex::new(1, 1)).is_none());
|
||||
/// ```
|
||||
#[cfg_attr(not(debug_assertions), inline)]
|
||||
#[must_use]
|
||||
|
||||
212
src/tile.rs
212
src/tile.rs
@@ -1,6 +1,4 @@
|
||||
use super::Walls;
|
||||
#[cfg(feature = "bevy_reflect")]
|
||||
use bevy::prelude::*;
|
||||
use hexx::Hex;
|
||||
#[cfg(feature = "bevy_reflect")]
|
||||
use hexx::HexLayout;
|
||||
@@ -11,7 +9,7 @@ use std::fmt::Display;
|
||||
/// Each tile has a position and a set of walls defining its boundaries.
|
||||
#[allow(clippy::module_name_repetitions)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
#[cfg_attr(feature = "bevy_reflect", derive(Reflect))]
|
||||
#[cfg_attr(feature = "bevy_reflect", derive(bevy_reflect::Reflect))]
|
||||
#[cfg_attr(feature = "bevy", derive(Component))]
|
||||
#[cfg_attr(feature = "bevy", reflect(Component))]
|
||||
#[derive(Debug, Clone, Default, PartialEq, Eq)]
|
||||
@@ -26,6 +24,16 @@ impl HexTile {
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `pos` - The hexagonal coordinates of the tile.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use hexlab::prelude::*;
|
||||
///
|
||||
/// let tile = HexTile::new(Hex::new(1, -1));
|
||||
/// assert_eq!(tile.pos(), Hex::new(1, -1));
|
||||
/// assert_eq!(*tile.walls(), Walls::default());
|
||||
/// ```
|
||||
#[must_use]
|
||||
pub fn new(pos: Hex) -> Self {
|
||||
Self {
|
||||
@@ -35,6 +43,15 @@ impl HexTile {
|
||||
}
|
||||
|
||||
/// Returns a reference to the tile's walls
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use hexlab::prelude::*;
|
||||
///
|
||||
/// let tile = HexTile::new(Hex::ZERO);
|
||||
/// assert_eq!(*tile.walls(), Walls::default());
|
||||
/// ```
|
||||
#[cfg_attr(not(debug_assertions), inline)]
|
||||
#[must_use]
|
||||
pub const fn walls(&self) -> &Walls {
|
||||
@@ -42,11 +59,21 @@ impl HexTile {
|
||||
}
|
||||
|
||||
/// Returns position of the tile
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use hexlab::prelude::*;
|
||||
///
|
||||
/// let tile = HexTile::new(Hex::new(2, -2));
|
||||
/// assert_eq!(tile.pos(), Hex::new(2, -2));
|
||||
/// ```
|
||||
#[cfg_attr(not(debug_assertions), inline)]
|
||||
#[must_use]
|
||||
pub const fn pos(&self) -> Hex {
|
||||
self.pos
|
||||
}
|
||||
|
||||
/// Converts the tile's position to a 2D vector based on the given layout.
|
||||
///
|
||||
/// # Arguments
|
||||
@@ -55,7 +82,7 @@ impl HexTile {
|
||||
#[cfg(feature = "bevy_reflect")]
|
||||
#[cfg_attr(not(debug_assertions), inline)]
|
||||
#[must_use]
|
||||
pub fn to_vec2(&self, layout: &HexLayout) -> Vec2 {
|
||||
pub fn to_vec2(&self, layout: &HexLayout) -> glam::Vec2 {
|
||||
layout.hex_to_world_pos(self.pos)
|
||||
}
|
||||
|
||||
@@ -67,7 +94,9 @@ impl HexTile {
|
||||
#[cfg(feature = "bevy_reflect")]
|
||||
#[cfg_attr(not(debug_assertions), inline)]
|
||||
#[must_use]
|
||||
pub fn to_vec3(&self, layout: &HexLayout) -> Vec3 {
|
||||
pub fn to_vec3(&self, layout: &HexLayout) -> glam::Vec3 {
|
||||
use glam::Vec3;
|
||||
|
||||
let pos = self.to_vec2(layout);
|
||||
Vec3::new(pos.x, 0., pos.y)
|
||||
}
|
||||
@@ -90,76 +119,26 @@ impl Display for HexTile {
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use hexx::EdgeDirection;
|
||||
|
||||
use super::*;
|
||||
use hexx::EdgeDirection;
|
||||
use rand::{thread_rng, Rng};
|
||||
|
||||
#[test]
|
||||
fn new_tile() {
|
||||
let pos = Hex::ZERO;
|
||||
let tile = HexTile::new(pos);
|
||||
|
||||
assert_eq!(tile.pos, pos, "Position should match constructor argument");
|
||||
assert_eq!(
|
||||
tile.walls,
|
||||
Walls::default(),
|
||||
"Walls should be initialized to default"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tile_walls_accessor() {
|
||||
let pos = Hex::new(1, -1);
|
||||
let tile = HexTile::new(pos);
|
||||
|
||||
// Test walls accessor method
|
||||
let walls_ref = tile.walls();
|
||||
assert_eq!(
|
||||
walls_ref, &tile.walls,
|
||||
"Walls accessor should return reference to walls"
|
||||
);
|
||||
fn random_hex() -> Hex {
|
||||
let mut rng = thread_rng();
|
||||
Hex::new(rng.gen(), rng.gen())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tile_modification() {
|
||||
let pos = Hex::new(2, 3);
|
||||
let mut tile = HexTile::new(pos);
|
||||
let hex = random_hex();
|
||||
let mut tile = HexTile::new(hex);
|
||||
|
||||
// Modify walls
|
||||
tile.walls.remove(EdgeDirection::FLAT_TOP);
|
||||
assert!(
|
||||
!tile.walls.contains(EdgeDirection::FLAT_TOP),
|
||||
"Wall should be removed"
|
||||
);
|
||||
assert!(!tile.walls.contains(EdgeDirection::FLAT_TOP));
|
||||
|
||||
tile.walls.add(EdgeDirection::FLAT_TOP);
|
||||
assert!(
|
||||
tile.walls.contains(EdgeDirection::FLAT_TOP),
|
||||
"Wall should be added back"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tile_clone() {
|
||||
let pos = Hex::new(0, -2);
|
||||
let tile = HexTile::new(pos);
|
||||
|
||||
// Test Clone trait
|
||||
let cloned_tile = tile.clone();
|
||||
assert_eq!(tile, cloned_tile, "Cloned tile should equal original");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tile_debug() {
|
||||
let pos = Hex::ZERO;
|
||||
let tile = HexTile::new(pos);
|
||||
|
||||
// Test Debug trait
|
||||
let debug_string = format!("{:?}", tile);
|
||||
assert!(
|
||||
debug_string.contains("HexTile"),
|
||||
"Debug output should contain struct name"
|
||||
);
|
||||
assert!(tile.walls.contains(EdgeDirection::FLAT_TOP));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -174,38 +153,10 @@ mod test {
|
||||
|
||||
// Verify each tile has correct position
|
||||
for (tile, &pos) in tiles.iter().zip(positions.iter()) {
|
||||
assert_eq!(
|
||||
tile.pos, pos,
|
||||
"Tile position should match constructor argument"
|
||||
);
|
||||
assert_eq!(tile.pos, pos);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tile_equality() {
|
||||
let pos1 = Hex::new(1, 1);
|
||||
let pos2 = Hex::new(1, 1);
|
||||
let pos3 = Hex::new(2, 1);
|
||||
|
||||
let tile1 = HexTile::new(pos1);
|
||||
let tile2 = HexTile::new(pos2);
|
||||
let tile3 = HexTile::new(pos3);
|
||||
|
||||
assert_eq!(tile1, tile2, "Tiles with same position should be equal");
|
||||
assert_ne!(
|
||||
tile1, tile3,
|
||||
"Tiles with different positions should not be equal"
|
||||
);
|
||||
|
||||
// Test with modified walls
|
||||
let mut tile4 = HexTile::new(pos1);
|
||||
tile4.walls.remove(EdgeDirection::FLAT_TOP);
|
||||
assert_ne!(
|
||||
tile1, tile4,
|
||||
"Tiles with different walls should not be equal"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hex_boundaries() {
|
||||
// Test with extreme coordinate values
|
||||
@@ -218,10 +169,77 @@ mod test {
|
||||
|
||||
for pos in extreme_positions {
|
||||
let tile = HexTile::new(pos);
|
||||
assert_eq!(
|
||||
tile.pos, pos,
|
||||
"Tile should handle extreme coordinate values"
|
||||
);
|
||||
assert_eq!(tile.pos, pos);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hex_tile_creation_and_properties() {
|
||||
let hex = random_hex();
|
||||
let tile = HexTile::new(hex);
|
||||
|
||||
assert_eq!(tile.pos(), hex);
|
||||
assert!(tile.walls().is_enclosed());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hex_tile_from_hex() {
|
||||
let hex = random_hex();
|
||||
let tile = HexTile::from(hex);
|
||||
|
||||
assert_eq!(tile.pos, hex);
|
||||
assert_eq!(tile.walls, Walls::default());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hex_hex_into_tile() {
|
||||
let hex = random_hex();
|
||||
let tile: HexTile = hex.into();
|
||||
|
||||
assert_eq!(tile.pos, hex);
|
||||
assert_eq!(tile.walls, Walls::default());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hex_tile_display() {
|
||||
let tile = HexTile::new(Hex::new(3, -3));
|
||||
assert_eq!(format!("{tile}"), "(3,-3)");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hex_tile_wall_modifications() {
|
||||
let mut tile = HexTile::new(Hex::ZERO);
|
||||
|
||||
for direction in EdgeDirection::ALL_DIRECTIONS {
|
||||
tile.walls.add(direction);
|
||||
}
|
||||
assert_eq!(tile.walls.count(), 6);
|
||||
|
||||
for direction in EdgeDirection::ALL_DIRECTIONS {
|
||||
tile.walls.remove(direction);
|
||||
}
|
||||
assert_eq!(tile.walls.count(), 0);
|
||||
}
|
||||
|
||||
#[cfg(feature = "bevy_reflect")]
|
||||
mod bevy_tests {
|
||||
use super::*;
|
||||
use glam::{Vec2, Vec3};
|
||||
|
||||
#[test]
|
||||
fn hex_tile_to_vec2() {
|
||||
let layout = HexLayout::default();
|
||||
let tile = HexTile::new(Hex::new(1, 0));
|
||||
let vec2 = tile.to_vec2(&layout);
|
||||
assert_eq!(vec2, Vec2::new(1.5, -0.8660254));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hex_tile_to_vec3() {
|
||||
let layout = HexLayout::default();
|
||||
let tile = HexTile::new(Hex::new(0, 1));
|
||||
let vec3 = tile.to_vec3(&layout);
|
||||
assert_eq!(vec3, Vec3::new(0.0, 0.0, -1.7320508));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
152
src/walls.rs
152
src/walls.rs
@@ -1,5 +1,3 @@
|
||||
#[cfg(feature = "bevy_reflect")]
|
||||
use bevy::prelude::*;
|
||||
use hexx::EdgeDirection;
|
||||
|
||||
/// A bit-flag representation of walls in a hexagonal tile.
|
||||
@@ -28,7 +26,7 @@ use hexx::EdgeDirection;
|
||||
/// assert_eq!(walls.count(), 2);
|
||||
/// ```
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
#[cfg_attr(feature = "bevy_reflect", derive(Reflect))]
|
||||
#[cfg_attr(feature = "bevy_reflect", derive(bevy_reflect::Reflect))]
|
||||
#[cfg_attr(feature = "bevy", derive(Component))]
|
||||
#[cfg_attr(feature = "bevy", reflect(Component))]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
@@ -38,6 +36,15 @@ impl Walls {
|
||||
/// Creates a new set of walls with all edges closed.
|
||||
///
|
||||
/// This is the default state where all six edges of the hexagon have walls.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use hexlab::prelude::*;
|
||||
///
|
||||
/// let walls = Walls::new();
|
||||
/// assert!(walls.is_enclosed());
|
||||
/// ```
|
||||
#[cfg_attr(not(debug_assertions), inline)]
|
||||
#[must_use]
|
||||
pub fn new() -> Self {
|
||||
@@ -45,6 +52,15 @@ impl Walls {
|
||||
}
|
||||
|
||||
/// Creates a new set of walls with no edges (completely open).
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use hexlab::prelude::*;
|
||||
///
|
||||
/// let walls = Walls::empty();
|
||||
/// assert!(walls.is_empty());
|
||||
/// ```
|
||||
#[cfg_attr(not(debug_assertions), inline)]
|
||||
#[must_use]
|
||||
pub const fn empty() -> Self {
|
||||
@@ -52,6 +68,15 @@ impl Walls {
|
||||
}
|
||||
|
||||
/// Checks if the walls are currently empty (no walls present).
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use hexlab::prelude::*;
|
||||
///
|
||||
/// let walls = Walls::empty();
|
||||
/// assert!(walls.is_empty());
|
||||
/// ```
|
||||
#[cfg_attr(not(debug_assertions), inline)]
|
||||
#[must_use]
|
||||
pub const fn is_empty(&self) -> bool {
|
||||
@@ -62,7 +87,26 @@ impl Walls {
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// 0 `direction` - The direction in which to add the wall.
|
||||
/// - `direction` - The direction in which to add the wall.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use hexlab::prelude::*;
|
||||
///
|
||||
/// let mut walls = Walls::empty();
|
||||
/// assert_eq!(walls.count(), 0);
|
||||
///
|
||||
/// walls.add(1);
|
||||
/// assert_eq!(walls.count(), 1);
|
||||
///
|
||||
/// walls.add(1);
|
||||
/// assert_eq!(walls.count(), 1);
|
||||
///
|
||||
/// walls.add(EdgeDirection::FLAT_NORTH);
|
||||
/// assert_eq!(walls.count(), 2);
|
||||
///
|
||||
/// ```
|
||||
#[cfg_attr(not(debug_assertions), inline)]
|
||||
pub fn add<T>(&mut self, direction: T)
|
||||
where
|
||||
@@ -76,6 +120,23 @@ impl Walls {
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `direction` - The direction from which to remove the wall.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use hexlab::prelude::*;
|
||||
///
|
||||
/// let mut walls = Walls::new();
|
||||
///
|
||||
/// assert!(walls.remove(1));
|
||||
/// assert_eq!(walls.count(), 5);
|
||||
///
|
||||
/// assert!(!walls.remove(1));
|
||||
/// assert_eq!(walls.count(), 5);
|
||||
///
|
||||
/// assert!(walls.remove(EdgeDirection::FLAT_NORTH));
|
||||
/// assert_eq!(walls.count(), 4);
|
||||
/// ```
|
||||
#[cfg_attr(not(debug_assertions), inline)]
|
||||
pub fn remove<T>(&mut self, direction: T) -> bool
|
||||
where
|
||||
@@ -93,6 +154,18 @@ impl Walls {
|
||||
/// # Arguments
|
||||
///
|
||||
/// - `other` - The direction to check for a wall.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use hexlab::prelude::*;
|
||||
///
|
||||
/// let mut walls = Walls::empty();
|
||||
/// walls.add(EdgeDirection::FLAT_NORTH);
|
||||
///
|
||||
/// assert!(walls.contains(EdgeDirection::FLAT_NORTH));
|
||||
/// assert!(!walls.contains(EdgeDirection::FLAT_SOUTH));
|
||||
/// ```
|
||||
#[cfg_attr(not(debug_assertions), inline)]
|
||||
pub fn contains<T>(&self, other: T) -> bool
|
||||
where
|
||||
@@ -102,6 +175,18 @@ impl Walls {
|
||||
}
|
||||
|
||||
/// Returns the raw bit representation of the walls
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use hexlab::prelude::*;
|
||||
///
|
||||
/// let walls = Walls::new();
|
||||
/// assert_eq!(walls.as_bits(), 0b11_1111);
|
||||
///
|
||||
/// let walls = Walls::empty();
|
||||
/// assert_eq!(walls.as_bits(), 0);
|
||||
/// ```
|
||||
#[cfg_attr(not(debug_assertions), inline)]
|
||||
#[must_use]
|
||||
pub const fn as_bits(&self) -> u8 {
|
||||
@@ -109,6 +194,21 @@ impl Walls {
|
||||
}
|
||||
|
||||
/// Returns the total number of walls present
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use hexlab::prelude::*;
|
||||
///
|
||||
/// let mut walls = Walls::empty();
|
||||
/// assert!(walls.is_empty());
|
||||
///
|
||||
/// walls.add(0);
|
||||
/// assert_eq!(walls.count(), 1);
|
||||
///
|
||||
/// walls.add(1);
|
||||
/// assert_eq!(walls.count(), 2);
|
||||
/// ```
|
||||
#[cfg_attr(not(debug_assertions), inline)]
|
||||
#[must_use]
|
||||
pub fn count(&self) -> u8 {
|
||||
@@ -116,6 +216,14 @@ impl Walls {
|
||||
}
|
||||
|
||||
/// Returns a `Walls` value representing all possible directions.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use hexlab::prelude::*;
|
||||
///
|
||||
/// assert_eq!(Walls::all_directions().as_bits(), 0b11_1111);
|
||||
/// ```
|
||||
#[cfg_attr(not(debug_assertions), inline)]
|
||||
#[must_use]
|
||||
pub const fn all_directions() -> Self {
|
||||
@@ -134,6 +242,20 @@ impl Walls {
|
||||
/// # Returns
|
||||
///
|
||||
/// The previous state (`true` if a wall was present before toggling, `false` otherwise).
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use hexlab::prelude::*;
|
||||
///
|
||||
/// let mut walls = Walls::empty();
|
||||
///
|
||||
/// assert!(!walls.toggle(0));
|
||||
/// assert_eq!(walls.count(), 1);
|
||||
///
|
||||
/// assert!(walls.toggle(0));
|
||||
/// assert_eq!(walls.count(), 0);
|
||||
/// ```
|
||||
pub fn toggle<T>(&mut self, direction: T) -> bool
|
||||
where
|
||||
T: Into<Self> + Copy,
|
||||
@@ -155,10 +277,10 @@ impl Walls {
|
||||
///
|
||||
/// # Deprecated
|
||||
///
|
||||
/// This method is deprecated since version 0.3.1. Use `is_enclosed()` instead.
|
||||
/// This method is deprecated since version 0.4.0. Use `is_enclosed()` instead.
|
||||
#[cfg_attr(not(debug_assertions), inline)]
|
||||
#[must_use]
|
||||
#[deprecated(since = "0.3.1", note = "use `walls::Walls::is_enclosed()`")]
|
||||
#[deprecated(since = "0.4.0", note = "use `walls::Walls::is_enclosed()`")]
|
||||
pub fn is_closed(&self) -> bool {
|
||||
self.is_enclosed()
|
||||
}
|
||||
@@ -168,6 +290,18 @@ impl Walls {
|
||||
/// # Returns
|
||||
///
|
||||
/// `true` if the hexagon has all possible walls, making it completely enclosed.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use hexlab::prelude::*;
|
||||
///
|
||||
/// let mut walls = Walls::new();
|
||||
/// assert!(walls.is_enclosed());
|
||||
///
|
||||
/// walls.remove(0);
|
||||
/// assert!(!walls.is_enclosed());
|
||||
/// ```
|
||||
#[cfg_attr(not(debug_assertions), inline)]
|
||||
#[must_use]
|
||||
pub fn is_enclosed(&self) -> bool {
|
||||
@@ -247,7 +381,7 @@ mod test {
|
||||
#[test]
|
||||
fn all_directions_creates_closed_walls() {
|
||||
let walls = Walls::all_directions();
|
||||
assert!(walls.is_closed());
|
||||
assert!(walls.is_enclosed());
|
||||
assert!(!walls.is_empty());
|
||||
assert_eq!(walls.as_bits(), 0b111111);
|
||||
}
|
||||
@@ -284,7 +418,7 @@ mod test {
|
||||
#[test]
|
||||
fn new_created_closed_walls() {
|
||||
let walls = Walls::new();
|
||||
assert!(walls.is_closed());
|
||||
assert!(walls.is_enclosed());
|
||||
assert_eq!(walls.as_bits(), 0b111111);
|
||||
}
|
||||
|
||||
@@ -393,7 +527,7 @@ mod test {
|
||||
#[test]
|
||||
fn default_creates_closed_walls() {
|
||||
let walls = Walls::default();
|
||||
assert!(walls.is_closed());
|
||||
assert!(walls.is_enclosed());
|
||||
assert_eq!(walls.as_bits(), 0b111111);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user