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));
}
}