Files
pokerfreak/tests/preflop_plo5.rs
T
mmintel 04d5251acf Welt ohne fremden Namen: Pruefordner vollstaendig mitkopieren, Engine nur im eigenen Baum
Die Welt nannte 'pokerfreak' nur noch in zwei Harness-Zeilen - der Rest waren veraltete
Rust-Pruefungen im Pruefordner, die der Aufbau nie auffrischte.
2026-11-01 23:37:11 +01:00

107 lines
3.2 KiB
Rust

use rechner::card::Card;
use rechner::preflop::hand_percentile::percentile;
use rechner::preflop::plo5_score::score;
use rechner::variant::Variant;
fn hand(text: &str) -> Vec<Card> {
Card::parse_list(text).expect("valid cards")
}
fn pct(text: &str) -> f64 {
percentile(Variant::Plo5, &hand(text))
}
/// Deterministic pseudo-random 5-card hands (LCG), independent of the crate's Rng.
fn sample_hands(count: usize) -> Vec<Vec<Card>> {
let mut state: u64 = 0x2545_F491_4F6C_DD1D;
let mut next = move || {
state = state
.wrapping_mul(6364136223846793005)
.wrapping_add(1442695040888963407);
(state >> 33) as u8
};
(0..count)
.map(|_| {
let mut picked: Vec<u8> = Vec::new();
while picked.len() < 5 {
let c = next() % 52;
if !picked.contains(&c) {
picked.push(c);
}
}
picked.into_iter().filter_map(Card::from_index).collect()
})
.collect()
}
#[test]
fn double_suited_big_pairs_beat_rainbow_junk() {
let strong = pct("Ah Ad Kh Kd Jc");
let junk = pct("2c 7d 4h 9s 3c");
assert!(strong < 0.05, "strong {strong}");
assert!(junk > 0.8, "junk {junk}");
assert!(strong < junk);
}
#[test]
fn double_suited_beats_single_suited_with_same_ranks() {
assert!(pct("Ah Kh Qd Jd Tc") < pct("Ah Kd Qc Js Ts"));
}
#[test]
fn trips_and_quads_are_penalised() {
assert!(pct("Ah Ad Kh Kd Qc") < pct("Ah Ad Ac Kh Qd"));
assert!(pct("Ah Ad Ac Kh Qd") < pct("Ah Ad Ac As Kd"));
}
#[test]
fn connected_rundowns_beat_scattered_cards_of_same_top() {
assert!(pct("Jh Td 9c 8s 2h") < pct("Jh 8d 5c 3s 2h"));
}
#[test]
fn bigger_pairs_beat_smaller_pairs() {
assert!(pct("Ah Ad Kc Qs Jh") < pct("7h 7d Kc Qs Jh"));
}
#[test]
fn suit_permutation_does_not_change_the_value() {
assert_eq!(pct("Ah Ad Kh Kd Jc"), pct("As Ac Ks Kc Jd"));
assert_eq!(pct("Ah Ad Kh Kd Jc"), pct("Jc Kd Kh Ad Ah"));
}
#[test]
fn percentile_is_monotone_in_score() {
let hands = sample_hands(1500);
for a in &hands {
for b in hands.iter().take(40) {
let (sa, sb) = (score(a).expect("score"), score(b).expect("score"));
let (pa, pb) = (percentile(Variant::Plo5, a), percentile(Variant::Plo5, b));
if sa > sb {
assert!(pa <= pb);
}
if sa == sb {
assert_eq!(pa, pb);
}
}
}
}
#[test]
fn random_hands_spread_evenly_over_the_unit_interval() {
let hands = sample_hands(20_000);
let values: Vec<f64> = hands.iter().map(|h| percentile(Variant::Plo5, h)).collect();
assert!(values.iter().all(|p| (0.0..=1.0).contains(p)));
let mean = values.iter().sum::<f64>() / values.len() as f64;
assert!((mean - 0.5).abs() < 0.02, "mean {mean}");
let top_decile = values.iter().filter(|p| **p < 0.1).count() as f64 / values.len() as f64;
assert!((top_decile - 0.1).abs() < 0.03, "top decile {top_decile}");
}
#[test]
fn score_rejects_wrong_card_counts() {
assert_eq!(score(&hand("Ah Kd")), None);
assert_eq!(score(&hand("Ah Kd Qc Js Th 9h")), None);
assert_eq!(score(&hand("Ah Ah Qc Js Th")), None);
}