//! Spezifikation der Rake-Rechnung. Die Zahlen stammen aus Händen des Tisches 1000/2000 //! (`game.winnerInfo`, `potAmount` gegen `potAmountAfterRake`); die Hand steht am Fall. use rechner::rake::{split_over_pots, uncalled, ChartRake, HandEnd, RakeRule, MEASURED_ANTE_BB}; /// Der gemessene Tisch in seiner eigenen Währung. const TABLE: RakeRule = RakeRule { percent: 5.0, cap: 2000.0, cap_more_than_three: 2000.0 }; fn near(a: f64, b: f64) { assert!((a - b).abs() < 1e-9, "{a} != {b}"); } // -- Eine Hand ------------------------------------------------------------------------------ #[test] fn a_pot_under_the_cap_pays_five_percent_antes_included() { // Hand 166457200019, Topf 4640 samt Antes: 232 Rake. near(TABLE.of_hand(4640.0, 2, HandEnd::FlopDealt), 232.0); } #[test] fn the_cap_stops_the_rake() { // Hand 166408600402: Topf 191680, 2000 Rake. near(TABLE.of_hand(191_680.0, 2, HandEnd::FlopDealt), 2000.0); } #[test] fn the_cap_starts_exactly_at_twenty_big_blinds() { near(TABLE.of_hand(39_999.0, 2, HandEnd::FlopDealt), 1999.95); near(TABLE.of_hand(40_000.0, 2, HandEnd::FlopDealt), 2000.0); near(TABLE.of_hand(40_001.0, 2, HandEnd::FlopDealt), 2000.0); } #[test] fn heads_up_pays_the_same_as_three_players() { assert_eq!(TABLE.of_hand(10_000.0, 2, HandEnd::FlopDealt), TABLE.of_hand(10_000.0, 3, HandEnd::FlopDealt)); } #[test] fn a_hand_that_ends_before_the_flop_pays_nothing() { assert_eq!(TABLE.of_hand(21_600.0, 2, HandEnd::NoFlop), 0.0); assert_eq!(TABLE.of_hand(1_000_000.0, 6, HandEnd::NoFlop), 0.0); } #[test] fn more_than_three_players_use_their_own_cap_and_three_do_not() { let rule = RakeRule { percent: 5.0, cap: 100.0, cap_more_than_three: 40.0 }; near(rule.of_hand(10_000.0, 3, HandEnd::FlopDealt), 100.0); near(rule.of_hand(10_000.0, 4, HandEnd::FlopDealt), 40.0); near(rule.of_hand(500.0, 4, HandEnd::FlopDealt), 25.0); } #[test] fn an_empty_or_broken_pot_pays_nothing() { assert_eq!(TABLE.of_hand(0.0, 2, HandEnd::FlopDealt), 0.0); assert_eq!(TABLE.of_hand(-5.0, 2, HandEnd::FlopDealt), 0.0); assert_eq!(TABLE.of_hand(f64::NAN, 2, HandEnd::FlopDealt), 0.0); } #[test] fn the_measured_table_in_big_blinds_is_the_table_above() { let bb = 2000.0; for pot in [4640.0, 39_999.0, 191_680.0] { near(RakeRule::MEASURED_BB.of_hand(pot / bb, 2, HandEnd::FlopDealt) * bb, TABLE.of_hand(pot, 2, HandEnd::FlopDealt)); } near(MEASURED_ANTE_BB, 320.0 / bb); } // -- Side Pots ------------------------------------------------------------------------------ #[test] fn the_cap_holds_per_hand_and_is_shared_in_proportion_to_the_pots() { // Hand 166408600403: Töpfe 609640 und 574480, abgezogen 1029,69 und 970,31. let pots = [609_640.0, 574_480.0]; let total = TABLE.of_hand(pots.iter().sum(), 2, HandEnd::FlopDealt); let parts = split_over_pots(total, &pots); near(total, 2000.0); assert!((parts[0] - 1029.69).abs() < 0.01, "{}", parts[0]); assert!((parts[1] - 970.31).abs() < 0.01, "{}", parts[1]); near(parts.iter().sum(), 2000.0); } #[test] fn nothing_to_split_stays_empty_or_zero() { assert!(split_over_pots(100.0, &[]).is_empty()); assert_eq!(split_over_pots(100.0, &[0.0, 0.0]), vec![0.0, 0.0]); assert_eq!(split_over_pots(100.0, &[50.0]), vec![100.0]); } #[test] fn only_the_part_nobody_called_comes_back() { assert_eq!(uncalled(&[10.0, 4.0, 4.0]), Some((0, 6.0))); assert_eq!(uncalled(&[1.0, 8.0, 3.0]), Some((1, 5.0))); assert_eq!(uncalled(&[5.0, 5.0]).map(|u| u.1), Some(0.0)); assert_eq!(uncalled(&[5.0]), None); } // -- Rake in den Chart-Spielen -------------------------------------------------------------- #[test] fn no_rake_is_no_rake() { assert_eq!(ChartRake::None.postflop(5.5), 0.0); assert_eq!(ChartRake::None.all_in(200.0), 0.0); } #[test] fn an_all_in_pays_the_exact_rule_on_the_pot() { near(ChartRake::Measured.all_in(200.0), 1.0); near(ChartRake::Measured.all_in(5.96), 0.05 * 5.96); } #[test] fn a_pot_with_chips_behind_pays_what_such_pots_paid_at_the_table() { // Mittlerer Rake je Flop-Topf (Topf samt Antes, aus 728 Händen; Kopf von `rake`). near(ChartRake::Measured.postflop(4.0), 0.489); near(ChartRake::Measured.postflop(6.46), 0.720); near(ChartRake::Measured.postflop(10.0), 0.850); near(ChartRake::Measured.postflop(19.46), 0.906); near(ChartRake::Measured.postflop(60.0), 0.950); } #[test] fn a_flop_pot_on_a_bucket_bound_belongs_to_the_next_bucket() { near(ChartRake::Measured.postflop(6.0), 0.720); } #[test] fn the_postflop_rake_never_shrinks_with_the_pot_and_never_passes_the_cap() { let mut last = 0.0; for k in 0..400 { let r = ChartRake::Measured.postflop(k as f64 * 0.5); assert!(r >= last && r <= 1.0, "{k}: {r}"); last = r; } }