embedded-unit-converter/test.py

34 lines
997 B
Python
Raw Permalink Normal View History

2019-11-05 10:00:30 -05:00
import random
2019-11-06 09:24:35 -05:00
import unit_converter as rust
import py_unit_converter as py
2019-11-05 22:29:47 -05:00
def test_using_unit_converter():
2019-11-06 09:24:35 -05:00
rusty = rust.Temperature(25.0)
snakey = py.Temperature(25.0)
assert rusty.to_fahrenheit() == 77.0
assert snakey.to_fahrenheit() == 77.0
2019-10-30 10:37:01 -04:00
2019-11-05 10:00:30 -05:00
def test_using_python_constant(benchmark):
2019-10-30 10:37:01 -04:00
result = benchmark(python_unit_converter, 25.0)
2019-11-05 10:00:30 -05:00
assert round(result, 3) == round(77.0, 3)
2019-10-30 10:37:01 -04:00
2019-11-05 10:00:30 -05:00
def test_using_rust_constant(benchmark):
2019-11-06 09:24:35 -05:00
result = benchmark(unit_converter.convert_to_fahrenheit, 25.0)
2019-11-05 10:00:30 -05:00
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):
temperature = random.random() * 100
2019-11-06 09:24:35 -05:00
result = benchmark(unit_converter.convert_to_fahrenheit, temperature)
2019-11-05 10:00:30 -05:00
assert round(result, 3) == round(python_unit_converter(temperature), 3)