aboutsummaryrefslogtreecommitdiff
path: root/tests/qc/test_cells.py
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2022-04-11 14:00:30 +0300
committerFrederick Muriuki Muriithi2022-04-11 14:00:30 +0300
commit7bd0a4c58dc1d238027c593b24c2d783e88b8f49 (patch)
treeef78984ef3b7cf9cdec5005df5a4a06a253b06bb /tests/qc/test_cells.py
parenta126edd7a9f2a72bf744a34c57aa9cb23568ba29 (diff)
downloadgn-uploader-7bd0a4c58dc1d238027c593b24c2d783e88b8f49.tar.gz
Implement tests and stubs for functions under test
Diffstat (limited to 'tests/qc/test_cells.py')
-rw-r--r--tests/qc/test_cells.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/qc/test_cells.py b/tests/qc/test_cells.py
new file mode 100644
index 0000000..b105286
--- /dev/null
+++ b/tests/qc/test_cells.py
@@ -0,0 +1,40 @@
+"""Test that values in cells within a line fulfill the required criteria"""
+
+import pytest
+from hypothesis import given
+from hypothesis import strategies as st
+
+from quality_control.errors import InvalidValue
+from quality_control.average import valid_value as avg_valid_value
+from quality_control.standard_error import valid_value as se_valid_value
+
+@given(num_str=st.from_regex("^(?!([0-9]+\.([0-9]{3}|[0-9]{6,}))).*", fullmatch=True))
+def test_cell_value_errors_with_invalid_inputs(num_str):
+ with pytest.raises(InvalidValue):
+ avg_valid_value(num_str)
+ with pytest.raises(InvalidValue):
+ se_valid_value(num_str)
+
+@given(num_str=st.from_regex("^[0-9]+\.([0-9]{1,2}|[0-9]{4,}$)", fullmatch=True))
+def test_cell_average_value_errors_if_not_three_decimal_places(num_str):
+ with pytest.raises(InvalidValue):
+ avg_valid_value(num_str)
+
+@given(num_str=st.from_regex("^[0-9]+\.[0-9]{3}$", fullmatch=True))
+def test_cell_average_value_pass_if_three_decimal_places(num_str):
+ processed = avg_valid_value(num_str)
+ assert (
+ isinstance(processed, float) and
+ processed == float(num_str))
+
+@given(num_str=st.from_regex("^[0-9]+\.([0-9]{0,5}$)", fullmatch=True))
+def test_cell_standard_error_value_errors_if_less_than_six_decimal_places(num_str):
+ with pytest.raises(InvalidValue):
+ se_valid_value(num_str)
+
+@given(num_str=st.from_regex("^[0-9]+\.[0-9]{6,}$", fullmatch=True))
+def test_cell_standard_error_value_pass_if_six_or_more_decimal_places(num_str):
+ processed = se_valid_value(num_str)
+ assert (
+ isinstance(processed, float) and
+ processed == float(num_str))