diff options
Diffstat (limited to 'test/test_EeVal.py')
-rw-r--r-- | test/test_EeVal.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/test/test_EeVal.py b/test/test_EeVal.py index b96e089..6e15ff0 100644 --- a/test/test_EeVal.py +++ b/test/test_EeVal.py @@ -1,5 +1,50 @@ +import pytest from ee import EeVal +@pytest.mark.parametrize("s, num_value, str_value, unit", [ + ("0", 0, "0", None), + ("0 k", 0, "0", None), + ("1", 1, "1", None), + ("10", 10, "10", None), + ("10k", 10 * 1000, "10 k", None), + ("10 k", 10 * 1000, "10 k", None), + ("10 k", 10 * 1000, "10 k", None), + ("1000 m", 1, "1", None), + ("100 m", 0.1, "100 m", None), + ("100 n", 0.0000001, "100 n", None), + ("1 m", 0.001, "1 m", None), + ("1 u", 0.000001, "1 u", None), + ("0.1 u", 0.0000001, "100 n", None), + (".1 u", 0.0000001, "100 n", None), + ("4.7 u", 0.0000047, "4.7 u", None), + ("1 µ", 0.000001, "1 u", None), + ("1 n", 0.000000001, "1 n", None), + ("10 n", 0.00000001, "10 n", None), + ("1p", 1e-12, "1 p", None), + ("0.8p", 8e-13, "0.8 p", None), + ("0.008p", 8e-15, "0.008 p", None), + ]) +def test_basic(s, num_value, str_value, unit): + num_value = float(num_value) + v = EeVal(s) + assert float(v) == v.value + epsilon = num_value * 0.01 + assert (num_value + epsilon) >= float(v) and (num_value - epsilon) <= float(v) + assert str_value == str(v) + assert unit == v.unit + +@pytest.mark.parametrize("s, str_value, unit", [ + ("10nF", "10 nF", "F"), + ("10n F", "10 nF", "F"), + ("10 n F", "10 nF", "F"), + ("4.7 n F", "4.7 nF", "F"), + ]) +def test_units(s, str_value, unit): + v = EeVal(s) + assert unit == v.unit + assert float(v) == v.value + assert str_value == str(v) + def test_ordering(): p100 = EeVal('100 p') n100 = EeVal('100 n') |