From 93a50e6b86c9e0ab7aea2e7e0c18fbcde4731f81 Mon Sep 17 00:00:00 2001 From: Max Bradbury Date: Wed, 24 Jun 2020 15:30:16 +0100 Subject: [PATCH] don't try to get tiles with ID of zero; test this --- src/game.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/game.rs b/src/game.rs index b89b94f..786b93b 100644 --- a/src/game.rs +++ b/src/game.rs @@ -230,7 +230,7 @@ impl Game { if ! avatar_exists { return Err(NotFound::Avatar); } - + Ok( Game { name, @@ -318,6 +318,12 @@ impl Game { let mut tile_ids = room.unwrap().tiles.clone(); tile_ids.sort(); tile_ids.dedup(); + // remove 0 as this isn't a real tile + let zero_index = tile_ids.iter() + .position(|i| i == &"0".to_string()); + if zero_index.is_some() { + tile_ids.remove(zero_index.unwrap()); + } // remove Ok once this function returns a result Ok(self.get_tiles_by_ids(tile_ids)) } @@ -679,4 +685,12 @@ mod test { game.version = Some(Version { major: 5, minor: 0 }); assert!(game.to_string().contains("# BITSY VERSION 5.0")) } + + #[test] + fn test_get_tiles_for_room() { + assert_eq!( + crate::mock::game_default().get_tiles_for_room("0".to_string()).unwrap(), + vec![&crate::mock::tile_default()] + ) + } }