From 3a7429df1ae08b80d120ce5e11f762142dcd9598 Mon Sep 17 00:00:00 2001 From: Dorian Pula Date: Tue, 5 Nov 2019 10:00:30 -0500 Subject: [PATCH] Add more comprehensive benchmarks. --- test.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/test.py b/test.py index 9140f86..b9c09fd 100644 --- a/test.py +++ b/test.py @@ -1,3 +1,5 @@ +import random + import unit_converter @@ -10,11 +12,23 @@ def test_using_unit_converter(): assert python_unit_converter(25.0) == 77.0 -def test_using_python(benchmark): +def test_using_python_constant(benchmark): result = benchmark(python_unit_converter, 25.0) - assert result == 77.0 + assert round(result, 3) == round(77.0, 3) + + +def test_using_rust_constant(benchmark): + result = benchmark(unit_converter.convert_celsius_to_fahrenheit, 25.0) + assert round(result, 3) == round(77.0, 3) + + +def test_using_python(benchmark): + temperature = random.random() * 100 + result = benchmark(python_unit_converter, temperature) + assert round(result, 3) == round(python_unit_converter(temperature), 3) def test_using_rust(benchmark): - result = benchmark(unit_converter.convert_celsius_to_fahrenheit, 25.0) - assert result == 77.0 + temperature = random.random() * 100 + result = benchmark(unit_converter.convert_celsius_to_fahrenheit, temperature) + assert round(result, 3) == round(python_unit_converter(temperature), 3)