From dec4db8e9effc5d991c27be0725f9b4a3ae1b51e Mon Sep 17 00:00:00 2001 From: jatkinson1000 <109271713+jatkinson1000@users.noreply.github.com> Date: Thu, 24 Aug 2023 22:02:59 +0100 Subject: [PATCH] Add tests for classification utilities. --- .../tests/test_classification_utils.py | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 archeryutils/classifications/tests/test_classification_utils.py diff --git a/archeryutils/classifications/tests/test_classification_utils.py b/archeryutils/classifications/tests/test_classification_utils.py new file mode 100644 index 0000000..e1c27d9 --- /dev/null +++ b/archeryutils/classifications/tests/test_classification_utils.py @@ -0,0 +1,69 @@ +"""Tests for classification utilities""" +import pytest + +import archeryutils.classifications.classification_utils as class_utils + + +class TestStringUtils: + """ + Class to test the get_groupname() function of handicap_equations. + + Methods + ------- + test_get_groupname() + test if expected sanitised groupname returned + test_strip_spots() + test if expected full-face roundname returned + """ + + @pytest.mark.parametrize( + "bowstyle,age_group,gender,groupname_expected", + # Check all systems, different distances, negative and large handicaps. + [ + ("barebow", "adult", "male", "adult_male_barebow"), + ("Barebow", "Adult", "Male", "adult_male_barebow"), + ("Barebow", "Under 18", "Male", "under18_male_barebow"), + ("RECURVE", "UnDeR 18", "femaLe", "under18_female_recurve"), + ], + ) + def test_get_groupname( + self, + age_group: str, + gender: str, + bowstyle: str, + groupname_expected: str, + ) -> None: + """ + Check that get_groupname(handicap=float) returns expected value for a case. + """ + groupname = class_utils.get_groupname( + bowstyle=bowstyle, + gender=gender, + age_group=age_group, + ) + + assert groupname == groupname_expected + + @pytest.mark.parametrize( + "roundname,strippedname_expected", + # Check all systems, different distances, negative and large handicaps. + [ + ("portsmouth", "portsmouth"), + ("portsmouth_triple", "portsmouth"), + ("portsmouth_compound", "portsmouth_compound"), + ("portsmouth_compound_triple", "portsmouth_compound"), + ("portsmouth_triple_compound", "portsmouth_compound"), + ("worcester_5_centre", "worcester"), + ], + ) + def test_strip_spots( + self, + roundname: str, + strippedname_expected: str, + ) -> None: + """ + Check that strip_spots() returns expected value for a round. + """ + strippedname = class_utils.strip_spots(roundname) + + assert strippedname == strippedname_expected