1pub mod kinds {
6 #[derive(Debug, PartialEq)]
8 pub enum PrimaryColor {
9 Red,
10 Yellow,
11 Blue,
12 }
13
14 #[derive(Debug, PartialEq)]
16 pub enum SecondaryColor {
17 Orange,
18 Green,
19 Purple,
20 }
21}
22
23pub mod utils {
24 use crate::kinds::*;
25
26 pub fn mix(c1: PrimaryColor, c2: PrimaryColor) -> SecondaryColor {
43 match c1 {
44 PrimaryColor::Blue => match c2 {
45 PrimaryColor::Yellow => SecondaryColor::Green,
46 PrimaryColor::Red => SecondaryColor::Purple,
47 PrimaryColor::Blue => panic!("You can't mix the same colors"),
48 },
49 PrimaryColor::Yellow => match c2 {
50 PrimaryColor::Yellow => panic!("You can't mix the same colors"),
51 PrimaryColor::Red => SecondaryColor::Orange,
52 PrimaryColor::Blue => SecondaryColor::Green,
53 },
54 PrimaryColor::Red => match c2 {
55 PrimaryColor::Yellow => SecondaryColor::Orange,
56 PrimaryColor::Red => panic!("You can't mix the same colors"),
57 PrimaryColor::Blue => SecondaryColor::Purple,
58 },
59 }
60 }
61}
62
63pub use kinds::PrimaryColor;
64pub use kinds::SecondaryColor;
65pub use utils::mix;
66
67#[cfg(test)]
68mod test {
69 use super::*;
70
71 #[test]
72 #[should_panic(expected = "You can't mix the same colors")]
73 fn test_yellow_yellow() {
74 mix(PrimaryColor::Yellow, PrimaryColor::Yellow);
75 }
76
77 #[test]
78 #[should_panic(expected = "You can't mix the same colors")]
79 fn test_red_red() {
80 mix(PrimaryColor::Red, PrimaryColor::Red);
81 }
82
83 #[test]
84 #[should_panic(expected = "You can't mix the same colors")]
85 fn test_blue_blue() {
86 mix(PrimaryColor::Blue, PrimaryColor::Blue);
87 }
88}