use crate::card::get_rank;
use crate::card::get_suit;
pub fn to_string(card: i32) -> String {
let ranks: [&str; 13] = [
"2", "3", "4", "5", "6", "7", "8", "9", "T", "J", "Q", "K", "A",
];
let suits: [&str; 4] = ["c", "d", "h", "s"];
let rank: Option<&&str> = ranks.get(get_rank(card) as usize);
let suit: Option<&&str> = suits.get(get_suit(card) as usize);
if let (Some(rank), Some(suit)) = (rank, suit) {
return format!("{}{}", rank, suit);
}
return format!("");
}
#[cfg(test)]
mod to_string {
use crate::card::to_string;
#[test]
fn ace_of_clubs() {
let actual = to_string(268471337);
assert_eq!(actual, "Ac");
}
#[test]
fn ace_of_diamonds() {
let actual = to_string(268455017);
assert_eq!(actual, "Ad");
}
#[test]
fn ace_of_hearts() {
let actual = to_string(268446889);
assert_eq!(actual, "Ah");
}
#[test]
fn ace_of_spades() {
let actual = to_string(268442857);
assert_eq!(actual, "As");
}
}