Add a test for the temperature check.

This commit is contained in:
Dorian 2019-11-06 19:40:51 -05:00
parent 5c53942b62
commit 4d8777a9af
1 changed files with 11 additions and 7 deletions

View File

@ -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<f32>) -> Vec<f32> {
}
#[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::<Temperature>()?;
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::<Temperature>()?;
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);
}
}