From f4d6e8bbf66ce4601934c586014868f2ced690ca Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Thu, 19 Jan 2023 18:21:27 +0000 Subject: tests: Add unit tests for search. * tests/unit/test_search.py: New file. --- tests/unit/test_search.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 tests/unit/test_search.py (limited to 'tests') 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) -- cgit v1.2.3