diff --git a/batch_test.py b/batch_test.py index e7e2cfe..5349ea8 100644 --- a/batch_test.py +++ b/batch_test.py @@ -21,4 +21,4 @@ def test_using_python_batch(benchmark, batch_numbers): def test_using_rust_batch(benchmark, batch_numbers): - benchmark(unit_converter.batch_convert_celsius_to_fahrenheit, batch_numbers) + benchmark(unit_converter.batch_convert_to_fahrenheit, batch_numbers) diff --git a/src/lib.rs b/src/lib.rs index e9dc080..e9c6f08 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,32 +6,32 @@ extern crate pyo3; use pyo3::prelude::*; #[pyfunction] -fn convert_celsius_to_fahrenheit(celsius: f32) -> f32 { +fn convert_to_fahrenheit(celsius: f32) -> f32 { celsius * 1.8 + 32.0 } #[pyfunction] -fn batch_convert_celsius_to_fahrenheit(celsius: Vec) -> Vec { +fn batch_convert_to_fahrenheit(celsius: Vec) -> Vec { celsius .iter() - .map(|temperature| convert_celsius_to_fahrenheit(temperature.clone())) + .map(|temperature| convert_to_fahrenheit(temperature.clone())) .collect() } #[pymodule] fn unit_converter(_py: Python, m: &PyModule) -> PyResult<()> { - m.add_wrapped(wrap_pyfunction!(convert_celsius_to_fahrenheit))?; - m.add_wrapped(wrap_pyfunction!(batch_convert_celsius_to_fahrenheit))?; + m.add_wrapped(wrap_pyfunction!(convert_to_fahrenheit))?; + m.add_wrapped(wrap_pyfunction!(batch_convert_to_fahrenheit))?; Ok(()) } #[cfg(test)] mod tests { - use super::convert_celsius_to_fahrenheit; + use super::convert_to_fahrenheit; #[test] fn conversion_celsius_to_fahrenheit() { - assert_eq!(convert_celsius_to_fahrenheit(25.0), 77.0); + assert_eq!(convert_to_fahrenheit(25.0), 77.0); } } diff --git a/test.py b/test.py index 05191e0..cc56167 100644 --- a/test.py +++ b/test.py @@ -7,12 +7,8 @@ def python_unit_converter(celsius): return celsius * 1.8 + 32.0 -def batch_python_unit_converter(temperatures): - return [celsius * 1.8 + 32.0 for celsius in temperatures] - - def test_using_unit_converter(): - assert unit_converter.convert_celsius_to_fahrenheit(25.0) == 77.0 + assert unit_converter.convert_to_fahrenheit(25.0) == 77.0 assert python_unit_converter(25.0) == 77.0 @@ -22,7 +18,7 @@ def test_using_python_constant(benchmark): def test_using_rust_constant(benchmark): - result = benchmark(unit_converter.convert_celsius_to_fahrenheit, 25.0) + result = benchmark(unit_converter.convert_to_fahrenheit, 25.0) assert round(result, 3) == round(77.0, 3) @@ -34,5 +30,5 @@ def test_using_python(benchmark): def test_using_rust(benchmark): temperature = random.random() * 100 - result = benchmark(unit_converter.convert_celsius_to_fahrenheit, temperature) + result = benchmark(unit_converter.convert_to_fahrenheit, temperature) assert round(result, 3) == round(python_unit_converter(temperature), 3)