aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/unit/test_search.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/unit/test_search.py b/tests/unit/test_search.py
new file mode 100644
index 0000000..487bac0
--- /dev/null
+++ b/tests/unit/test_search.py
@@ -0,0 +1,35 @@
+from hypothesis import given, strategies as st
+from pymonad.maybe import Just, Nothing
+import pytest
+
+from gn3.api.search import apply_si_suffix, parse_range
+
+@pytest.mark.unit_test
+@given(st.decimals(places=3, allow_nan=False, allow_infinity=False),
+ st.sampled_from(["k", "K"]))
+def test_apply_si_suffix_kilo(mantissa, suffix):
+ assert apply_si_suffix(f"{mantissa}{suffix}") == int(mantissa * 10**3)
+
+@pytest.mark.unit_test
+@given(st.decimals(places=6, allow_nan=False, allow_infinity=False),
+ st.sampled_from(["m", "M"]))
+def test_apply_si_suffix_mega(mantissa, suffix):
+ assert apply_si_suffix(f"{mantissa}{suffix}") == int(mantissa * 10**6)
+
+@pytest.mark.unit_test
+@given(st.decimals(places=9, allow_nan=False, allow_infinity=False),
+ st.sampled_from(["g", "G"]))
+def test_apply_si_suffix_giga(mantissa, suffix):
+ assert apply_si_suffix(f"{mantissa}{suffix}") == int(mantissa * 10**9)
+
+@pytest.mark.unit_test
+def test_parse_range_closed_interval():
+ assert parse_range("foo..bar") == (Just("foo"), Just("bar"))
+
+@pytest.mark.unit_test
+def test_parse_range_left_open_interval():
+ assert parse_range("..bar") == (Nothing, Just("bar"))
+
+@pytest.mark.unit_test
+def test_parse_range_right_open_interval():
+ assert parse_range("foo..") == (Just("foo"), Nothing)