57 lines
1.7 KiB
Rust
57 lines
1.7 KiB
Rust
use kings_eunuch::hand_building::{find_high_card, Card, Rank};
|
|
|
|
#[test]
|
|
fn test_high_card_basic() {
|
|
let high_card: Vec<Card> = ["Ah", "Ks", "Qd", "Jc", "9h"]
|
|
.iter()
|
|
.map(|s| Card::str_to_card(s).unwrap())
|
|
.collect();
|
|
|
|
let result = find_high_card(&high_card).expect("Should always find high card");
|
|
assert_eq!(result.len(), 5, "High card should have 5 cards");
|
|
assert_eq!(result[0].rank, Rank::Ace, "First card should be Ace");
|
|
}
|
|
|
|
#[test]
|
|
fn test_high_card_from_7_cards() {
|
|
let seven_cards: Vec<Card> = ["Ah", "Ks", "Qd", "Jc", "9h", "7s", "2d"]
|
|
.iter()
|
|
.map(|s| Card::str_to_card(s).unwrap())
|
|
.collect();
|
|
|
|
let result = find_high_card(&seven_cards).expect("Should find high card from 7 cards");
|
|
assert_eq!(result.len(), 5, "Should return exactly 5 highest cards");
|
|
}
|
|
|
|
#[test]
|
|
fn test_high_card_with_duplicates() {
|
|
let with_dups: Vec<Card> = ["Ah", "As", "Kd", "Qc", "Jh", "Ts", "9d"]
|
|
.iter()
|
|
.map(|s| Card::str_to_card(s).unwrap())
|
|
.collect();
|
|
|
|
let result = find_high_card(&with_dups).expect("Should find high card even with pairs");
|
|
assert_eq!(result.len(), 5);
|
|
}
|
|
|
|
#[test]
|
|
fn test_high_card_exactly_5_cards() {
|
|
let exactly_5: Vec<Card> = ["Kh", "Qs", "Jd", "Tc", "8h"]
|
|
.iter()
|
|
.map(|s| Card::str_to_card(s).unwrap())
|
|
.collect();
|
|
|
|
let result = find_high_card(&exactly_5).expect("Should work with exactly 5 cards");
|
|
assert_eq!(result.len(), 5);
|
|
}
|
|
|
|
#[test]
|
|
fn test_high_card_insufficient_cards() {
|
|
let too_few: Vec<Card> = ["Ah", "Ks", "Qd", "Jc"]
|
|
.iter()
|
|
.map(|s| Card::str_to_card(s).unwrap())
|
|
.collect();
|
|
|
|
assert!(find_high_card(&too_few).is_none(), "Should return None with fewer than 5 cards");
|
|
}
|