From: Scott Worley Date: Fri, 14 Jul 2023 01:08:17 +0000 (-0700) Subject: 1-based rank value X-Git-Url: http://git.scottworley.com/pluta-lesnura/commitdiff_plain/b8e315ac26e9ce0a60ecb9d756f089d31b42e361?ds=sidebyside 1-based rank value --- 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); } }