From 4d8777a9af4bcd81132abce333d8f06cb928b659 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dorian=20Pu=C5=82a?= Date: Wed, 6 Nov 2019 19:40:51 -0500 Subject: [PATCH] Add a test for the temperature check. --- src/lib.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index b86119b..30e9d19 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -29,8 +29,6 @@ impl Temperature { } } -// TODO: Add a test that -20 C and 32 kph feels like -32.9 - #[pyfunction] fn convert_to_fahrenheit(celsius: f32) -> f32 { celsius * 1.8 + 32.0 @@ -45,20 +43,26 @@ fn batch_convert_to_fahrenheit(celsius: Vec) -> Vec { } #[pymodule] -fn unit_converter(_py: Python, m: &PyModule) -> PyResult<()> { - m.add_wrapped(wrap_pyfunction!(convert_to_fahrenheit))?; - m.add_wrapped(wrap_pyfunction!(batch_convert_to_fahrenheit))?; - m.add_class::()?; +fn unit_converter(_py: Python, module: &PyModule) -> PyResult<()> { + module.add_wrapped(wrap_pyfunction!(convert_to_fahrenheit))?; + module.add_wrapped(wrap_pyfunction!(batch_convert_to_fahrenheit))?; + module.add_class::()?; Ok(()) } #[cfg(test)] mod tests { - use super::convert_to_fahrenheit; + use super::{convert_to_fahrenheit, Temperature}; #[test] fn conversion_celsius_to_fahrenheit() { assert_eq!(convert_to_fahrenheit(25.0), 77.0); } + + #[test] + fn windchill_test() { + let temperature = Temperature{ celsius: -20.0 }; + assert_eq!(temperature.windchill(32.0).round(), -32.9); + } }