From b8e315ac26e9ce0a60ecb9d756f089d31b42e361 Mon Sep 17 00:00:00 2001 From: Scott Worley Date: Thu, 13 Jul 2023 18:08:17 -0700 Subject: [PATCH] 1-based rank value --- src/lib.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index c3736e9..c0475b3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,6 +7,12 @@ pub const NUM_CARDS: u8 = NUM_RANKS * NUM_SUITS + NUM_JOKERS; #[derive(Clone, Copy, Eq, PartialEq)] pub struct Rank(u8); +impl Rank { + #[must_use] + pub fn value(&self) -> u8 { + self.0 + 1 + } +} #[derive(Clone, Copy, Eq, PartialEq)] pub struct Suit(u8); @@ -103,7 +109,14 @@ mod tests { #[test] fn test_deck() { use WithOrWithoutJokers::*; - let _d = deck(WithoutJokers); + let d = deck(WithoutJokers); + let rank_sum: u32 = d + .iter() + .map(Card::rank) + .flatten() + .map(|r| u32::from(r.value())) + .sum(); + assert_eq!(rank_sum, 364); let _dj = deck(WithJokers); } } -- 2.44.1