# Path: athlib/uka/agegroups.py
# def calc_uka_age_group(birth_date,
#                        match_date,
#                        category,
#                        vets=True,
#                        underage=False):
#     """Return UKA age group"""
#     if category == 'TF':
#         return rule107_agegroups_trackandfield(birth_date,
#                                                match_date,
#                                                vets=vets,
#                                                underage=underage)
#     elif category in ['ROAD', 'XC']:
#         return rule507_agegroups_crosscountry(birth_date,
#                                               match_date,
#                                               vets=vets,
#                                               underage=underage)
#     elif category == 'ESAA':
#         # Apparently the English Schools has its own rule, but we haven't done
#         # this yet. If still here, raise an exception
#         raise NotImplementedError
#     else:
#         raise ValueError("category must be one of:  TF, ROAD, XC, ESAA")
# 
# def prior_date(match_date, cutoff_month, cutoff_day):
#     """
#     Count back to relevant date.
#     e.g. find the 31st August prior to match date
#     """
#     y = match_date.year
#     m = match_date.month
#     d = match_date.day
#     x = date(y, cutoff_month, cutoff_day)
#     if x > match_date:
#         x = date(y - 1, cutoff_month, cutoff_day)
#     return x


from dateutil.parser import parse as parse_date
from datetime import date
from unittest import TestCase, main
from athlib.uka.agegroups import calc_uka_age_group, prior_date
        self.assertAgeGroup(date(1998, 9, 8), date(2015, 9, 30), "XC", "U17")
        # self.assertAgeGroup(date(2008, 1, 3), date(2015, 1, 3),"XC", "U11")
        # self.assertAgeGroup(date(2002, 10, 10), date(2014, 1, 3),"XC", "U13")

        # Two actual errors from Surrey XC where we had a cutoff date of 30 Sep
        self.assertAgeGroup(date(1994, 9, 29), date(2015, 1, 3), "XC", "U20")
        self.assertAgeGroup(date(1997, 9, 1), date(2015, 1, 3), "XC", "U17")

        # 30th September is considered start of season
        # 29th September is considered end of season

    def test_track_and_field(self):
        """Examples provided by Nicola Fleet of Surrey AAA"""
        samples = """
            1/1/1994    14/2/2015   SEN
            31/8/1994   14/2/2015   SEN
            1/9/1994    14/2/2015   SEN
            30/9/1994   14/2/2015   SEN
            1/10/1994   14/2/2015   SEN
            31/12/1994  14/2/2015   SEN

            1/1/1995    14/2/2015   SEN
            31/8/1995   14/2/2015   SEN
            1/9/1995    14/2/2015   SEN
            30/9/1995   14/2/2015   SEN
            1/10/1995   14/2/2015   SEN
            31/12/1995  14/2/2015   SEN

            1/1/1996    14/2/2015   U20
            31/8/1996   14/2/2015   U20

# Path: athlib/uka/agegroups.py
# def calc_uka_age_group(birth_date,
#                        match_date,
#                        category,
#                        vets=True,
#                        underage=False):
#     """Return UKA age group"""
#     if category == 'TF':
#         return rule107_agegroups_trackandfield(birth_date,
#                                                match_date,
#                                                vets=vets,
#                                                underage=underage)
#     elif category in ['ROAD', 'XC']:
#         return rule507_agegroups_crosscountry(birth_date,
#                                               match_date,
#                                               vets=vets,
#                                               underage=underage)
#     elif category == 'ESAA':
#         # Apparently the English Schools has its own rule, but we haven't done
#         # this yet. If still here, raise an exception
#         raise NotImplementedError
#     else:
#         raise ValueError("category must be one of:  TF, ROAD, XC, ESAA")
# 
# def prior_date(match_date, cutoff_month, cutoff_day):
#     """
#     Count back to relevant date.
#     e.g. find the 31st August prior to match date
#     """
#     y = match_date.year
#     m = match_date.month
#     d = match_date.day
#     x = date(y, cutoff_month, cutoff_day)
#     if x > match_date:
#         x = date(y - 1, cutoff_month, cutoff_day)
#     return x


# Path: tests/test_agegroups.py
from dateutil.parser import parse as parse_date
from datetime import date
from unittest import TestCase, main
from athlib.uka.agegroups import calc_uka_age_group, prior_date

        self.assertAgeGroup(date(1998, 9, 8), date(2015, 9, 30), "XC", "U17")
        # self.assertAgeGroup(date(2008, 1, 3), date(2015, 1, 3),"XC", "U11")
        # self.assertAgeGroup(date(2002, 10, 10), date(2014, 1, 3),"XC", "U13")

        # Two actual errors from Surrey XC where we had a cutoff date of 30 Sep
        self.assertAgeGroup(date(1994, 9, 29), date(2015, 1, 3), "XC", "U20")
        self.assertAgeGroup(date(1997, 9, 1), date(2015, 1, 3), "XC", "U17")

        # 30th September is considered start of season
        # 29th September is considered end of season

    def test_track_and_field(self):
        """Examples provided by Nicola Fleet of Surrey AAA"""
        samples = """
            1/1/1994    14/2/2015   SEN
            31/8/1994   14/2/2015   SEN
            1/9/1994    14/2/2015   SEN
            30/9/1994   14/2/2015   SEN
            1/10/1994   14/2/2015   SEN
            31/12/1994  14/2/2015   SEN

            1/1/1995    14/2/2015   SEN
            31/8/1995   14/2/2015   SEN
            1/9/1995    14/2/2015   SEN
            30/9/1995   14/2/2015   SEN
            1/10/1995   14/2/2015   SEN
            31/12/1995  14/2/2015   SEN

            1/1/1996    14/2/2015   U20
            31/8/1996   14/2/2015   U20

            1/9/1996    14/2/2015   U20