# Path: athlib/hungarian_score.py
# def get_lookup_table():
#     global _table
#     if _table is None:
#         _table = {}
#         for (gender, inout, event_code, a, b, c) in FACTORS:
#             key = (gender, inout, event_code)
#             value = (a,b,c)
#             _table[key] = value
#     return _table
# 
# def score(gender, inout, event_code, performance):
#     "Return IAAF (Hungarian) points, or raise AssertionError"
#     assert inout in ('IND', 'OUT'), "Must specify indoor (IN) or outdoor (OUT)"
#     assert gender in 'MFX', "Gender must be M , F or X. X will be looked up in Male points tables!"
#     ec = check_event_code(event_code)
#     assert ec is not None, "Unrecognised event code %s" % event_code
# 
# 
#     key = (gender, inout, event_code)
#     tbl = get_lookup_table()
#     (a,b,c) = tbl[key]
# 
#     # b = performance in m or sec that gets no points.  (Slower would be an input error!)
#     #     Points grow quadratically above it
#     # a = multiplier to get all events onto a similar scale
#     # c = points shift applied at the end
# 
#     # to do:  if performance is worse than a, should get zero points.  e.g. 20 second 100m
# 
# 
#     return floor(a * (performance + b)**2 + c) 


from unittest import TestCase, main
from athlib.hungarian_score import get_lookup_table, score



class HunTest(TestCase):

    def test_table_lookup(self):
        """Just verify we pasted the right factors, some sources are rounded off"""

        tbl = get_lookup_table()
        inputs = ('M', 'OUT', '200')
        values = tbl[inputs]
        self.assertEquals(values, (5.08, -35.5, 0))


    def test_scores(self):

        tests = [
                ('M', 'OUT', '100', 9.46, 1400),
                ('M', 'OUT', 'MILE', 240, 1074),
                ('F', 'OUT', 'LJ', 7.50, 1329), 
                ('M', 'IND', 'SP', 20.00, 1121),
            ]

        for test in tests:
            (gender, inout, event_code, performance, points) = test
            self.assertEquals(

# Path: athlib/hungarian_score.py
# def get_lookup_table():
#     global _table
#     if _table is None:
#         _table = {}
#         for (gender, inout, event_code, a, b, c) in FACTORS:
#             key = (gender, inout, event_code)
#             value = (a,b,c)
#             _table[key] = value
#     return _table
# 
# def score(gender, inout, event_code, performance):
#     "Return IAAF (Hungarian) points, or raise AssertionError"
#     assert inout in ('IND', 'OUT'), "Must specify indoor (IN) or outdoor (OUT)"
#     assert gender in 'MFX', "Gender must be M , F or X. X will be looked up in Male points tables!"
#     ec = check_event_code(event_code)
#     assert ec is not None, "Unrecognised event code %s" % event_code
# 
# 
#     key = (gender, inout, event_code)
#     tbl = get_lookup_table()
#     (a,b,c) = tbl[key]
# 
#     # b = performance in m or sec that gets no points.  (Slower would be an input error!)
#     #     Points grow quadratically above it
#     # a = multiplier to get all events onto a similar scale
#     # c = points shift applied at the end
# 
#     # to do:  if performance is worse than a, should get zero points.  e.g. 20 second 100m
# 
# 
#     return floor(a * (performance + b)**2 + c) 


# Path: tests/test_hungarian_score.py
from unittest import TestCase, main
from athlib.hungarian_score import get_lookup_table, score




class HunTest(TestCase):

    def test_table_lookup(self):
        """Just verify we pasted the right factors, some sources are rounded off"""

        tbl = get_lookup_table()
        inputs = ('M', 'OUT', '200')
        values = tbl[inputs]
        self.assertEquals(values, (5.08, -35.5, 0))


    def test_scores(self):

        tests = [
                ('M', 'OUT', '100', 9.46, 1400),
                ('M', 'OUT', 'MILE', 240, 1074),
                ('F', 'OUT', 'LJ', 7.50, 1329), 
                ('M', 'IND', 'SP', 20.00, 1121),
            ]

        for test in tests:
            (gender, inout, event_code, performance, points) = test
            self.assertEquals(

                score(gender, inout, event_code, performance), 