From c213b0010c3ddc8d3215adab65bd489a9b884e30 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Fri, 24 Nov 2023 14:44:50 +0300 Subject: QC: Check for only one decimal place. --- tests/qc/test_cells.py | 21 +++++++++++++-------- tests/qc/test_cells_average.py | 4 ++++ tests/qc/test_cells_standard_error.py | 4 +++- 3 files changed, 20 insertions(+), 9 deletions(-) (limited to 'tests/qc') diff --git a/tests/qc/test_cells.py b/tests/qc/test_cells.py index 1c6c3f6..f5411fe 100644 --- a/tests/qc/test_cells.py +++ b/tests/qc/test_cells.py @@ -1,7 +1,8 @@ """Test that values in cells within a line fulfill the required criteria""" - import re from random import randint + +import pytest from hypothesis import given from hypothesis import strategies as st @@ -10,7 +11,7 @@ from quality_control.average import invalid_value as avg_invalid_value from quality_control.standard_error import invalid_value as se_invalid_value @given(num_str=st.from_regex( - r"^(?!(([0-9]+\.([0-9]{3}|[0-9]{6,}))|[0-9]+\.?0*)).*", fullmatch=True)) + r"^(?!([0-9]+\.[0-9]{1,}|0+)).*", fullmatch=True)) def test_cell_value_errors_with_invalid_inputs2(num_str): """ GIVEN: `num_str` is an arbitrary string that is an invalid input, @@ -22,12 +23,14 @@ def test_cell_value_errors_with_invalid_inputs2(num_str): assert avg_invalid_value(0, 0, num_str) == InvalidValue( 0, 0, num_str, ( f"Invalid value '{num_str}'. Expected string representing a number " - "with exactly three decimal places.")) + "with at least one decimal place.")) assert se_invalid_value(0, 0, num_str) == InvalidValue( 0, 0, num_str, ( f"Invalid value '{num_str}'. Expected string representing a number " - "with at least six decimal places.")) + "with at least one decimal place.")) +@pytest.mark.skip(reason=("Checks changed. We now enforce values must have at " + "least one decimal place")) @given(num_str=st.from_regex( r"^[0-9]+\.([0-9]{1,2}|[0-9]{4,}$)", fullmatch=True).filter( lambda param: not re.match(r"^[0-9]+\.0+$", param))) @@ -45,10 +48,10 @@ def test_cell_average_value_errors_if_not_three_decimal_places2(num_str): f"Invalid value '{num_str}'. Expected string representing a number " "with exactly three decimal places.")) -@given(num_str=st.from_regex(r"^[0-9]+\.[0-9]{3}$", fullmatch=True)) +@given(num_str=st.from_regex(r"^[0-9]+\.[0-9]{1,}$", fullmatch=True)) def test_cell_average_value_pass_if_three_decimal_places(num_str): """ - GIVEN: `num_str` is a string representing a number with exactly three + GIVEN: `num_str` is a string representing a number with at least one decimal places, e.g. 2.924, 39.483 WHEN: `num_str` is provided as an argument to `avg_invalid_value` function, THEN: `avg_invalid_value` returns `None` @@ -56,6 +59,8 @@ def test_cell_average_value_pass_if_three_decimal_places(num_str): line, col = randint(0, 100), randint(0, 20) assert avg_invalid_value(line, col, num_str) is None +@pytest.mark.skip(reason=("Checks changed. We now enforce values must have at " + "least one decimal place")) @given(num_str=st.from_regex(r"^[0-9]+\.([0-9]{0,5}$)", fullmatch=True).filter( lambda param: not re.match(r"^[0-9]+\.?0*$", param))) def test_cell_standard_error_value_errors_if_less_than_six_decimal_places2(num_str): @@ -73,10 +78,10 @@ def test_cell_standard_error_value_errors_if_less_than_six_decimal_places2(num_s "with at least six decimal places.")) -@given(num_str=st.from_regex(r"^[0-9]+\.[0-9]{6,}$", fullmatch=True)) +@given(num_str=st.from_regex(r"^[0-9]+\.[0-9]{1,}$", fullmatch=True)) def test_cell_standard_error_value_pass_if_six_or_more_decimal_places(num_str): """ - GIVEN: `num_str` is a string representing a number with six or more + GIVEN: `num_str` is a string representing a number with one or more decimal places, e.g. 2.938434, 39.4837343 WHEN: `num_str` is provided as an argument to `se_invalid_value` function, THEN: `se_invalid_value` returns `None` diff --git a/tests/qc/test_cells_average.py b/tests/qc/test_cells_average.py index 68fd4ec..cf23e13 100644 --- a/tests/qc/test_cells_average.py +++ b/tests/qc/test_cells_average.py @@ -1,10 +1,14 @@ """Test average values.""" from random import randint + +import pytest from hypothesis import given from hypothesis import strategies as st from quality_control.average import invalid_value as avg_invalid_value +@pytest.mark.skip(reason=("Checks changed. We now enforce values must have at " + "least one decimal place")) @given(num_str=st.from_regex(r"^[0-9]+$", fullmatch=True)) def test_cell_average_value_pass_if_no_decimal_places(num_str): """ diff --git a/tests/qc/test_cells_standard_error.py b/tests/qc/test_cells_standard_error.py index 90c13cf..754db22 100644 --- a/tests/qc/test_cells_standard_error.py +++ b/tests/qc/test_cells_standard_error.py @@ -1,12 +1,14 @@ """Test standard error values.""" from random import randint - +import pytest from hypothesis import given from hypothesis import strategies as st from quality_control.standard_error import invalid_value +@pytest.mark.skip(reason=("Checks changed. We now enforce values must have at " + "least one decimal place")) @given(num_str=st.from_regex(r"^[0-9]+\.?0*", fullmatch=True)) def test_cell_standard_error_value_errors_if_less_than_six_decimal_places2(num_str): """ -- cgit v1.2.3