diff options
author | Arun Isaac | 2023-01-19 18:21:27 +0000 |
---|---|---|
committer | Arun Isaac | 2023-01-19 18:34:44 +0000 |
commit | f4d6e8bbf66ce4601934c586014868f2ced690ca (patch) | |
tree | a3bbca887fb1840378ae2e82ad669d6a00c16ab8 | |
parent | 62b010ad6b501207f10e57897baf9f23e508b20b (diff) | |
download | genenetwork3-f4d6e8bbf66ce4601934c586014868f2ced690ca.tar.gz |
tests: Add unit tests for search.
* tests/unit/test_search.py: New file.
-rw-r--r-- | tests/unit/test_search.py | 35 |
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) |