212 lines
6.0 KiB
Rust
212 lines
6.0 KiB
Rust
use kings_eunuch::hand_building::{find_pair, find_two_pair, find_trips, find_quads, find_full_house, Card};
|
|
|
|
// ===== PAIR TESTS =====
|
|
|
|
#[test]
|
|
fn test_pair_basic() {
|
|
let pair_aces: Vec<Card> = ["Ah", "As", "Kd", "Qc", "Jh"]
|
|
.iter()
|
|
.map(|s| Card::str_to_card(s).unwrap())
|
|
.collect();
|
|
|
|
let cards = find_pair(&pair_aces).expect("Should find pair");
|
|
assert_eq!(cards.len(), 5, "Pair hand should have 5 cards (2 pair + 3 kickers)");
|
|
}
|
|
|
|
#[test]
|
|
fn test_pair_from_7_cards() {
|
|
let pair_7cards: Vec<Card> = ["Kh", "Ks", "Ad", "Qc", "Jh", "Ts", "9d"]
|
|
.iter()
|
|
.map(|s| Card::str_to_card(s).unwrap())
|
|
.collect();
|
|
|
|
let cards = find_pair(&pair_7cards).expect("Should find pair from 7 cards");
|
|
assert_eq!(cards.len(), 5);
|
|
}
|
|
|
|
#[test]
|
|
fn test_no_pair_all_different() {
|
|
let no_pair: Vec<Card> = ["Ah", "Ks", "Qd", "Jc", "9h"]
|
|
.iter()
|
|
.map(|s| Card::str_to_card(s).unwrap())
|
|
.collect();
|
|
|
|
assert!(find_pair(&no_pair).is_none(), "All different ranks - no pair");
|
|
}
|
|
|
|
#[test]
|
|
fn test_two_pair_not_detected_as_pair() {
|
|
let two_pairs: Vec<Card> = ["8h", "8d", "7s", "7c", "Kh"]
|
|
.iter()
|
|
.map(|s| Card::str_to_card(s).unwrap())
|
|
.collect();
|
|
|
|
assert!(find_pair(&two_pairs).is_none(), "Two pair should not be detected as single pair");
|
|
}
|
|
|
|
#[test]
|
|
fn test_trips_not_detected_as_pair() {
|
|
let trips: Vec<Card> = ["7h", "7d", "7s", "Kc", "Qh"]
|
|
.iter()
|
|
.map(|s| Card::str_to_card(s).unwrap())
|
|
.collect();
|
|
|
|
assert!(find_pair(&trips).is_none(), "Trips should not be detected as pair");
|
|
}
|
|
|
|
// ===== TWO PAIR TESTS =====
|
|
|
|
#[test]
|
|
fn test_two_pair_basic() {
|
|
let two_pair_basic: Vec<Card> = ["Kh", "Ks", "8d", "8c", "Ah"]
|
|
.iter()
|
|
.map(|s| Card::str_to_card(s).unwrap())
|
|
.collect();
|
|
|
|
let cards = find_two_pair(&two_pair_basic).expect("Should find two pair");
|
|
assert_eq!(cards.len(), 5, "Two pair should have 5 cards (2 pairs + 1 kicker)");
|
|
}
|
|
|
|
#[test]
|
|
fn test_two_pair_from_7_cards() {
|
|
let two_pair_7cards: Vec<Card> = ["Ah", "As", "Kd", "Kc", "Qh", "Js", "9d"]
|
|
.iter()
|
|
.map(|s| Card::str_to_card(s).unwrap())
|
|
.collect();
|
|
|
|
let cards = find_two_pair(&two_pair_7cards).expect("Should find two pair");
|
|
assert_eq!(cards.len(), 5);
|
|
}
|
|
|
|
#[test]
|
|
fn test_one_pair_not_two_pair() {
|
|
let one_pair: Vec<Card> = ["Kh", "Ks", "Ad", "Qc", "Jh"]
|
|
.iter()
|
|
.map(|s| Card::str_to_card(s).unwrap())
|
|
.collect();
|
|
|
|
assert!(find_two_pair(&one_pair).is_none(), "Single pair should not be detected as two pair");
|
|
}
|
|
|
|
#[test]
|
|
fn test_full_house_not_two_pair() {
|
|
let full_house: Vec<Card> = ["7h", "7d", "7s", "Kc", "Kh"]
|
|
.iter()
|
|
.map(|s| Card::str_to_card(s).unwrap())
|
|
.collect();
|
|
|
|
assert!(find_two_pair(&full_house).is_none(), "Full house should not be detected as two pair");
|
|
}
|
|
|
|
// ===== TRIPS TESTS =====
|
|
|
|
#[test]
|
|
fn test_trips_basic() {
|
|
let trips_basic: Vec<Card> = ["7h", "7d", "7s", "Ac", "Kh"]
|
|
.iter()
|
|
.map(|s| Card::str_to_card(s).unwrap())
|
|
.collect();
|
|
|
|
let cards = find_trips(&trips_basic).expect("Should find trips");
|
|
assert_eq!(cards.len(), 5, "Trips should have 5 cards (3 trips + 2 kickers)");
|
|
}
|
|
|
|
#[test]
|
|
fn test_trips_from_7_cards() {
|
|
let trips_7cards: Vec<Card> = ["9h", "9d", "9s", "Ac", "Kh", "Qd", "Jc"]
|
|
.iter()
|
|
.map(|s| Card::str_to_card(s).unwrap())
|
|
.collect();
|
|
|
|
let cards = find_trips(&trips_7cards).expect("Should find trips from 7 cards");
|
|
assert_eq!(cards.len(), 5);
|
|
}
|
|
|
|
#[test]
|
|
fn test_full_house_not_trips() {
|
|
let full_house: Vec<Card> = ["8h", "8d", "8s", "5c", "5h"]
|
|
.iter()
|
|
.map(|s| Card::str_to_card(s).unwrap())
|
|
.collect();
|
|
|
|
assert!(find_trips(&full_house).is_none(), "Full house should not be detected as trips");
|
|
}
|
|
|
|
// ===== QUADS TESTS =====
|
|
|
|
#[test]
|
|
fn test_quads_basic() {
|
|
let quads_basic: Vec<Card> = ["Ah", "Ad", "As", "Ac", "Kh"]
|
|
.iter()
|
|
.map(|s| Card::str_to_card(s).unwrap())
|
|
.collect();
|
|
|
|
let cards = find_quads(&quads_basic).expect("Should find quads");
|
|
assert_eq!(cards.len(), 5, "Quads should have 5 cards (4 quads + 1 kicker)");
|
|
}
|
|
|
|
#[test]
|
|
fn test_quads_from_7_cards() {
|
|
let quads_7cards: Vec<Card> = ["3h", "3d", "3s", "3c", "Ah", "Kd", "Qc"]
|
|
.iter()
|
|
.map(|s| Card::str_to_card(s).unwrap())
|
|
.collect();
|
|
|
|
let cards = find_quads(&quads_7cards).expect("Should find quads from 7 cards");
|
|
assert_eq!(cards.len(), 5);
|
|
}
|
|
|
|
#[test]
|
|
fn test_trips_not_quads() {
|
|
let trips: Vec<Card> = ["Kh", "Kd", "Ks", "Ac", "Qh"]
|
|
.iter()
|
|
.map(|s| Card::str_to_card(s).unwrap())
|
|
.collect();
|
|
|
|
assert!(find_quads(&trips).is_none(), "Trips should not be detected as quads");
|
|
}
|
|
|
|
// ===== FULL HOUSE TESTS =====
|
|
|
|
#[test]
|
|
fn test_full_house_basic() {
|
|
let fh_basic: Vec<Card> = ["7h", "7d", "7s", "Kc", "Kh"]
|
|
.iter()
|
|
.map(|s| Card::str_to_card(s).unwrap())
|
|
.collect();
|
|
|
|
let cards = find_full_house(&fh_basic).expect("Should find full house");
|
|
assert_eq!(cards.len(), 5, "Full house should have 5 cards (3 trips + 2 pair)");
|
|
}
|
|
|
|
#[test]
|
|
fn test_full_house_from_7_cards() {
|
|
let fh_7cards: Vec<Card> = ["Ah", "Ad", "As", "Kc", "Kh", "Qd", "Jc"]
|
|
.iter()
|
|
.map(|s| Card::str_to_card(s).unwrap())
|
|
.collect();
|
|
|
|
let cards = find_full_house(&fh_7cards).expect("Should find full house from 7 cards");
|
|
assert_eq!(cards.len(), 5);
|
|
}
|
|
|
|
#[test]
|
|
fn test_just_trips_not_full_house() {
|
|
let just_trips: Vec<Card> = ["9h", "9d", "9s", "Ac", "Kh"]
|
|
.iter()
|
|
.map(|s| Card::str_to_card(s).unwrap())
|
|
.collect();
|
|
|
|
assert!(find_full_house(&just_trips).is_none(), "Just trips should not be full house");
|
|
}
|
|
|
|
#[test]
|
|
fn test_two_pair_not_full_house() {
|
|
let two_pair: Vec<Card> = ["Kh", "Ks", "8d", "8c", "Ah"]
|
|
.iter()
|
|
.map(|s| Card::str_to_card(s).unwrap())
|
|
.collect();
|
|
|
|
assert!(find_full_house(&two_pair).is_none(), "Two pair should not be full house");
|
|
}
|