use rechner::preflop::position::{position, Position}; #[test] fn six_max_zero_based() { let at = |hero| position(6, hero, Some(3)); assert_eq!(at(3), Position::Button); assert_eq!(at(4), Position::SmallBlind); assert_eq!(at(5), Position::BigBlind); assert_eq!(at(0), Position::Early); assert_eq!(at(1), Position::Middle); assert_eq!(at(2), Position::Cutoff); } #[test] fn six_max_one_based() { let at = |hero| position(6, hero, Some(6)); assert_eq!(at(6), Position::Button); assert_eq!(at(1), Position::SmallBlind); assert_eq!(at(2), Position::BigBlind); assert_eq!(at(3), Position::Early); assert_eq!(at(4), Position::Middle); assert_eq!(at(5), Position::Cutoff); } #[test] fn heads_up_button_is_small_blind() { assert_eq!(position(2, 0, Some(0)), Position::HeadsUpButton); assert_eq!(position(2, 1, Some(0)), Position::BigBlind); assert_eq!(position(2, 2, Some(1)), Position::BigBlind); assert_eq!(position(2, 1, Some(1)), Position::HeadsUpButton); } #[test] fn three_and_four_handed() { assert_eq!(position(3, 0, Some(0)), Position::Button); assert_eq!(position(3, 1, Some(0)), Position::SmallBlind); assert_eq!(position(3, 2, Some(0)), Position::BigBlind); assert_eq!(position(4, 0, Some(1)), Position::Cutoff); assert_eq!(position(4, 1, Some(1)), Position::Button); } #[test] fn five_handed_has_one_early_seat() { assert_eq!(position(5, 4, Some(1)), Position::Early); assert_eq!(position(5, 0, Some(1)), Position::Cutoff); } #[test] fn nine_and_ten_handed_split_early_and_middle() { let nine: Vec = (3..9).map(|o| position(9, o, Some(0))).collect(); assert_eq!( nine, vec![ Position::Early, Position::Early, Position::Early, Position::Middle, Position::Middle, Position::Cutoff ] ); let ten: Vec = (3..10).map(|o| position(10, o, Some(0))).collect(); assert_eq!(ten.iter().filter(|p| **p == Position::Early).count(), 3); assert_eq!(ten.iter().filter(|p| **p == Position::Middle).count(), 3); assert_eq!(ten[6], Position::Cutoff); } #[test] fn unknown_when_button_missing_or_input_absurd() { assert_eq!(position(6, 2, None), Position::Unknown); assert_eq!(position(1, 0, Some(0)), Position::Unknown); assert_eq!(position(0, 0, Some(0)), Position::Unknown); assert_eq!(position(11, 0, Some(0)), Position::Unknown); assert_eq!(position(6, 9, Some(0)), Position::Unknown); assert_eq!(position(6, 0, Some(9)), Position::Unknown); } #[test] fn labels_are_short_and_distinct() { let all = [ Position::Early, Position::Middle, Position::Cutoff, Position::Button, Position::SmallBlind, Position::BigBlind, Position::HeadsUpButton, Position::Unknown, ]; let mut labels: Vec<&str> = all.iter().map(|p| p.label()).collect(); labels.sort_unstable(); labels.dedup(); assert_eq!(labels.len(), all.len()); assert_eq!(Position::Button.label(), "BTN"); }