aboutsummaryrefslogtreecommitdiff
path: root/tests/qc/test_checks.py
blob: e91cd1907d4d983a63a4f443bdc86988b8c0638e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"""Test that the checks run correct."""
import pytest
from hypothesis import given
from hypothesis import strategies as st

from quality_control.checks import decimal_places_pattern

@pytest.mark.unit_test
@given(numstr=st.from_regex(r"^[0-9]+$", fullmatch=True))
def test_matches_whole_numbers(numstr):
    """
    GIVEN: 'numstr' is an arbitrary string that represents a whole number,
        e.g. 45342
    WHEN: We test for a match made by 'decimal_places_pattern'
    THEN: The string in 'numstr' always matches.
    """
    assert bool(decimal_places_pattern(3, 6).search(numstr))

@pytest.mark.unit_test
@given(numstr=st.from_regex(r"^0+\.?0*$", fullmatch=True))
def test_matches_zeroes(numstr):
    """
    GIVEN: 'numstr' is an arbitrary string that represents zero,
        e.g. 0, 00, 000, 0.0, 00.00, 000.0
    WHEN: We test for a match made by 'decimal_places_pattern'
    THEN: The string in 'numstr' always matches.
    """
    assert bool(decimal_places_pattern(3, 6).search(numstr))

@pytest.mark.unit_test
@given(numstr=st.from_regex(r"^[0-9]+\.[1-9]{1,5}$", fullmatch=True))
def test_does_not_match_fewer_decimal_places(numstr):
    """
    GIVEN: 'numstr' is an arbitrary string that represents a non-whole decimal
        number with fewer decimal places than allowed
    WHEN: We test for a match made by 'decimal_places_pattern'
    THEN: The string in 'numstr' always fails to match
    """
    assert decimal_places_pattern(6).match(numstr) is None

@pytest.mark.unit_test
@given(numstr=st.from_regex(r"^[0-9]+\.[1-9]{7}$", fullmatch=True))
def test_does_not_match_more_decimal_places(numstr):
    """
    GIVEN: 'numstr' is an arbitrary string that represents a non-whole decimal
        number with more decimal places than allowed
    WHEN: We test for a match made by 'decimal_places_pattern'
    THEN: The string in 'numstr' always fails to match
    """
    assert decimal_places_pattern(3, 6).match(numstr) is None