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.
41 lines
926 B
Rust
41 lines
926 B
Rust
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());
|
|
}
|