Test: Too short input

This commit is contained in:
Jonas Zeunert
2024-02-18 15:57:12 +01:00
parent 2eb0925f1d
commit 4f3068b8b9

View File

@@ -71,13 +71,16 @@ fn parse_playfield(field: &String, field_size: usize) -> Playfield {
let chars = field.split(" ").collect::<Vec<&str>>(); let chars = field.split(" ").collect::<Vec<&str>>();
if chars.len() != field_size * field_size {
panic!(
"Input must have dimension of size {size}x{size}",
size = field_size
);
}
for row in 0..field_size { for row in 0..field_size {
for col in 0..field_size { for col in 0..field_size {
let field = &mut playfield.fields[row][col]; let field = &mut playfield.fields[row][col];
let char_field = chars.get(row * field_size + col).expect(&format!( let char_field = chars.get(row * field_size + col).unwrap();
"Input must have dimension of size {size}x{size}",
size = field_size
));
if *char_field == "0" { if *char_field == "0" {
continue; continue;
@@ -115,11 +118,20 @@ mod tests {
} }
#[test] #[test]
#[should_panic(expected = "Input must have dimension of size 2x2)")] #[should_panic(expected = "Input must have dimension of size 2x2")]
fn test_parse_field_too_long_input() { fn test_parse_field_too_long_input() {
let input = "1 2 3 0 0 0 3 2 1"; let input = "1 2 3 0 0 0 3 2 1";
let field_size = 2; let field_size = 2;
let _ = parse_playfield(&input.to_string(), field_size); let _ = parse_playfield(&input.to_string(), field_size);
} }
#[test]
#[should_panic(expected = "Input must have dimension of size 2x2")]
fn test_parse_field_too_short_input() {
let input = "1 2 3";
let field_size = 2;
let _ = parse_playfield(&input.to_string(), field_size);
}
} }