55 lines
1.6 KiB
Rust
55 lines
1.6 KiB
Rust
use kings_eunuch::hand_building::{find_flush, Card};
|
|
|
|
#[test]
|
|
fn test_basic_flush() {
|
|
let flush_cards: Vec<Card> = ["Ah", "Kh", "Qh", "Jh", "9h"]
|
|
.iter()
|
|
.map(|s| Card::str_to_card(s).unwrap())
|
|
.collect();
|
|
|
|
let cards = find_flush(&flush_cards).expect("Should find flush");
|
|
assert_eq!(cards.len(), 5, "Flush should have 5 cards");
|
|
}
|
|
|
|
#[test]
|
|
fn test_flush_from_7_cards() {
|
|
let seven_cards: Vec<Card> = ["Ah", "Kh", "Qh", "Jh", "9h", "8d", "2c"]
|
|
.iter()
|
|
.map(|s| Card::str_to_card(s).unwrap())
|
|
.collect();
|
|
|
|
let cards = find_flush(&seven_cards).expect("Should find flush from 7 cards");
|
|
assert_eq!(cards.len(), 5, "Should return best 5 cards");
|
|
}
|
|
|
|
#[test]
|
|
fn test_no_flush_mixed_suits() {
|
|
let no_flush: Vec<Card> = ["Ah", "Ks", "Qd", "Jc", "9h"]
|
|
.iter()
|
|
.map(|s| Card::str_to_card(s).unwrap())
|
|
.collect();
|
|
|
|
assert!(find_flush(&no_flush).is_none(), "Should not find flush in mixed suits");
|
|
}
|
|
|
|
#[test]
|
|
fn test_six_spades_returns_best_five() {
|
|
let six_spades: Vec<Card> = ["As", "Ks", "Qs", "Js", "9s", "2s"]
|
|
.iter()
|
|
.map(|s| Card::str_to_card(s).unwrap())
|
|
.collect();
|
|
|
|
let cards = find_flush(&six_spades).expect("Should find flush");
|
|
assert_eq!(cards.len(), 5, "Should return exactly 5 cards");
|
|
}
|
|
|
|
#[test]
|
|
fn test_four_hearts_no_flush() {
|
|
let four_hearts: Vec<Card> = ["Ah", "Kh", "Qh", "Jh", "9s"]
|
|
.iter()
|
|
.map(|s| Card::str_to_card(s).unwrap())
|
|
.collect();
|
|
|
|
assert!(find_flush(&four_hearts).is_none(), "4 cards is not enough for flush");
|
|
}
|