From 7b0eaf6640e3b7e3d4558c20b9f598e0591e5e7e Mon Sep 17 00:00:00 2001 From: Joachim Lusiardi Date: Wed, 6 Dec 2023 20:59:03 +0100 Subject: [PATCH] add test & fix bug --- src/level.rs | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/level.rs b/src/level.rs index 80dea11..46ac627 100644 --- a/src/level.rs +++ b/src/level.rs @@ -23,9 +23,9 @@ pub struct Level { pub(crate) discovered: [[bool; LEVEL_HEIGHT]; LEVEL_WIDTH], pub(crate) monsters: Vec, pub(crate) artifacts: Vec>, - /// the position of the start in the level (eiter stair up or start point) + /// the position of the start in the level (either stair up or start point) pub(crate) start: (usize, usize), - /// the position of the end in the level (eiter stair down or end point) + /// the position of the end in the level (either stair down or end point) pub(crate) end: (usize, usize), } @@ -120,7 +120,7 @@ impl Level { } for (index, a) in &mut self.artifacts.iter().enumerate() { if a.get_immutable_position() == position { - self.monsters.remove(index); + self.artifacts.remove(index); break; } } @@ -304,3 +304,21 @@ fn test_monster_can_be_removed() { assert!(level.get_element(10, 10).1.is_none()); } + +#[test] +fn test_artefact_can_be_removed() { + let mut l = Level::new(0); + let p = Position::new(0, 10, 10); + l.discover(&p); + assert_eq!(l.get_element(10, 10).0.unwrap(), StructureElement::Floor); + assert!(l.get_element(10, 10).2.is_none()); + + let a = Chest::new(Position::new(0, 10, 10)); + assert_eq!(l.add_artifact(a), Ok(())); + + l.remove_artifact(&Position::new(0, 10, 10)).expect("Foo"); + + let elem = l.get_element(10, 10); + assert_eq!(elem.0.unwrap(), StructureElement::Floor); + assert!(elem.2.is_none()); +}