@@ -1331,5 +1331,34 @@ mod test {
1331
1331
) ;
1332
1332
}
1333
1333
}
1334
+ #[ test]
1335
+ fn invalid_index_error ( ) {
1336
+ const HEIGHT : SizeType = 4 ;
1337
+ const WIDTH : SizeType = 6 ;
1338
+ const NUMBER_OF_MINES : SizeType = 10 ;
1339
+ let expected_open_error: Result < OpenInfo , & ' static str > = Err ( INVALID_INDEX_ERROR ) ;
1340
+ let expected_flag_error: Result < FlagResult , & ' static str > = Err ( INVALID_INDEX_ERROR ) ;
1341
+ let mut game = BasicTable :: new ( HEIGHT , WIDTH , NUMBER_OF_MINES ) . unwrap ( ) ;
1342
+ let mut check_indices = |row, col, message| {
1343
+ let open_result = game. open_field ( row, col) ;
1344
+ assert_eq ! ( expected_open_error, open_result, "{} open_field" , message) ;
1345
+ let open_neighbors_result = game. open_neighbors ( row, col) ;
1346
+ assert_eq ! (
1347
+ expected_open_error, open_neighbors_result,
1348
+ "{} open_neighbors" ,
1349
+ message
1350
+ ) ;
1351
+ let flag_result = game. toggle_flag ( row, col) ;
1352
+ assert_eq ! ( expected_flag_error, flag_result, "{} toggle_flag" , message) ;
1353
+ } ;
1354
+ const GOOD_INDEX : SizeType = 1 ;
1355
+ check_indices ( HEIGHT , GOOD_INDEX , "Exact height" ) ;
1356
+ check_indices ( GOOD_INDEX , WIDTH , "Exact width" ) ;
1357
+ check_indices ( HEIGHT , WIDTH , "Exact both" ) ;
1358
+ check_indices ( -1 , GOOD_INDEX , "Negative height" ) ;
1359
+ check_indices ( GOOD_INDEX , -1 , "Negative width" ) ;
1360
+ check_indices ( -1 , -1 , "Negative both" ) ;
1361
+ }
1362
+
1334
1363
// TODO Write test to full game
1335
1364
}
0 commit comments