# 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

class SimpleTest(TestCase):

    def test_basic_addition(self):
        """Tests that 1 + 1 always equals 2."""
        self.assertEqual(1 + 1, 2)


class AgeGroupTests(TestCase):

    def assertAgeGroup(self, dob, match_date, category, expected,
                       vets=True, underage=False):
        ag = calc_uka_age_group(dob, match_date, category,
                                vets=vets, underage=underage)
        self.assertEqual(ag,
                          expected,
                          ("Unexpected age group, expected %s but got %s" %
                           (expected, ag)))

    def test_cat_check(self):
        self.assertRaises(Exception,
                          calc_uka_age_group,
                          date(1966, 1, 1),
                          date(2015, 1, 3),
                          "FOO")

    def test_cutoff_date(self):
        self.assertEqual(prior_date(date(2015, 1, 3), 8, 31),
                          date(2014, 8, 31))


# 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


class SimpleTest(TestCase):

    def test_basic_addition(self):
        """Tests that 1 + 1 always equals 2."""
        self.assertEqual(1 + 1, 2)


class AgeGroupTests(TestCase):

    def assertAgeGroup(self, dob, match_date, category, expected,
                       vets=True, underage=False):
        ag = calc_uka_age_group(dob, match_date, category,
                                vets=vets, underage=underage)
        self.assertEqual(ag,
                          expected,
                          ("Unexpected age group, expected %s but got %s" %
                           (expected, ag)))

    def test_cat_check(self):
        self.assertRaises(Exception,
                          calc_uka_age_group,
                          date(1966, 1, 1),
                          date(2015, 1, 3),
                          "FOO")

    def test_cutoff_date(self):
        self.assertEqual(prior_date(date(2015, 1, 3), 8, 31),
                          date(2014, 8, 31))


        self.assertEqual(prior_date(date(2014, 9, 30), 8, 31),