-
Notifications
You must be signed in to change notification settings - Fork 520
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
part of #1824
- Loading branch information
Showing
3 changed files
with
133 additions
and
50 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use minesweeper::*; | ||
|
||
{% for test in cases %} | ||
#[test] | ||
#[ignore] | ||
fn {{ test.description | make_ident }}() { | ||
{% if test.input.minefield | length < 2 -%} | ||
let input = &[ | ||
{%- for line in test.input.minefield %} | ||
{{ line | json_encode() }}, | ||
{%- endfor %} | ||
]; | ||
let expected{% if test.expected | length == 0 %}: &[&str]{% endif %} = &[ | ||
{%- for line in test.expected %} | ||
{{ line | json_encode() }}, | ||
{%- endfor %} | ||
]; | ||
{% else -%} | ||
#[rustfmt::skip] | ||
let (input, expected) = (&[ | ||
{%- for line in test.input.minefield %} | ||
{{ line | json_encode() }}, | ||
{%- endfor %} | ||
], &[ | ||
{%- for line in test.expected %} | ||
{{ line | json_encode() }}, | ||
{%- endfor %} | ||
]); | ||
{% endif -%} | ||
let actual = annotate(input); | ||
assert_eq!(actual, expected); | ||
} | ||
{% endfor -%} |
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 |
---|---|---|
@@ -1,153 +1,190 @@ | ||
use minesweeper::annotate; | ||
|
||
fn remove_annotations(board: &[&str]) -> Vec<String> { | ||
board.iter().map(|r| remove_annotations_in_row(r)).collect() | ||
} | ||
|
||
fn remove_annotations_in_row(row: &str) -> String { | ||
row.as_bytes() | ||
.iter() | ||
.map(|&ch| match ch { | ||
b'*' => '*', | ||
_ => ' ', | ||
}) | ||
.collect() | ||
} | ||
|
||
fn run_test(test_case: &[&str]) { | ||
let cleaned = remove_annotations(test_case); | ||
let cleaned_strs = cleaned.iter().map(|r| &r[..]).collect::<Vec<_>>(); | ||
let expected = test_case.iter().map(|&r| r.to_string()).collect::<Vec<_>>(); | ||
assert_eq!(expected, annotate(&cleaned_strs)); | ||
} | ||
use minesweeper::*; | ||
|
||
#[test] | ||
fn no_rows() { | ||
#[rustfmt::skip] | ||
run_test(&[ | ||
]); | ||
let input = &[]; | ||
let expected: &[&str] = &[]; | ||
let actual = annotate(input); | ||
assert_eq!(actual, expected); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn no_columns() { | ||
#[rustfmt::skip] | ||
run_test(&[ | ||
"", | ||
]); | ||
let input = &[""]; | ||
let expected = &[""]; | ||
let actual = annotate(input); | ||
assert_eq!(actual, expected); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn no_mines() { | ||
#[rustfmt::skip] | ||
run_test(&[ | ||
let (input, expected) = (&[ | ||
" ", | ||
" ", | ||
" ", | ||
], &[ | ||
" ", | ||
" ", | ||
" ", | ||
]); | ||
let actual = annotate(input); | ||
assert_eq!(actual, expected); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn board_with_only_mines() { | ||
fn minefield_with_only_mines() { | ||
#[rustfmt::skip] | ||
run_test(&[ | ||
let (input, expected) = (&[ | ||
"***", | ||
"***", | ||
"***", | ||
], &[ | ||
"***", | ||
"***", | ||
"***", | ||
]); | ||
let actual = annotate(input); | ||
assert_eq!(actual, expected); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn mine_surrounded_by_spaces() { | ||
#[rustfmt::skip] | ||
run_test(&[ | ||
let (input, expected) = (&[ | ||
" ", | ||
" * ", | ||
" ", | ||
], &[ | ||
"111", | ||
"1*1", | ||
"111", | ||
]); | ||
let actual = annotate(input); | ||
assert_eq!(actual, expected); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn space_surrounded_by_mines() { | ||
#[rustfmt::skip] | ||
run_test(&[ | ||
let (input, expected) = (&[ | ||
"***", | ||
"* *", | ||
"***", | ||
], &[ | ||
"***", | ||
"*8*", | ||
"***", | ||
]); | ||
let actual = annotate(input); | ||
assert_eq!(actual, expected); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn horizontal_line() { | ||
#[rustfmt::skip] | ||
run_test(&[ | ||
"1*2*1", | ||
]); | ||
let input = &[" * * "]; | ||
let expected = &["1*2*1"]; | ||
let actual = annotate(input); | ||
assert_eq!(actual, expected); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn horizontal_line_mines_at_edges() { | ||
#[rustfmt::skip] | ||
run_test(&[ | ||
"*1 1*", | ||
]); | ||
let input = &["* *"]; | ||
let expected = &["*1 1*"]; | ||
let actual = annotate(input); | ||
assert_eq!(actual, expected); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn vertical_line() { | ||
#[rustfmt::skip] | ||
run_test(&[ | ||
let (input, expected) = (&[ | ||
" ", | ||
"*", | ||
" ", | ||
"*", | ||
" ", | ||
], &[ | ||
"1", | ||
"*", | ||
"2", | ||
"*", | ||
"1", | ||
]); | ||
let actual = annotate(input); | ||
assert_eq!(actual, expected); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn vertical_line_mines_at_edges() { | ||
#[rustfmt::skip] | ||
run_test(&[ | ||
let (input, expected) = (&[ | ||
"*", | ||
" ", | ||
" ", | ||
" ", | ||
"*", | ||
], &[ | ||
"*", | ||
"1", | ||
" ", | ||
"1", | ||
"*", | ||
]); | ||
let actual = annotate(input); | ||
assert_eq!(actual, expected); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn cross() { | ||
#[rustfmt::skip] | ||
run_test(&[ | ||
let (input, expected) = (&[ | ||
" * ", | ||
" * ", | ||
"*****", | ||
" * ", | ||
" * ", | ||
], &[ | ||
" 2*2 ", | ||
"25*52", | ||
"*****", | ||
"25*52", | ||
" 2*2 ", | ||
]); | ||
let actual = annotate(input); | ||
assert_eq!(actual, expected); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn large_board() { | ||
fn large_minefield() { | ||
#[rustfmt::skip] | ||
run_test(&[ | ||
let (input, expected) = (&[ | ||
" * * ", | ||
" * ", | ||
" * ", | ||
" * *", | ||
" * * ", | ||
" ", | ||
], &[ | ||
"1*22*1", | ||
"12*322", | ||
" 123*2", | ||
"112*4*", | ||
"1*22*2", | ||
"111111", | ||
]); | ||
let actual = annotate(input); | ||
assert_eq!(actual, expected); | ||
} |