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

101 lines
3.5 KiB
Rust

//! Every table size 2..=10, both seat numberings, button and hero at every seat.
use rechner::preflop::position::{position, Position};
/// Independent statement of the rule: offsets clockwise from the button.
fn expected(seats: u8, offset: u8) -> Position {
if seats == 2 {
return if offset == 0 { Position::HeadsUpButton } else { Position::BigBlind };
}
match offset {
0 => Position::Button,
1 => Position::SmallBlind,
2 => Position::BigBlind,
o if o == seats - 1 => Position::Cutoff,
o => {
// seats 3.. up to the cutoff: the first ceil(n/2) of the (n-4) are early
let early = (seats - 3) / 2;
if o - 3 < early {
Position::Early
} else {
Position::Middle
}
}
}
}
#[test]
fn every_seat_at_every_table_size_and_numbering() {
let mut checked = 0;
for seats in 2u8..=10 {
for base in 0u8..=1 {
for button in base..base + seats {
for hero in base..base + seats {
let offset = (hero + seats - button) % seats;
assert_eq!(
position(seats, hero, Some(button)),
expected(seats, offset),
"seats {seats} base {base} button {button} hero {hero}"
);
checked += 1;
}
}
}
}
assert_eq!(checked, 2 * (4 + 9 + 16 + 25 + 36 + 49 + 64 + 81 + 100));
}
#[test]
fn numbering_base_does_not_matter() {
for seats in 2u8..=10 {
for button in 0..seats {
for hero in 0..seats {
assert_eq!(
position(seats, hero, Some(button)),
position(seats, hero + 1, Some(button + 1)),
"seats {seats} button {button} hero {hero}"
);
}
}
}
}
#[test]
fn heads_up_button_is_the_small_blind_and_the_other_the_big_blind() {
for base in 0u8..=1 {
for button in base..base + 2 {
let other = if button == base { base + 1 } else { base };
assert_eq!(position(2, button, Some(button)), Position::HeadsUpButton);
assert_eq!(position(2, other, Some(button)), Position::BigBlind);
}
}
}
#[test]
fn cutoff_is_the_seat_before_the_button_and_utg_the_first_after_the_big_blind() {
for seats in 5u8..=10 {
for button in 0..seats {
let cutoff = (button + seats - 1) % seats;
let utg = (button + 3) % seats;
assert_eq!(position(seats, cutoff, Some(button)), Position::Cutoff);
assert_eq!(position(seats, utg, Some(button)), Position::Early, "seats {seats}");
}
}
}
#[test]
fn early_middle_split_counts_for_every_table_size() {
// (seats, early, middle): the n-4 seats between big blind and cutoff, earlier half early.
let table = [(4u8, 0usize, 0usize), (5, 1, 0), (6, 1, 1), (7, 2, 1), (8, 2, 2), (9, 3, 2), (10, 3, 3)];
for (seats, early, middle) in table {
let positions: Vec<Position> = (0..seats).map(|h| position(seats, h, Some(0))).collect();
let count = |p: Position| positions.iter().filter(|x| **x == p).count();
assert_eq!(count(Position::Early), early, "seats {seats}");
assert_eq!(count(Position::Middle), middle, "seats {seats}");
assert_eq!(count(Position::Button), 1);
assert_eq!(count(Position::SmallBlind), 1);
assert_eq!(count(Position::BigBlind), 1);
assert_eq!(count(Position::Cutoff), 1);
}
}