76 lines
2.3 KiB
Rust
76 lines
2.3 KiB
Rust
//! Deck construction per deck rule.
|
|
//! Reference: short deck (6+ hold'em) removes the twos through fives: 9 ranks x 4 suits = 36 cards
|
|
//! (Wikipedia, "Six-plus hold'em").
|
|
|
|
use pokerfreak::card::{deck, Card, Rank, Suit};
|
|
use pokerfreak::rng::Rng;
|
|
use pokerfreak::variant::DeckRule;
|
|
|
|
fn cs(text: &str) -> Vec<Card> {
|
|
Card::parse_list(text).expect("cards")
|
|
}
|
|
|
|
#[test]
|
|
fn short_deck_has_36_cards_and_no_twos_to_fives() {
|
|
let cards = deck::of(DeckRule::SHORT);
|
|
assert_eq!(cards.len(), 36);
|
|
assert!(cards.iter().all(|c| c.rank >= Rank::Six), "{cards:?}");
|
|
assert!(!cards.contains(&cs("5h")[0]));
|
|
assert!(!cards.contains(&cs("2c")[0]));
|
|
}
|
|
|
|
#[test]
|
|
fn short_deck_has_every_suit_of_every_rank_from_six_up_exactly_once() {
|
|
let cards = deck::of(DeckRule::SHORT);
|
|
for rank in Rank::ALL.iter().filter(|r| **r >= Rank::Six) {
|
|
for suit in Suit::ALL {
|
|
assert_eq!(cards.iter().filter(|c| c.rank == *rank && c.suit == suit).count(), 1);
|
|
}
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn the_full_rule_is_the_old_52_card_deck_in_the_same_order() {
|
|
assert_eq!(deck::of(DeckRule::FULL), deck::full());
|
|
assert_eq!(deck::full().len(), 52);
|
|
}
|
|
|
|
#[test]
|
|
fn without_in_removes_dead_cards_from_the_rule_deck() {
|
|
let dead = cs("Ah Kd 6c");
|
|
let left = deck::without_in(DeckRule::SHORT, &dead);
|
|
assert_eq!(left.len(), 33);
|
|
assert!(dead.iter().all(|c| !left.contains(c)));
|
|
}
|
|
|
|
#[test]
|
|
fn without_in_ignores_dead_cards_that_are_not_in_the_deck() {
|
|
let left = deck::without_in(DeckRule::SHORT, &cs("5h 2c"));
|
|
assert_eq!(left.len(), 36);
|
|
}
|
|
|
|
#[test]
|
|
fn without_in_full_matches_without() {
|
|
let dead = cs("Ah Kd 2c");
|
|
assert_eq!(deck::without_in(DeckRule::FULL, &dead), deck::without(&dead));
|
|
}
|
|
|
|
#[test]
|
|
fn short_deck_draws_never_contain_cards_below_six() {
|
|
let pool = deck::of(DeckRule::SHORT);
|
|
let mut rng = Rng::seeded(2024);
|
|
for _ in 0..500 {
|
|
let (hand, next) = deck::draw(&pool, 9, rng).expect("pool is big enough");
|
|
rng = next;
|
|
assert!(hand.iter().all(|c| c.rank >= Rank::Six), "{hand:?}");
|
|
assert!(hand.iter().enumerate().all(|(i, c)| !hand[..i].contains(c)), "{hand:?}");
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn drawing_more_than_the_short_deck_holds_is_none() {
|
|
let pool = deck::of(DeckRule::SHORT);
|
|
assert!(deck::draw(&pool, 37, Rng::seeded(1)).is_none());
|
|
assert!(deck::draw(&pool, 36, Rng::seeded(1)).is_some());
|
|
}
|