card: new -> make_joker and make_playing-card

Always better to be explicit with our constructor names.
This commit is contained in:
2026-04-03 02:07:02 +01:00
committed by oreodave
parent f40596bc1d
commit 6119410496
3 changed files with 8 additions and 4 deletions

View File

@@ -55,7 +55,11 @@ impl PlayingCard {
}
impl Card {
pub fn new(rank: Rank, suit: Suit) -> Self {
pub fn make_joker() -> Self {
Self::Joker(-1)
}
pub fn make_playing_card(rank: Rank, suit: Suit) -> Self {
Self::PlayingCard(PlayingCard::new(0, rank, suit))
}

View File

@@ -128,7 +128,7 @@ mod tests {
#[test]
fn new() {
// Two jokers can never be a pair.
assert_eq!(Pair::new(Card::joker(), Card::joker()), None);
assert_eq!(Pair::new(Card::make_joker(), Card::make_joker()), None);
for rank in 0..13 {
// Vector of cards of a rank: size 4.
@@ -157,7 +157,7 @@ mod tests {
// TEST: Pairs may have one joker.
let pair = {
let p = Pair::new(c1, Card::joker());
let p = Pair::new(c1, Card::make_joker());
assert_ne!(p, None);
p.unwrap()
};

View File

@@ -55,7 +55,7 @@ mod tests {
#[test]
fn new() {
// TEST: Jokers are not valid singles.
assert!(Single::new(Card::joker()).is_none());
assert!(Single::new(Card::make_joker()).is_none());
let deck = make_decks(1);
let singles: Vec<Option<Single>> =