Skip to content

Commit

Permalink
refactor(map): remove unnecessary reference in from_actions
Browse files Browse the repository at this point in the history
- Change the signature of Map::from_actions from &Actions to Actions
- Update all calls to from_actions to pass Actions directly instead of references
  • Loading branch information
ShenMian committed Nov 20, 2024
1 parent 51eead6 commit fa2fce5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl Map {
///
/// Tries to restore the map with a complete solution. This method can only
/// restore the parts of the map that are used by the solution.
pub fn from_actions(actions: &Actions) -> Result<Self, ParseMapError> {
pub fn from_actions(actions: Actions) -> Result<Self, ParseMapError> {
let mut min_position = Vector2::<i32>::zeros();
let mut max_position = Vector2::<i32>::zeros();

Expand Down
14 changes: 7 additions & 7 deletions tests/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,23 +67,23 @@ fn map_from_str() {

#[test]
fn map_from_actions() {
assert!(Map::from_actions(&Actions::from_str("R").unwrap()).is_ok());
assert!(Map::from_actions(&Actions::from_str("DuLLrUUdrR").unwrap()).is_ok());
assert!(Map::from_actions(Actions::from_str("R").unwrap()).is_ok());
assert!(Map::from_actions(Actions::from_str("DuLLrUUdrR").unwrap()).is_ok());

assert_eq!(
Map::from_actions(&Actions::from_str("RddrU").unwrap()).unwrap_err(),
Map::from_actions(Actions::from_str("RddrU").unwrap()).unwrap_err(),
ParseMapError::InvalidActions
);
assert_eq!(
Map::from_actions(&Actions::from_str("RdU").unwrap()).unwrap_err(),
Map::from_actions(Actions::from_str("RdU").unwrap()).unwrap_err(),
ParseMapError::InvalidActions
);
assert_eq!(
Map::from_actions(&Actions::from_str("RL").unwrap()).unwrap_err(),
Map::from_actions(Actions::from_str("RL").unwrap()).unwrap_err(),
ParseMapError::InvalidActions
);
assert_eq!(
Map::from_actions(&Actions::from_str("llurldd").unwrap()).unwrap_err(),
Map::from_actions(Actions::from_str("llurldd").unwrap()).unwrap_err(),
ParseMapError::NoBoxOrGoal
);
}
Expand Down Expand Up @@ -149,7 +149,7 @@ fn from_actions() {
Actions::from_str("uulLdlluRRllddlluuRRdrruRurDDulldldddllUdrruuluullddRluurrdrrurrdDldLrurrdLLuruulldlluRRRurDDullllllddrddrrUUddlluuluurrdRurrrdDldLrurrdLLuruullllllddrddrrUULuurrrrdddlLruruullllddrUluRRRurDDullllllddRddrrUUdrrrruLdllluUluRRRurDDDrdLL")
.unwrap();
assert_eq!(
Map::from_actions(&actions).unwrap(),
Map::from_actions(actions).unwrap(),
Map::from_str(
r#"
-----####-
Expand Down

0 comments on commit fa2fce5

Please sign in to comment.