110 lines
3.8 KiB
Rust
110 lines
3.8 KiB
Rust
mod spot_fixture;
|
|
|
|
use pokerfreak::game::{ActionKind, Choice, Decision, Spot};
|
|
use pokerfreak::guard::enforce::enforce;
|
|
use pokerfreak::variant::Variant;
|
|
use spot_fixture::*;
|
|
|
|
fn choose(spot: &Spot, choice: Choice) -> Choice {
|
|
enforce(spot, Decision::new(choice, 0.9, "test")).choice
|
|
}
|
|
|
|
#[test]
|
|
fn legal_choices_pass_through() {
|
|
let spot = flop();
|
|
assert_eq!(choose(&spot, Choice::Fold), Choice::Fold);
|
|
assert_eq!(choose(&spot, Choice::Call), Choice::Call);
|
|
assert_eq!(choose(&spot, Choice::Raise { to: 1.0 }), Choice::Raise { to: 1.0 });
|
|
}
|
|
|
|
#[test]
|
|
fn abstain_stays_abstain() {
|
|
let out = enforce(&flop(), Decision::abstain("unsure"));
|
|
assert_eq!(out.choice, Choice::Abstain);
|
|
assert_eq!(out.reason, "unsure");
|
|
}
|
|
|
|
#[test]
|
|
fn illegal_kinds_become_abstain_with_a_reason() {
|
|
let spot = flop(); // no CHECK
|
|
let out = enforce(&spot, Decision::new(Choice::Check, 0.9, "x"));
|
|
assert_eq!(out.choice, Choice::Abstain);
|
|
assert!(out.reason.contains("CHECK"), "{}", out.reason);
|
|
assert_eq!(out.confidence.value(), 0.0);
|
|
|
|
let no_raise = Spot { legal: vec![ActionKind::Fold, ActionKind::Call], ..flop() };
|
|
assert_eq!(choose(&no_raise, Choice::Raise { to: 1.0 }), Choice::Abstain);
|
|
}
|
|
|
|
#[test]
|
|
fn fold_is_turned_into_check_when_check_is_legal() {
|
|
let spot = Spot {
|
|
to_call: 0.0,
|
|
legal: vec![ActionKind::Fold, ActionKind::Check, ActionKind::Raise],
|
|
..flop()
|
|
};
|
|
assert_eq!(choose(&spot, Choice::Fold), Choice::Check);
|
|
}
|
|
|
|
#[test]
|
|
fn raise_is_snapped_to_allowed_sizes_exactly() {
|
|
let spot = Spot { allowed_sizes: Some(vec![0.5, 1.15, 4.6]), ..flop() };
|
|
assert_eq!(choose(&spot, Choice::Raise { to: 1.15 }), Choice::Raise { to: 1.15 });
|
|
assert_eq!(choose(&spot, Choice::Raise { to: 4.6 }), Choice::Raise { to: 1.15 });
|
|
assert_eq!(choose(&spot, Choice::Raise { to: 1.0 }), Choice::Raise { to: 1.15 });
|
|
assert_eq!(choose(&spot, Choice::Raise { to: 0.1 }), Choice::Raise { to: 0.5 });
|
|
}
|
|
|
|
#[test]
|
|
fn raise_with_no_affordable_allowed_size_abstains() {
|
|
let spot = Spot { allowed_sizes: Some(vec![4.6, 5.0]), ..flop() };
|
|
assert_eq!(choose(&spot, Choice::Raise { to: 4.6 }), Choice::Abstain);
|
|
}
|
|
|
|
#[test]
|
|
fn free_raise_is_clamped_to_bounds_and_stack() {
|
|
let spot = flop();
|
|
assert_eq!(choose(&spot, Choice::Raise { to: 100.0 }), Choice::Raise { to: 2.4 });
|
|
assert_eq!(choose(&spot, Choice::Raise { to: 0.01 }), Choice::Raise { to: 0.5 });
|
|
let capped = Spot { max_raise_to: Some(1.0), ..flop() };
|
|
assert_eq!(choose(&capped, Choice::Raise { to: 2.0 }), Choice::Raise { to: 1.0 });
|
|
}
|
|
|
|
#[test]
|
|
fn raise_with_non_finite_size_or_no_stack_abstains() {
|
|
assert_eq!(choose(&flop(), Choice::Raise { to: f64::NAN }), Choice::Abstain);
|
|
let broke = Spot { hero_stack: 0.0, ..flop() };
|
|
assert_eq!(choose(&broke, Choice::Raise { to: 1.0 }), Choice::Abstain);
|
|
}
|
|
|
|
#[test]
|
|
fn binary_variants_allow_only_give_up_or_all_in() {
|
|
let aof = with_variant(flop(), Variant::Aof);
|
|
assert_eq!(choose(&aof, Choice::Fold), Choice::Fold);
|
|
assert_eq!(choose(&aof, Choice::Raise { to: 1.0 }), Choice::Raise { to: 2.4 });
|
|
// a partial call is not an all-in
|
|
assert_eq!(choose(&aof, Choice::Call), Choice::Abstain);
|
|
}
|
|
|
|
#[test]
|
|
fn binary_call_that_covers_the_stack_is_an_all_in() {
|
|
let aof = with_variant(Spot { to_call: 2.4, ..flop() }, Variant::Aof);
|
|
assert_eq!(choose(&aof, Choice::Call), Choice::Call);
|
|
}
|
|
|
|
#[test]
|
|
fn binary_check_is_allowed() {
|
|
let aof = with_variant(
|
|
Spot { to_call: 0.0, legal: vec![ActionKind::Check, ActionKind::Raise], ..flop() },
|
|
Variant::Aof,
|
|
);
|
|
assert_eq!(choose(&aof, Choice::Check), Choice::Check);
|
|
}
|
|
|
|
#[test]
|
|
fn repairs_are_mentioned_in_the_reason() {
|
|
let out = enforce(&flop(), Decision::new(Choice::Raise { to: 100.0 }, 0.8, "big"));
|
|
assert!(out.reason.starts_with("big"), "{}", out.reason);
|
|
assert!(out.reason.len() > "big".len());
|
|
}
|