Add a test for the temperature check.
This commit is contained in:
parent
5c53942b62
commit
4d8777a9af
18
src/lib.rs
18
src/lib.rs
|
@ -29,8 +29,6 @@ impl Temperature {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Add a test that -20 C and 32 kph feels like -32.9
|
|
||||||
|
|
||||||
#[pyfunction]
|
#[pyfunction]
|
||||||
fn convert_to_fahrenheit(celsius: f32) -> f32 {
|
fn convert_to_fahrenheit(celsius: f32) -> f32 {
|
||||||
celsius * 1.8 + 32.0
|
celsius * 1.8 + 32.0
|
||||||
|
@ -45,20 +43,26 @@ fn batch_convert_to_fahrenheit(celsius: Vec<f32>) -> Vec<f32> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[pymodule]
|
#[pymodule]
|
||||||
fn unit_converter(_py: Python, m: &PyModule) -> PyResult<()> {
|
fn unit_converter(_py: Python, module: &PyModule) -> PyResult<()> {
|
||||||
m.add_wrapped(wrap_pyfunction!(convert_to_fahrenheit))?;
|
module.add_wrapped(wrap_pyfunction!(convert_to_fahrenheit))?;
|
||||||
m.add_wrapped(wrap_pyfunction!(batch_convert_to_fahrenheit))?;
|
module.add_wrapped(wrap_pyfunction!(batch_convert_to_fahrenheit))?;
|
||||||
m.add_class::<Temperature>()?;
|
module.add_class::<Temperature>()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|
||||||
use super::convert_to_fahrenheit;
|
use super::{convert_to_fahrenheit, Temperature};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn conversion_celsius_to_fahrenheit() {
|
fn conversion_celsius_to_fahrenheit() {
|
||||||
assert_eq!(convert_to_fahrenheit(25.0), 77.0);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue