@@ -203,6 +203,7 @@ pub fn calculate_replacement_number_3_player(
203
203
#[ cfg( test) ]
204
204
mod tests {
205
205
use super :: * ;
206
+ use crate :: bingpai:: InvalidBingpaiError ;
206
207
207
208
#[ test]
208
209
fn calculate_replacement_number_standard_tenpai ( ) {
@@ -251,7 +252,52 @@ mod tests {
251
252
let replacement_number = calculate_replacement_number ( & bingpai, & None ) ;
252
253
assert ! ( matches!(
253
254
replacement_number. unwrap_err( ) ,
254
- InvalidShoupaiError :: EmptyShoupai
255
+ InvalidShoupaiError :: InvalidBingpai ( InvalidBingpaiError :: EmptyBingpai )
256
+ ) ) ;
257
+ }
258
+
259
+ #[ test]
260
+ fn calculate_replacement_number_too_many_tiles ( ) {
261
+ let bingpai: Bingpai = [
262
+ 1 , 1 , 1 , 1 , 0 , 0 , 0 , 0 , 0 , // m
263
+ 1 , 1 , 1 , 1 , 0 , 0 , 0 , 0 , 0 , // p
264
+ 1 , 1 , 1 , 1 , 0 , 0 , 0 , 0 , 0 , // s
265
+ 1 , 1 , 1 , 0 , 0 , 0 , 0 , // z
266
+ ] ;
267
+ let replacement_number = calculate_replacement_number ( & bingpai, & None ) ;
268
+ assert ! ( matches!(
269
+ replacement_number. unwrap_err( ) ,
270
+ InvalidShoupaiError :: InvalidBingpai ( InvalidBingpaiError :: ExceedsMaxNumBingpai ( 15 ) )
271
+ ) ) ;
272
+ }
273
+
274
+ #[ test]
275
+ fn calculate_replacement_number_5th_tile ( ) {
276
+ let bingpai: Bingpai = [
277
+ 5 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , // m
278
+ 1 , 1 , 1 , 1 , 0 , 0 , 0 , 0 , 0 , // p
279
+ 1 , 1 , 1 , 1 , 0 , 0 , 0 , 0 , 0 , // s
280
+ 1 , 0 , 0 , 0 , 0 , 0 , 0 , // z
281
+ ] ;
282
+ let replacement_number = calculate_replacement_number ( & bingpai, & None ) ;
283
+ assert ! ( matches!(
284
+ replacement_number. unwrap_err( ) ,
285
+ InvalidShoupaiError :: InvalidBingpai ( InvalidBingpaiError :: ExceedsMaxNumSameTile ( 5 ) )
286
+ ) ) ;
287
+ }
288
+
289
+ #[ test]
290
+ fn calculate_replacement_number_incomplete_hand ( ) {
291
+ let bingpai: Bingpai = [
292
+ 4 , 4 , 4 , 0 , 0 , 0 , 0 , 0 , 0 , // m
293
+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , // p
294
+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , // s
295
+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , // z
296
+ ] ;
297
+ let replacement_number = calculate_replacement_number ( & bingpai, & None ) ;
298
+ assert ! ( matches!(
299
+ replacement_number. unwrap_err( ) ,
300
+ InvalidShoupaiError :: InvalidBingpai ( InvalidBingpaiError :: InvalidNumBingpai ( 12 ) )
255
301
) ) ;
256
302
}
257
303
@@ -302,7 +348,35 @@ mod tests {
302
348
let replacement_number = calculate_replacement_number_3_player ( & bingpai, & None ) ;
303
349
assert ! ( matches!(
304
350
replacement_number. unwrap_err( ) ,
305
- InvalidShoupaiError :: EmptyShoupai
351
+ InvalidShoupaiError :: InvalidBingpai ( InvalidBingpaiError :: EmptyBingpai )
352
+ ) ) ;
353
+ }
354
+
355
+ #[ test]
356
+ fn calculate_replacement_number_3_player_2m_8m ( ) {
357
+ let bingpai_2m: Bingpai = [
358
+ 0 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , // m
359
+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , // p
360
+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , // s
361
+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , // z
362
+ ] ;
363
+ let bingpai_8m: Bingpai = [
364
+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 0 , // m
365
+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , // p
366
+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , // s
367
+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , // z
368
+ ] ;
369
+
370
+ let replacement_number_2m = calculate_replacement_number_3_player ( & bingpai_2m, & None ) ;
371
+ let replacement_number_8m = calculate_replacement_number_3_player ( & bingpai_8m, & None ) ;
372
+
373
+ assert ! ( matches!(
374
+ replacement_number_2m. unwrap_err( ) ,
375
+ InvalidShoupaiError :: InvalidBingpai ( InvalidBingpaiError :: InvalidTileFor3Player ( 1 ) )
376
+ ) ) ;
377
+ assert ! ( matches!(
378
+ replacement_number_8m. unwrap_err( ) ,
379
+ InvalidShoupaiError :: InvalidBingpai ( InvalidBingpaiError :: InvalidTileFor3Player ( 7 ) )
306
380
) ) ;
307
381
}
308
382
}
0 commit comments