Skip to content

Commit

Permalink
test(action): add unit tests for Action conversions
Browse files Browse the repository at this point in the history
- Implement tests for converting chars to Actions
- Verify correct parsing of move and push actions
- Test error handling for invalid inputs
- Add tests for converting Actions back to chars
  • Loading branch information
ShenMian committed Jan 2, 2025
1 parent 7c743ec commit c301ffd
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tests/action.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use soukoban::{direction::Direction, Action};

#[test]
fn action_from_char() {
assert_eq!(Action::try_from('u'), Ok(Action::Move(Direction::Up)));
assert_eq!(Action::try_from('d'), Ok(Action::Move(Direction::Down)));

assert_eq!(Action::try_from('U'), Ok(Action::Push(Direction::Up)));
assert_eq!(Action::try_from('D'), Ok(Action::Push(Direction::Down)));

assert!(Action::try_from('x').is_err());
}

#[test]
fn action_to_char() {
assert_eq!(char::from(Action::Move(Direction::Up)), 'u');
assert_eq!(char::from(Action::Push(Direction::Up)), 'U');
}

0 comments on commit c301ffd

Please sign in to comment.