Created Hand Type

Created a Hand type that can also calculate the sum of the cards in the
hand. Also wrote a display for it so that we can just print hands out.
This commit is contained in:
2026-01-11 16:22:35 -05:00
parent b5cc0a7293
commit a7567d2a09
3 changed files with 127 additions and 0 deletions

40
tests/hand_tests.rs Normal file
View File

@@ -0,0 +1,40 @@
use blackjack::Card;
use blackjack::Hand;
const ACE_HEARTS: Card = Card { suit: 0, value: 0 };
const ACE_SPADES: Card = Card { suit: 3, value: 0 };
const KING_HEARTS: Card = Card { suit: 0, value: 12 };
const KING_SPADES: Card = Card { suit: 3, value: 12 };
#[test]
fn test_double_ace() {
let mut hand = Hand::new(false);
hand.get_new_card(ACE_HEARTS);
hand.get_new_card(ACE_SPADES);
assert_eq!(12, hand.sum());
}
#[test]
fn double_ace_double_face() {
let mut hand = Hand::new(false);
hand.get_new_card(ACE_HEARTS);
hand.get_new_card(ACE_SPADES);
hand.get_new_card(KING_HEARTS);
hand.get_new_card(KING_SPADES);
assert_eq!(22, hand.sum());
}
#[test]
fn show_all_is_dealer() {
let mut hand = Hand::new(true);
hand.get_new_card(ACE_HEARTS);
hand.get_new_card(KING_SPADES);
assert_eq!(10, hand.sum());
hand.set_show_all(true);
assert_eq!(21, hand.sum());
}