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
90
91
92
93
94
95
pub use self::kinds::PrimaryColor;
pub use self::kinds::SecondaryColor;
pub use self::utils::mix;
pub mod kinds {
#[derive(Debug)]
#[derive(PartialEq)]
pub enum PrimaryColor {
Red,
Yellow,
Blue,
}
#[derive(Debug)]
#[derive(PartialEq)]
pub enum SecondaryColor {
Red,
Yellow,
Blue,
Orange,
Green,
Purple,
}
}
pub mod utils {
use crate::kinds::*;
pub fn mix(c1: PrimaryColor, c2: PrimaryColor) -> SecondaryColor {
match c1 {
PrimaryColor::Red => {
match c2 {
PrimaryColor::Red => SecondaryColor::Red,
PrimaryColor::Yellow => SecondaryColor::Orange,
PrimaryColor::Blue => SecondaryColor::Purple,
}
},
PrimaryColor::Yellow => {
match c2 {
PrimaryColor::Red => SecondaryColor::Orange,
PrimaryColor::Yellow => SecondaryColor::Yellow,
PrimaryColor::Blue => SecondaryColor::Green,
}
},
PrimaryColor::Blue => {
match c2 {
PrimaryColor::Red => SecondaryColor::Purple,
PrimaryColor::Yellow => SecondaryColor::Green,
PrimaryColor::Blue => SecondaryColor::Blue,
}
}
}
}
}
#[cfg(test)]
mod tests {
use super::*;
use kinds::SecondaryColor;
use kinds::PrimaryColor;
use utils::mix;
#[test]
fn mix_a_few_primary_colors() {
assert_eq!(SecondaryColor::Green, mix(PrimaryColor::Blue, PrimaryColor::Yellow));
assert_eq!(SecondaryColor::Orange, mix(PrimaryColor::Yellow, PrimaryColor::Red));
assert_eq!(SecondaryColor::Purple, mix(PrimaryColor::Red, PrimaryColor::Blue));
}
}