-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d4a9513
commit bc8a3d9
Showing
4 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
use crate::game::hexchess::Hexchess; | ||
use crate::game::notation::Notation; | ||
|
||
pub fn execute(hexchess_arg: String, notation_arg: String) -> Result<String, String> { | ||
let hexchess = match Hexchess::from(hexchess_arg.as_str()) { | ||
Ok(result) => result, | ||
Err(_) => return Err(format!("invalid state: {}", hexchess_arg)), | ||
}; | ||
|
||
let notation = match Notation::from(notation_arg.as_str()) { | ||
Ok(result) => result, | ||
Err(_) => return Err(format!("invalid notation: {}", notation_arg)), | ||
}; | ||
|
||
if hexchess.all_targets().contains(¬ation) { | ||
return Ok("ok".to_string()); | ||
} | ||
|
||
return Err("illegal".to_string()); | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use crate::app::{App, Command, handle}; | ||
|
||
#[test] | ||
fn test_check_move() { | ||
let output = handle(App { | ||
command: Command::CheckMove { | ||
fen: crate::constants::INITIAL_HEXCHESS.to_string(), | ||
notation: "g4g5".to_string(), | ||
} | ||
}); | ||
|
||
assert_eq!(Ok("ok".to_string()), output); | ||
} | ||
|
||
#[test] | ||
fn test_check_move_invalid() { | ||
let output = handle(App { | ||
command: Command::CheckMove { | ||
fen: crate::constants::INITIAL_HEXCHESS.to_string(), | ||
notation: "whoops".to_string(), | ||
} | ||
}); | ||
|
||
assert_eq!(output, Err("invalid notation: whoops".to_string())); | ||
} | ||
|
||
#[test] | ||
fn test_check_move_illegal() { | ||
let output = handle(App { | ||
command: Command::CheckMove { | ||
fen: crate::constants::INITIAL_HEXCHESS.to_string(), | ||
notation: "a1a2".to_string(), | ||
} | ||
}); | ||
|
||
assert_eq!(output, Err("illegal".to_string())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
pub mod all_targets; | ||
pub mod apply_sequence; | ||
pub mod check_move; | ||
pub mod get_targets; | ||
pub mod parse; |