usse/funda-scraper/venv/lib/python3.10/site-packages/mypyc/test-data/run-floats.test

31 lines
784 B
Plaintext

# Test cases for floats (compile and run)
[case testStrToFloat]
def str_to_float(x: str) -> float:
return float(x)
[file driver.py]
from native import str_to_float
assert str_to_float("1") == 1.0
assert str_to_float("1.234567") == 1.234567
assert str_to_float("44324") == 44324.0
assert str_to_float("23.4") == 23.4
assert str_to_float("-43.44e-4") == -43.44e-4
[case testFloatArithmetic]
def test_abs() -> None:
assert abs(0.0) == 0.0
assert abs(-1.234567) == 1.234567
assert abs(44324.732) == 44324.732
assert abs(-23.4) == 23.4
assert abs(-43.44e-4) == 43.44e-4
def test_float_min_max() -> None:
x: float = 20.0
y: float = 30.0
assert min(x, y) == 20.0
assert min(y, x) == 20.0
assert max(x, y) == 30.0
assert max(y, x) == 30.0