use rgb::RGB8;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ColorPalette {
pub primary: RGB8,
pub secondary: RGB8,
pub accent: RGB8,
}
impl ColorPalette {
pub fn new(primary: RGB8, secondary: RGB8, accent: RGB8) -> Self {
Self {
primary,
secondary,
accent,
}
}
pub fn mono(color: RGB8) -> Self {
Self {
primary: color,
secondary: color,
accent: color,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_new_stores_fields() {
let p = RGB8::new(255, 0, 0);
let s = RGB8::new(0, 255, 0);
let a = RGB8::new(0, 0, 255);
let palette = ColorPalette::new(p, s, a);
assert_eq!(palette.primary, p);
assert_eq!(palette.secondary, s);
assert_eq!(palette.accent, a);
}
#[test]
fn test_mono_sets_all_equal() {
let color = RGB8::new(42, 100, 200);
let palette = ColorPalette::mono(color);
assert_eq!(palette.primary, color);
assert_eq!(palette.secondary, color);
assert_eq!(palette.accent, color);
}
#[test]
fn test_copy_clone() {
let palette = ColorPalette::mono(RGB8::new(10, 20, 30));
let copied = palette;
let cloned = palette.clone();
assert_eq!(palette, copied);
assert_eq!(palette, cloned);
}
#[test]
fn test_partial_eq() {
let a = ColorPalette::new(RGB8::new(1, 2, 3), RGB8::new(4, 5, 6), RGB8::new(7, 8, 9));
let b = ColorPalette::new(RGB8::new(1, 2, 3), RGB8::new(4, 5, 6), RGB8::new(7, 8, 9));
let c = ColorPalette::new(RGB8::new(9, 8, 7), RGB8::new(4, 5, 6), RGB8::new(7, 8, 9));
assert_eq!(a, b);
assert_ne!(a, c);
}
}