mod range_model_fixture; use rechner::exploit::range_guess::top_fraction; use rechner::exploit::range_spec::RangeSpec; use rechner::game::SeenAction::{AllIn, Call, Check, Raise}; use rechner::game::Spot; use range_model_fixture::*; fn near(a: f64, b: f64) -> bool { (a - b).abs() < 1e-9 } fn band(history: Vec, seat: u8) -> (f64, f64) { let s = spot(0, hand(history), None); let r = spec(&s, seat); assert!(well_formed(&r, 0), "{r:?}"); assert!(r.continues.is_empty()); (r.lo, r.hi) } #[test] fn opener_band_is_the_opening_chart_of_its_position() { let (lo, hi) = band(vec![pre(MIDDLE, Raise)], MIDDLE); assert!(near(lo, 0.0) && near(hi, 0.19), "{lo} {hi}"); let (lo, hi) = band(vec![pre(CUTOFF, Raise)], CUTOFF); assert!(near(lo, 0.0) && near(hi, 0.27), "{lo} {hi}"); let (_, hi) = band(vec![pre(BUTTON, Raise)], BUTTON); assert!(near(hi, 0.42)); let (_, hi) = band(vec![pre(SMALL_BLIND, Raise)], SMALL_BLIND); assert!(near(hi, 0.38)); } #[test] fn later_positions_open_wider() { let hi = |seat| band(vec![pre(seat, Raise)], seat).1; assert!(hi(MIDDLE) < hi(CUTOFF) && hi(CUTOFF) < hi(BUTTON)); } #[test] fn opener_with_an_unknown_position_is_charted_as_middle() { let mut s = spot(0, vec![pre(MIDDLE, Raise)], None); s.button_seat = None; let r = spec(&s, MIDDLE); assert!(near(r.hi, 0.19), "{r:?}"); } #[test] fn three_bettor_has_a_narrow_top_band() { let (lo, hi) = band(vec![pre(MIDDLE, Raise), pre(BUTTON, Raise)], BUTTON); assert!(near(lo, 0.0) && near(hi, 0.09), "{lo} {hi}"); let (_, open_hi) = band(vec![pre(BUTTON, Raise)], BUTTON); assert!(hi < open_hi / 3.0); } #[test] fn four_bettor_is_narrower_than_a_three_bettor() { let history = vec![pre(MIDDLE, Raise), pre(BUTTON, Raise), pre(MIDDLE, Raise)]; let (lo, hi) = band(history, MIDDLE); assert!(near(lo, 0.0) && near(hi, 0.03), "{lo} {hi}"); } #[test] fn cold_caller_is_condensed_without_the_very_top_and_the_bottom() { let (lo, hi) = band(vec![pre(MIDDLE, Raise), pre(BUTTON, Call)], BUTTON); assert!(near(lo, 0.045) && near(hi, 0.24), "{lo} {hi}"); let (_, open_hi) = band(vec![pre(BUTTON, Raise)], BUTTON); assert!(lo > 0.0 && hi < open_hi); } #[test] fn cold_caller_from_early_position_is_tighter_than_from_the_button() { let early = band(vec![pre(CUTOFF, Raise), pre(MIDDLE, Call)], MIDDLE); let late = band(vec![pre(MIDDLE, Raise), pre(BUTTON, Call)], BUTTON); assert!(early.1 < late.1); } #[test] fn opener_who_calls_a_three_bet_is_capped() { let (lo, hi) = band(vec![pre(MIDDLE, Raise), pre(BUTTON, Raise), pre(MIDDLE, Call)], MIDDLE); assert!(near(lo, 0.015) && near(hi, 0.05), "{lo} {hi}"); } #[test] fn caller_of_a_three_bet_is_narrower_than_a_caller_of_an_open() { let vs_open = band(vec![pre(MIDDLE, Raise), pre(BUTTON, Call)], BUTTON); let vs_three = band(vec![pre(MIDDLE, Raise), pre(CUTOFF, Raise), pre(BUTTON, Call)], BUTTON); assert!(vs_three.1 < vs_open.1); } #[test] fn limper_is_capped_in_the_middle() { let (lo, hi) = band(vec![pre(MIDDLE, Call)], MIDDLE); assert!(lo > 0.05 && hi > lo + 0.1, "{lo} {hi}"); let (_, open_hi) = band(vec![pre(MIDDLE, Raise)], MIDDLE); assert!(hi > open_hi, "a limping range is wider than the opening range"); } #[test] fn small_blind_completing_is_wide_without_the_raising_hands() { let (lo, hi) = band(vec![pre(MIDDLE, Call), pre(SMALL_BLIND, Call)], SMALL_BLIND); assert!(lo > 0.05 && hi >= 0.7, "{lo} {hi}"); } #[test] fn small_blind_that_only_posted_and_saw_no_raise_counts_as_completing() { let implied = band(vec![pre(MIDDLE, Call)], SMALL_BLIND); let explicit = band(vec![pre(MIDDLE, Call), pre(SMALL_BLIND, Call)], SMALL_BLIND); assert_eq!(implied, explicit); } #[test] fn big_blind_check_is_wide_minus_the_strongest_raising_hands() { let (lo, hi) = band(vec![pre(MIDDLE, Call), pre(BIG_BLIND, Check)], BIG_BLIND); assert!(lo > 0.05 && near(hi, 1.0), "{lo} {hi}"); } #[test] fn big_blind_with_no_action_after_limps_counts_as_checking() { let implied = band(vec![pre(MIDDLE, Call)], BIG_BLIND); let explicit = band(vec![pre(MIDDLE, Call), pre(BIG_BLIND, Check)], BIG_BLIND); assert_eq!(implied, explicit); } #[test] fn big_blind_that_stayed_in_against_a_raise_is_a_defender() { let (lo, hi) = band(vec![pre(BUTTON, Raise)], BIG_BLIND); assert!(near(lo, 0.04) && near(hi, 0.35), "{lo} {hi}"); let explicit = band(vec![pre(BUTTON, Raise), pre(BIG_BLIND, Call)], BIG_BLIND); assert_eq!((lo, hi), explicit); } #[test] fn preflop_all_in_is_a_narrow_top_band() { let (lo, hi) = band(vec![pre(BUTTON, AllIn)], BUTTON); assert!(near(lo, 0.0) && near(hi, 0.15), "{lo} {hi}"); let (lo, hi) = band(vec![pre(MIDDLE, Raise), pre(BUTTON, AllIn)], BUTTON); assert!(near(lo, 0.0) && near(hi, 0.06), "{lo} {hi}"); } #[test] fn no_records_for_this_villain_means_the_old_behaviour() { let s = spot(3, hand(vec![pre(MIDDLE, Raise)]), None); let v = s.villains.iter().find(|v| v.seat == BUTTON).unwrap(); assert_eq!(rechner::exploit::range_model::range_spec(&s, v), RangeSpec::top(top_fraction(&s, v))); } #[test] fn empty_history_is_exactly_the_old_behaviour_for_every_villain() { for board in [0usize, 3, 4, 5] { for p in [None, vpip(0.5), vpip(0.1), profile(Some(0.3), Some(0.2), Some(0.4))] { let s = spot(board, vec![], p); for v in &s.villains { assert_eq!( rechner::exploit::range_model::range_spec(&s, v), RangeSpec::top(top_fraction(&s, v)) ); } } } } #[test] fn only_postflop_records_use_the_plain_vpip_band() { let s = spot(3, vec![post(rechner::game::Street::Flop, BUTTON, Check)], None); let r = spec(&s, BUTTON); assert!(near(r.lo, 0.0) && near(r.hi, 0.30), "{r:?}"); let s = spot(3, vec![post(rechner::game::Street::Flop, BUTTON, Check)], vpip(0.5)); assert!(near(spec(&s, BUTTON).hi, 0.5)); } #[test] fn other_seats_actions_do_not_change_this_villains_band() { let a = band(vec![pre(MIDDLE, Raise), pre(BUTTON, Call)], BUTTON); let b: Spot = spot(0, hand(vec![pre(MIDDLE, Raise), pre(BUTTON, Call)]), None); assert_eq!(spec(&b, BUTTON).hi, a.1); }