Die Welt nannte 'pokerfreak' nur noch in zwei Harness-Zeilen - der Rest waren veraltete Rust-Pruefungen im Pruefordner, die der Aufbau nie auffrischte.
112 lines
3.3 KiB
Rust
112 lines
3.3 KiB
Rust
use rechner::card::Card;
|
|
use rechner::preflop::hand_percentile::percentile;
|
|
use rechner::preflop::holdem_ranking::RANKING;
|
|
use rechner::variant::Variant;
|
|
|
|
fn hand(text: &str) -> Vec<Card> {
|
|
Card::parse_list(text).expect("valid cards")
|
|
}
|
|
|
|
fn pct(text: &str) -> f64 {
|
|
percentile(Variant::Nlhe, &hand(text))
|
|
}
|
|
|
|
fn all_combos() -> Vec<Vec<Card>> {
|
|
(0..52u8)
|
|
.flat_map(|i| (i + 1..52u8).map(move |j| (i, j)))
|
|
.filter_map(|(i, j)| Some(vec![Card::from_index(i)?, Card::from_index(j)?]))
|
|
.collect()
|
|
}
|
|
|
|
#[test]
|
|
fn ranking_table_has_169_distinct_classes() {
|
|
assert_eq!(RANKING.len(), 169);
|
|
let mut sorted: Vec<&str> = RANKING.to_vec();
|
|
sorted.sort_unstable();
|
|
sorted.dedup();
|
|
assert_eq!(sorted.len(), 169);
|
|
}
|
|
|
|
#[test]
|
|
fn aces_are_best_and_seven_deuce_is_near_worst() {
|
|
assert!(pct("Ah Ad") < 0.01);
|
|
assert!(pct("7c 2d") > 0.93);
|
|
assert!(pct("3c 2d") > pct("7c 2d"));
|
|
}
|
|
|
|
#[test]
|
|
fn pairs_descend() {
|
|
assert!(pct("Ah Ad") < pct("Kh Kd"));
|
|
assert!(pct("Kh Kd") < pct("Qh Qd"));
|
|
assert!(pct("Qh Qd") < pct("2h 2d"));
|
|
}
|
|
|
|
#[test]
|
|
fn well_known_orderings_hold() {
|
|
assert!(pct("Ah Kh") < pct("Ah Kd"));
|
|
assert!(pct("Ah Kh") < pct("Ah Qh"));
|
|
assert!(pct("Ah Kd") < pct("Ah Qd"));
|
|
assert!(pct("Kh Kd") < pct("Ah Kh"));
|
|
assert!(pct("Jh Th") < pct("Jh 2h"));
|
|
assert!(pct("2h 2d") < pct("7c 3d"));
|
|
}
|
|
|
|
#[test]
|
|
fn suited_beats_offsuit_for_every_unpaired_class() {
|
|
let ranks = "23456789TJQKA";
|
|
for (i, hi) in ranks.chars().enumerate().skip(1) {
|
|
for lo in ranks.chars().take(i) {
|
|
let suited = pct(&format!("{hi}h {lo}h"));
|
|
let offsuit = pct(&format!("{hi}h {lo}d"));
|
|
assert!(suited < offsuit, "{hi}{lo}s vs {hi}{lo}o");
|
|
}
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn every_combo_maps_into_unit_interval_and_averages_one_half() {
|
|
let combos = all_combos();
|
|
assert_eq!(combos.len(), 1326);
|
|
let values: Vec<f64> = combos
|
|
.iter()
|
|
.map(|c| percentile(Variant::Nlhe, c))
|
|
.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.001, "mean {mean}");
|
|
}
|
|
|
|
#[test]
|
|
fn suit_and_card_order_do_not_matter() {
|
|
assert_eq!(pct("Ah 5h"), pct("5s As"));
|
|
assert_eq!(pct("Ah 5d"), pct("5c Ad"));
|
|
assert_ne!(pct("Ah 5h"), pct("Ah 5d"));
|
|
}
|
|
|
|
#[test]
|
|
fn hold_em_family_shares_one_table() {
|
|
let h = hand("Qh Jd");
|
|
let base = percentile(Variant::Nlhe, &h);
|
|
assert_eq!(percentile(Variant::KPoker, &h), base);
|
|
assert_eq!(percentile(Variant::Aof, &h), base);
|
|
}
|
|
|
|
#[test]
|
|
fn invalid_hands_are_worst_not_panics() {
|
|
assert_eq!(percentile(Variant::Nlhe, &[]), 1.0);
|
|
assert_eq!(percentile(Variant::Nlhe, &hand("Ah")), 1.0);
|
|
assert_eq!(percentile(Variant::Nlhe, &hand("Ah Kd Qc")), 1.0);
|
|
assert_eq!(percentile(Variant::Nlhe, &hand("Ah Ah")), 1.0);
|
|
assert_eq!(percentile(Variant::Plo5, &hand("Ah Kd")), 1.0);
|
|
assert_eq!(percentile(Variant::Plo5, &hand("Ah Kd Qc Js Th 9h")), 1.0);
|
|
assert_eq!(percentile(Variant::Plo5, &hand("Ah Ah Qc Js Th")), 1.0);
|
|
}
|
|
|
|
#[test]
|
|
fn many_calls_are_cheap_and_deterministic() {
|
|
let h = hand("9h 8h");
|
|
let first = percentile(Variant::Nlhe, &h);
|
|
let sum: f64 = (0..300_000).map(|_| percentile(Variant::Nlhe, &h)).sum();
|
|
assert!((sum / 300_000.0 - first).abs() < 1e-9);
|
|
}
|