Kings-Eunuch/kings-eunuch/tests/straight_tests.rs
2026-02-08 09:13:01 -05:00

79 lines
2.3 KiB
Rust

use kings_eunuch::hand_building::{find_straight, Card, Rank};
#[test]
fn test_basic_straight() {
let basic_straight: Vec<Card> = ["5h", "6d", "7s", "8c", "9h"]
.iter()
.map(|s| Card::str_to_card(s).unwrap())
.collect();
let cards = find_straight(&basic_straight).expect("Should find straight");
assert_eq!(cards.len(), 5, "Straight should have 5 cards");
}
#[test]
fn test_straight_from_7_cards() {
let seven_cards: Vec<Card> = ["5h", "6d", "7s", "8c", "9h", "Ts", "Kd"]
.iter()
.map(|s| Card::str_to_card(s).unwrap())
.collect();
let cards = find_straight(&seven_cards).expect("Should find straight from 7 cards");
assert_eq!(cards.len(), 5, "Should return exactly 5 cards");
}
#[test]
fn test_broadway_straight() {
let broadway: Vec<Card> = ["Th", "Jd", "Qs", "Kc", "Ah"]
.iter()
.map(|s| Card::str_to_card(s).unwrap())
.collect();
let cards = find_straight(&broadway).expect("Should find Broadway straight");
assert_eq!(cards.len(), 5);
}
#[test]
fn test_wheel_straight_5_cards() {
let wheel: Vec<Card> = ["Ah", "2d", "3s", "4c", "5h"]
.iter()
.map(|s| Card::str_to_card(s).unwrap())
.collect();
let cards = find_straight(&wheel).expect("Should find wheel straight");
assert_eq!(cards.len(), 5);
assert_eq!(cards[4].rank, Rank::Ace, "Ace should be last in wheel");
}
#[test]
fn test_wheel_straight_from_7_cards() {
let wheel_7cards: Vec<Card> = ["Ah", "2d", "3s", "4c", "5h", "Kd", "Qc"]
.iter()
.map(|s| Card::str_to_card(s).unwrap())
.collect();
let cards = find_straight(&wheel_7cards).expect("Should find wheel from 7 cards");
assert_eq!(cards.len(), 5);
assert_eq!(cards[4].rank, Rank::Ace, "Ace should be last in wheel");
}
#[test]
fn test_no_straight_gap_in_sequence() {
let no_straight: Vec<Card> = ["5h", "6d", "7s", "9c", "Th"]
.iter()
.map(|s| Card::str_to_card(s).unwrap())
.collect();
assert!(find_straight(&no_straight).is_none(), "Gap should prevent straight");
}
#[test]
fn test_duplicates_no_straight() {
let duplicates: Vec<Card> = ["7h", "7d", "8s", "8c", "9h", "9d", "Ts"]
.iter()
.map(|s| Card::str_to_card(s).unwrap())
.collect();
assert!(find_straight(&duplicates).is_none(), "Only 4 unique consecutive ranks");
}