diff --git a/challenges/temperature-converter/description.md b/challenges/temperature-converter/description.md index f796648..60f606f 100644 --- a/challenges/temperature-converter/description.md +++ b/challenges/temperature-converter/description.md @@ -31,6 +31,9 @@ assert_eq!(result, Ok(26.85)); let result = convert_temperature(100.0, "C", "X"); assert_eq!(result, Err("Invalid unit".to_string())); + +let result = convert_temperature(37.5, "C", "C"); +assert_eq!(result, Ok(37.5)); ``` ## Hints diff --git a/challenges/temperature-converter/src/lib.rs b/challenges/temperature-converter/src/lib.rs index f557801..d810900 100644 --- a/challenges/temperature-converter/src/lib.rs +++ b/challenges/temperature-converter/src/lib.rs @@ -6,6 +6,7 @@ pub fn convert_temperature(value: f64, from_unit: &str, to_unit: &str) -> Result ("K", "C") => Ok(value - 273.15), ("F", "K") => Ok((value - 32.0) * 5.0 / 9.0 + 273.15), ("K", "F") => Ok((value - 273.15) * 9.0 / 5.0 + 32.0), + ("C", "C") | ("F", "F") | ("K", "K") => Ok(value), _ => Err("Invalid unit".to_string()), } } diff --git a/challenges/temperature-converter/tests/tests.rs b/challenges/temperature-converter/tests/tests.rs index e3131a7..8ac02c4 100644 --- a/challenges/temperature-converter/tests/tests.rs +++ b/challenges/temperature-converter/tests/tests.rs @@ -41,4 +41,9 @@ mod tests { fn test_convert_kelvin_to_fahrenheit() { assert_eq!(convert_temperature(273.15, "K", "F"), Ok(32.0)); } + + #[test] + fn test_convert_celsius_to_celsius() { + assert_eq!(convert_temperature(37.5, "C", "C"), Ok(37.5)); + } }