Files
pokerfreak/tests/engine_choose_postflop.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

141 lines
5.1 KiB
Rust

mod spot_fixture;
use rechner::engine::postflop::choose_postflop;
use rechner::exploit::thresholds::Thresholds;
use rechner::game::{ActionKind, Choice, Spot};
use rechner::sizing::candidates::candidates;
use spot_fixture::*;
const BASE: Thresholds = Thresholds::BASE;
// round_flop: pot 10, 5 to call -> break-even exactly 1/3.
#[test]
fn clear_call_when_equity_beats_the_price() {
let d = choose_postflop(&round_flop(), &estimate(0.45, 0.005), &BASE, &neutral_read());
assert_eq!(d.choice, Choice::Call);
assert!(d.reason.contains("equity 0.45"), "{}", d.reason);
assert!(d.reason.contains("break-even 0.33"), "{}", d.reason);
assert!(d.reason.contains("EV"), "{}", d.reason);
}
#[test]
fn clear_fold_when_equity_is_far_below_the_price() {
let d = choose_postflop(&round_flop(), &estimate(0.15, 0.005), &BASE, &neutral_read());
assert_eq!(d.choice, Choice::Fold);
}
#[test]
fn abstains_near_the_breakpoint() {
let d = choose_postflop(&round_flop(), &estimate(0.34, 0.005), &BASE, &neutral_read());
assert_eq!(d.choice, Choice::Abstain);
assert!(d.confidence.value() > 0.0 && d.confidence.value() <= 0.3, "{d:?}");
}
#[test]
fn abstain_band_widens_with_the_standard_error() {
// call breakpoint = 1/3 + call_margin 0.02 = 0.3533
let noisy = choose_postflop(&round_flop(), &estimate(0.38, 0.02), &BASE, &neutral_read());
assert_eq!(noisy.choice, Choice::Abstain);
let tight = choose_postflop(&round_flop(), &estimate(0.38, 0.001), &BASE, &neutral_read());
assert_eq!(tight.choice, Choice::Call);
}
#[test]
fn call_margin_is_required_above_break_even() {
let thresholds = Thresholds { abstain_band: 0.0, call_margin: 0.05, ..BASE };
// 0.36 is above break-even (0.333) but below break-even + margin (0.383)
let d = choose_postflop(&round_flop(), &estimate(0.36, 0.0), &thresholds, &neutral_read());
assert_eq!(d.choice, Choice::Fold);
}
#[test]
fn value_raise_when_equity_is_high() {
let spot = round_flop();
let d = choose_postflop(&spot, &estimate(0.80, 0.005), &BASE, &neutral_read());
match d.choice {
Choice::Raise { to } => assert!(candidates(&spot).contains(&to), "{to}"),
other => panic!("expected a raise, got {other:?}"),
}
}
#[test]
fn no_raise_below_the_value_threshold() {
let d = choose_postflop(&round_flop(), &estimate(0.50, 0.005), &BASE, &neutral_read());
assert_eq!(d.choice, Choice::Call);
}
#[test]
fn value_threshold_comes_from_the_thresholds() {
let eager = Thresholds { value_raise: 0.45, ..BASE };
let d = choose_postflop(&round_flop(), &estimate(0.50, 0.005), &eager, &neutral_read());
assert!(matches!(d.choice, Choice::Raise { .. }), "{d:?}");
}
#[test]
fn checks_when_free_and_weak() {
let spot = Spot { to_call: 0.0, legal: vec![ActionKind::Check, ActionKind::Raise], ..round_flop() };
let d = choose_postflop(&spot, &estimate(0.30, 0.005), &BASE, &neutral_read());
assert_eq!(d.choice, Choice::Check);
}
#[test]
fn raises_when_free_and_strong() {
let spot = Spot { to_call: 0.0, legal: vec![ActionKind::Check, ActionKind::Raise], ..round_flop() };
let d = choose_postflop(&spot, &estimate(0.90, 0.005), &BASE, &neutral_read());
assert!(matches!(d.choice, Choice::Raise { .. }), "{d:?}");
}
#[test]
fn never_folds_when_check_is_legal() {
let spot = Spot {
to_call: 0.0,
legal: vec![ActionKind::Fold, ActionKind::Check],
..round_flop()
};
for share in [0.0, 0.05, 0.3, 0.9] {
let d = choose_postflop(&spot, &estimate(share, 0.005), &BASE, &neutral_read());
assert_eq!(d.choice, Choice::Check, "share {share}");
}
}
#[test]
fn call_when_fold_and_check_are_not_available() {
let spot = Spot { legal: vec![ActionKind::Call], ..round_flop() };
let d = choose_postflop(&spot, &estimate(0.10, 0.005), &BASE, &neutral_read());
assert_eq!(d.choice, Choice::Call);
}
#[test]
fn raises_come_from_allowed_sizes_verbatim() {
let spot = Spot { allowed_sizes: Some(vec![20.0, 40.0]), ..round_flop() };
let d = choose_postflop(&spot, &estimate(0.85, 0.005), &BASE, &neutral_read());
match d.choice {
Choice::Raise { to } => assert!(to == 20.0 || to == 40.0, "{to}"),
other => panic!("expected a raise, got {other:?}"),
}
}
#[test]
fn raise_without_candidates_falls_back_to_the_passive_line() {
let spot = Spot { allowed_sizes: Some(vec![500.0]), ..round_flop() };
let d = choose_postflop(&spot, &estimate(0.85, 0.005), &BASE, &neutral_read());
assert_eq!(d.choice, Choice::Call);
}
#[test]
fn non_finite_equity_abstains() {
let d = choose_postflop(&round_flop(), &estimate(f64::NAN, 0.0), &BASE, &neutral_read());
assert_eq!(d.choice, Choice::Abstain);
}
#[test]
fn confidence_grows_with_distance_from_the_breakpoint() {
let near = choose_postflop(&round_flop(), &estimate(0.40, 0.001), &BASE, &neutral_read());
let far = choose_postflop(&round_flop(), &estimate(0.55, 0.001), &BASE, &neutral_read());
assert_eq!(near.choice, Choice::Call);
assert_eq!(far.choice, Choice::Call);
assert!(far.confidence > near.confidence);
assert!(far.confidence.value() <= 1.0 && near.confidence.value() > 0.0);
}