From 93d29be6230b6404b9194882caefad6eb90cdea4 Mon Sep 17 00:00:00 2001 From: Daniel Yan Date: Sun, 24 Nov 2024 21:25:30 +0800 Subject: [PATCH 1/4] add test (temperature-converter) --- challenges/temperature-converter/tests/tests.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/challenges/temperature-converter/tests/tests.rs b/challenges/temperature-converter/tests/tests.rs index e3131a7..5ac7bb3 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_convert_celsius() { + assert_eq!(convert_temperature(37.5, "C", "C"), Ok(37.5)); + } } From c7ca4ab5711b296aaa2f5800758813f3fe199ad9 Mon Sep 17 00:00:00 2001 From: Daniel Yan Date: Sun, 24 Nov 2024 21:33:57 +0800 Subject: [PATCH 2/4] Update description.md --- challenges/temperature-converter/description.md | 3 +++ 1 file changed, 3 insertions(+) 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 From 9af194a2ba55b9fea2d646c44069f2a2e3c419f6 Mon Sep 17 00:00:00 2001 From: Daniel Yan Date: Sun, 24 Nov 2024 21:41:25 +0800 Subject: [PATCH 3/4] Update lib.rs in temperature-converter --- challenges/temperature-converter/src/lib.rs | 1 + 1 file changed, 1 insertion(+) 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()), } } From 2a2970f1eba40824ba1cb5b97956c151e8250a4b Mon Sep 17 00:00:00 2001 From: Daniel Yan Date: Sun, 24 Nov 2024 21:44:07 +0800 Subject: [PATCH 4/4] typo fix --- challenges/temperature-converter/tests/tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/challenges/temperature-converter/tests/tests.rs b/challenges/temperature-converter/tests/tests.rs index 5ac7bb3..8ac02c4 100644 --- a/challenges/temperature-converter/tests/tests.rs +++ b/challenges/temperature-converter/tests/tests.rs @@ -43,7 +43,7 @@ mod tests { } #[test] - fn test_convert_celsius_to_convert_celsius() { + fn test_convert_celsius_to_celsius() { assert_eq!(convert_temperature(37.5, "C", "C"), Ok(37.5)); } }