Решение на CSS Цветове от Ангел Седмаков

Обратно към всички решения

Към профила на Ангел Седмаков

Резултати

  • 16 точки от тестове
  • 0 бонус точки
  • 16 точки общо
  • 4 успешни тест(а)
  • 1 неуспешни тест(а)

Код

pub enum Color {
RGB {
red: u8,
green: u8,
blue: u8
},
HSV {
hue: u16,
saturation: u8,
value: u8,
}
}
impl Color{
pub fn new_rgb(red: u8, green: u8, blue: u8) -> Color {
Color::RGB{red, green,blue}
}
pub fn new_hsv(hue: u16, saturation: u8, value: u8) -> Color {
if hue > 360 || saturation > 100 || value >100 {
panic!("Input data is invalid");
}
Color::HSV{ hue,saturation, value}
}
pub fn unwrap_rgb(&self) -> (u8, u8, u8) {
if let Color::RGB{red, green,blue} = self {
(*red,*green,*blue)
}else{
panic!("Object is not of type Color::RGB")
}
}
pub fn unwrap_hsv(&self) -> (u16, u8, u8) {
if let Color::HSV{ hue,saturation, value} = self {
(*hue,*saturation,*value)
}else{
panic!("Object is not of type Color::HSV")
}
}
pub fn to_string(&self) -> String {
match self{
Color::RGB{red, green,blue} => {
format!("#{:x}{:x}{:x}", red, green,blue)
}
Color::HSV{ hue,saturation, value} => {
format!("hsv({},{}%,{}%)", hue, saturation,value)
}
}
}
pub fn invert(&self) -> Self {
match self{
Color::RGB{red, green,blue} => {
Color::RGB{
red: 255 - red,
green: 255 - green,
blue: 255 - blue
}
}
Color::HSV{ hue,saturation, value} => {
Color::HSV{
hue: 360 - hue,
saturation: 100 - saturation,
value: 100 - value
}
}
}
}
}

Лог от изпълнението

Compiling solution v0.1.0 (/tmp/d20230111-3772066-1j27zyy/solution)
    Finished test [unoptimized + debuginfo] target(s) in 0.66s
     Running tests/solution_test.rs (target/debug/deps/solution_test-0edbea2040daef01)

running 5 tests
test solution_test::test_invert_hsv ... ok
test solution_test::test_hsv_display ... ok
test solution_test::test_invert_rgb ... ok
test solution_test::test_rgb_display ... FAILED
test solution_test::test_new_hsv ... ok

failures:

---- solution_test::test_rgb_display stdout ----
thread 'solution_test::test_rgb_display' panicked at 'assertion failed: `(left == right)`
  left: `"#000"`,
 right: `"#000000"`', tests/solution_test.rs:8:5


failures:
    solution_test::test_rgb_display

test result: FAILED. 4 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

error: test failed, to rerun pass `--test solution_test`

История (1 версия и 0 коментара)

Ангел качи първо решение на 26.10.2022 19:39 (преди почти 3 години)