Skip to content

Commit

Permalink
tinybrain: Parse two-digit numbers correctly (#235)
Browse files Browse the repository at this point in the history
* Add a test

* Fix numeral parsing
  • Loading branch information
Terkwood authored Apr 23, 2020
1 parent d756a05 commit 8e8bfc3
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 12 deletions.
20 changes: 10 additions & 10 deletions tinybrain/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tinybrain/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tinybrain"
version = "0.1.8"
version = "0.1.9"
authors = ["terkwood <38859656+Terkwood@users.noreply.github.com>"]
edition = "2018"

Expand Down
21 changes: 20 additions & 1 deletion tinybrain/src/katago/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl TryFrom<KataGoResponse> for MoveComputed {
let left: char = ans[0];
Some(AlphaNumCoord(
left,
alpha_num_or_pass[1..2].parse::<u16>().expect("alphanum "),
alpha_num_or_pass[1..].parse::<u16>().expect("alphanum"),
))
};

Expand Down Expand Up @@ -137,6 +137,25 @@ mod tests {
assert_eq!(actual, expected)
}

#[test]
fn y_coord_not_truncated() {
let actual = MoveComputed::try_from(KataGoResponse {
id: Id(format!("{}_1_WHITE", Uuid::nil().to_string())),
turn_number: 1,
move_infos: vec![MoveInfo {
r#move: "D10".to_string(),
order: 0,
}],
})
.expect("fail");
let expected = MoveComputed {
game_id: GameId(Uuid::nil()),
alphanum_coord: Some(AlphaNumCoord('D', 10)),
player: Player::WHITE,
};
assert_eq!(actual, expected)
}

#[test]
fn move_computed_from_pass() {
let actual = MoveComputed::try_from(KataGoResponse {
Expand Down

0 comments on commit 8e8bfc3

Please sign in to comment.