@@ -266,7 +266,7 @@ impl CardDeck {
266
266
pub fn check_deal_cards ( & self , cards_to_deal : usize , include_muck : bool ) -> bool {
267
267
let mut total_cards = self . deck . len ( ) ;
268
268
if include_muck {
269
- total_cards = self . muck . len ( ) ;
269
+ total_cards + = self . muck . len ( ) ;
270
270
}
271
271
total_cards >= cards_to_deal
272
272
}
@@ -495,6 +495,46 @@ mod tests {
495
495
}
496
496
}
497
497
498
+ #[ test]
499
+ fn test_calculate_cards_left_without_muck ( ) {
500
+ let mut deck = CardDeck :: new ( None ) . expect ( "Deck could not be created" ) ;
501
+
502
+ deck. shuffle ( None ) . expect ( "Deck could not be shuffled" ) ;
503
+
504
+ let enough_cards = [ true , true , true , true , true , false ] ;
505
+ const CARDS_TO_DEAL : usize = 10 ;
506
+ const INCLUDE_MUCK : bool = false ;
507
+ for expect_enough_cards in enough_cards {
508
+ assert ! ( deck. check_deal_cards( CARDS_TO_DEAL , INCLUDE_MUCK ) == expect_enough_cards) ;
509
+ if expect_enough_cards {
510
+ let drawn_cards = deck
511
+ . deal_cards ( CARDS_TO_DEAL , INCLUDE_MUCK )
512
+ . expect ( "Cards could not be drawn" ) ;
513
+ deck. muck_cards ( drawn_cards) ;
514
+ }
515
+ }
516
+ }
517
+
518
+ #[ test]
519
+ fn test_calculate_cards_left_with_muck ( ) {
520
+ let mut deck = CardDeck :: new ( None ) . expect ( "Deck could not be created" ) ;
521
+
522
+ deck. shuffle ( None ) . expect ( "Deck could not be shuffled" ) ;
523
+
524
+ let enough_cards = [ true , true , true , true , true , true ] ;
525
+ const CARDS_TO_DEAL : usize = 10 ;
526
+ const INCLUDE_MUCK : bool = true ;
527
+ for expect_enough_cards in enough_cards {
528
+ assert ! ( deck. check_deal_cards( CARDS_TO_DEAL , INCLUDE_MUCK ) == expect_enough_cards) ;
529
+ if expect_enough_cards {
530
+ let drawn_cards = deck
531
+ . deal_cards ( CARDS_TO_DEAL , INCLUDE_MUCK )
532
+ . expect ( "Cards could not be drawn" ) ;
533
+ deck. muck_cards ( drawn_cards) ;
534
+ }
535
+ }
536
+ }
537
+
498
538
// This test relies on random entropy seeding. By the very nature of random numbers and normal
499
539
// curves, there will be a subset of runs that will fail since the actual percentage lands
500
540
// outside if the bounds of the expected percentage (+/- 0.2%).
0 commit comments