//! Made-hand classes relative to the board. Kicker rule: top pair is "good" with a kicker of queen or better. use rechner::card::Card; use rechner::read::hand_read::read; use rechner::read::made::Made; use rechner::variant::{rules, Variant}; fn cs(text: &str) -> Vec { Card::parse_list(text).expect("cards") } fn made(variant: Variant, hole: &str, board: &str) -> Made { read(&rules(variant), &cs(hole), &cs(board)).expect("read").made } fn nl(hole: &str, board: &str, expected: Made) { assert_eq!(made(Variant::Nlhe, hole, board), expected, "{hole} on {board}"); } #[test] fn air_has_no_pair() { nl("Ah Kd", "9c 6s 2d", Made::Air); nl("Ah Kd", "9c 6s 2d 4h 3c", Made::Air); } #[test] fn board_only_pair_trips_and_two_pair() { nl("Ah Kd", "9c 9s 4d", Made::BoardOnly); nl("Ah Kd", "7c 7s 7d", Made::BoardOnly); nl("Ah 4d", "Kc Ks 7d 7s 3h", Made::BoardOnly); nl("Ah Kd", "7c 7d 7h 7s 2d", Made::BoardOnly); } #[test] fn board_only_straight_and_flush() { nl("2c 2d", "Tc Jd Qh Ks Ac", Made::BoardOnly); nl("2h 3d", "Ah Kh Qh 9h 4h", Made::BoardOnly); } #[test] fn hero_flush_card_above_the_board_flush_improves_it() { nl("Jh 3d", "Ah Kh Qh 9h 4h", Made::Flush); } #[test] fn pocket_pairs_against_the_board() { nl("Qc Qd", "Jh 8s 2c", Made::Overpair); nl("3c 3d", "Kh 9s 5c", Made::Underpair); nl("7c 7d", "Kh 9s 5c", Made::MiddlePair); } #[test] fn top_pair_kicker_split_at_queen() { nl("Ah Kd", "Ks 7c 2d", Made::TopPairGoodKicker); nl("Kh Qd", "Ks 7c 2d", Made::TopPairGoodKicker); nl("Kh Jd", "Ks 7c 2d", Made::TopPairWeakKicker); nl("Kh 4d", "Ks 7c 2d", Made::TopPairWeakKicker); } #[test] fn middle_and_bottom_pair_on_the_flop() { nl("9h 4d", "Ks 9c 2d", Made::MiddlePair); nl("Ah 2d", "Ks 9c 2c", Made::BottomPair); } #[test] fn middle_and_bottom_pair_on_four_cards() { nl("9h Ad", "Ks 9c 6d 4c", Made::MiddlePair); nl("6h Ad", "Ks 9c 6d 4c", Made::MiddlePair); nl("4h Ad", "Ks 9c 6d 4c", Made::BottomPair); } #[test] fn two_pair_must_use_a_hole_card() { nl("Ah 7d", "Ac 7s 2d", Made::TwoPair); nl("Qh 3d", "Qc 8d 8s", Made::TwoPair); nl("9h 9d", "Kc Ks 2d", Made::TwoPair); } #[test] fn set_versus_trips() { nl("7c 7d", "7h Ks 2d", Made::Set); nl("7c Ad", "7h 7s 2d", Made::Trips); } #[test] fn straight_flush_full_house_quads() { nl("9h 8d", "7c 6s 5d", Made::Straight); nl("Ah 2h", "Kh 7h 9c 4h", Made::Flush); nl("Kh 7d", "7c 7s Kd", Made::FullHouse); nl("Kh Kd", "Kc 7s 7d", Made::FullHouse); nl("7c 7d", "7h 7s 2d", Made::Quads); nl("7c Ad", "7h 7s 7d", Made::Quads); nl("9h 8h", "7h 6h 5h", Made::StraightFlush); } #[test] fn wheel_straight_in_full_deck() { nl("Ah 2d", "3c 4s 5d", Made::Straight); } #[test] fn classes_are_ordered_weakest_first() { assert!(Made::Air < Made::BoardOnly && Made::BoardOnly < Made::Underpair); assert!(Made::TopPairGoodKicker < Made::Overpair && Made::Overpair < Made::TwoPair); assert!(Made::Set < Made::Straight && Made::FullHouse < Made::StraightFlush); } // --- Omaha-5: exactly two hole cards and three board cards --- #[test] fn plo5_board_flush_is_not_playable_with_one_suited_hole_card() { let m = made(Variant::Plo5, "Ah 2c 3d 8s 9c", "Kh 7h 4h Qh 5d"); assert_ne!(m, Made::Flush); } #[test] fn plo5_flush_needs_two_suited_hole_cards() { assert_eq!(made(Variant::Plo5, "Ah 2h 3d 8s 9c", "Kh 7h 4h 6c 5d"), Made::Flush); } #[test] fn plo5_classifies_from_best_two_plus_three() { assert_eq!(made(Variant::Plo5, "Ah Ad 3d 8s 9c", "Ks 7h 4h"), Made::Overpair); assert_eq!(made(Variant::Plo5, "Kh Qd 3d 8s 9c", "Ks 7h 4h"), Made::TopPairGoodKicker); assert_eq!(made(Variant::Plo5, "7c 7d 3d 8s 9c", "7h Ks 2d"), Made::Set); assert_eq!(made(Variant::Plo5, "7c Ad 3d 8s 9c", "7h 7s 2d"), Made::Trips); } #[test] fn plo5_straight_uses_exactly_two_hole_cards() { assert_eq!(made(Variant::Plo5, "9h 8d 2d 3s Kc", "7c 6s 5d"), Made::Straight); } #[test] fn plo5_board_straight_alone_is_not_a_straight_for_hero() { let m = made(Variant::Plo5, "Ac Ad 2d 2s Kc", "5c 6s 7d 8h 9c"); assert_ne!(m, Made::Straight); } #[test] fn short_deck_pair_classes_follow_the_same_rules() { assert_eq!(made(Variant::ShortDeck, "Ah Kd", "Ks 7c 8d"), Made::TopPairGoodKicker); assert_eq!(made(Variant::ShortDeck, "Ah Ad", "Ks 7c 8d"), Made::Overpair); }