1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
//! A module for games

// Enables use as an iterable and computation of length
use strum_macros::{EnumIter, EnumCount};

/// Suits of a standard deck of cards
#[derive(Debug, EnumIter, EnumCount, Copy, Clone)]
pub enum Suit {
    Hearts,
    Clubs,
    Spades,
    Diamonds
}

#[cfg(test)]
mod test_suit {
    use crate::{*, Suit as ENUM_TO_TEST};

    const X:ENUM_TO_TEST = ENUM_TO_TEST::Clubs;
    const Y:ENUM_TO_TEST = ENUM_TO_TEST::Spades;

    #[test]
    fn accessibility() {
        println!("I like {:?}, but I also like {:?}", X, Y)
    }

    #[test]
    fn strum() {
        for x in ENUM_TO_TEST::iter() {
            println!("{:?}", x);
        }
        println!("There are {:?} variants", ENUM_TO_TEST::iter().count())
    }
}

/// Ranks of a standard deck of cards
#[derive(Debug, EnumIter, EnumCount)]
pub enum Rank {
    Ace = 1,
    Two = 2,
    Three = 3,
    Four = 4,
    Five = 5,
    Six = 6,
    Seven = 7,
    Eight = 8,
    Nine = 9,
    Ten = 10,
    Jack = 11,
    Queen = 12,
    King = 13
}

impl Rank {
    fn value(self) -> u8 {
        let mut value = self as u8;
        if value > 10 {
            value = 10;
        }
        value
    }
}


#[cfg(test)]
mod test_rank {
    use crate::{*, Rank as ENUM_TO_TEST};

    const X:ENUM_TO_TEST = ENUM_TO_TEST::Two;
    const Y:ENUM_TO_TEST = ENUM_TO_TEST::Jack;

    #[test]
    fn accessibility() {
        println!("I like {:?}, but I also like {:?}", X, Y)
    }

    #[test]
    fn int_casting() {
        println!("{:?} are worth {:?}, but {:?} are worth {:?}", X, X.value(), Y, Y.value())
    }

    #[test]
    fn strum() {
        for x in ENUM_TO_TEST::iter() {
            println!("{:?}", x);
        }
        println!("There are {:?} variants", ENUM_TO_TEST::iter().count())
    }
}