# Path: athlib/highjump.py
# class Jumper(object):
# class TrialObj(dict):
# class HighJumpCompetition(object):
#     def __init__(self, **kwargs):
#     def _set_jump_array(self, height_count: int, label : str = 'jump') -> None:
#     def has_retired(self):
#     def ranking_key(self) -> Tuple[int, Decimal, int, int]:
#     def cleared(self, height_count: int, height: Decimal) -> None:
#     def failed(self, height_count: int, height: Decimal) -> None:
#     def passed(self, height_count: int, height: Decimal) -> None:
#     def retired(self, height_count: int, height: Decimal) -> None:
#     def __init__(self, *args, **kwargs):
#     def __init__(self):
#     def add_jumper(self, **kwargs) -> None:
#     def set_bar_height(self, new_height: Decimal) -> None:
#     def check_started(self, bib: str, label: str = 'jumping') -> Jumper:
#     def cleared(self, bib: str) -> None:
#     def failed(self, bib: str) -> None:
#     def passed(self, bib: str) -> None:
#     def retired(self, bib: str) -> None:
#     def trials(self) -> List[Tuple[str, Decimal, str]]:
#     def trial_objs(self) -> List[TrialObj]:
#     def remaining(self) -> List[Jumper]:
#     def eliminated(self) -> List[Jumper]:
#     def _rankj(self) -> List[Jumper]:
#     def _rank(self, verbose: bool = False) -> None:
#     def bib_trial(self, bib: str, trial: str) -> None:
#     def from_matrix(cls, matrix: List[List[str]], to_nth_height: int = None, verbose: bool = False) -> HighJumpCompetition:
#     def _looks_like_height(self, txt:str) -> bool:
#     def _ensure_dicts_ordered(self, dikts: List[Dict[str, str]]) -> None:
#     def print_ranking(self):
#     def from_actions(self, actions: List[Tuple] = None) -> HighJumpCompetition:
#     def to_matrix(self, keys: List[str] = []) -> List[List[str]]:
#     def is_finished(self) -> bool:
#     def is_running(self) -> bool:
#         T = []
#         R = [keys + ['%.2f'%h for h in self.heights]]
#         J = sorted([([getattr(j,k) for k in keys],j) for j in self.ranked_jumpers])
# 
# Path: athlib/exceptions.py
# class RuleViolation(Exception):
#     """Exception to indicate incorrect athletics logic
# 
#     This may be used if, for example, there is a fourth
#     attempt at a high jump.  We use this as a form of
#     assertion within the code; others are welcome to as well.
#     """
#     pass


from unittest import TestCase, main
from decimal import Decimal
from athlib.highjump import HighJumpCompetition, _012
from athlib.exceptions import RuleViolation
        # print grimsey.failures_at_height
        # print grimsey.consecutive_failures
        # print grimsey.attempts_by_height
        # if not for jump-off rules, it would be game over
        self.assertEqual(len(c.remaining), 2)
        self.assertEqual(c.state, 'jumpoff')

    def test_replay_through_jumpoff(self):
        "Run through a jumpoff to a draw"
        c = HighJumpCompetition.from_matrix(ESAA_2015_HJ)
        self.assertRaises(RuleViolation,c.failed,'53')

        # see who is winning
        maslen = c.jumpers_by_bib['85']
        field = c.jumpers_by_bib['77']
        grimsey = c.jumpers_by_bib['53']
        dwyer = c.jumpers_by_bib['81']

        self.assertEqual(field.place, 4)
        self.assertEqual(maslen.place, 3)

        self.assertEqual(grimsey.place, 1)
        self.assertEqual(dwyer.place, 1)

        self.assertEqual(len(c.remaining), 2)
        self.assertEqual(c.state, 'jumpoff')

    def test_replay_jumpoff_and_finish(self):
        "Run through a jumpoff to the final winner"
        c = HighJumpCompetition.from_matrix(_1066)

# Path: athlib/highjump.py
# class Jumper(object):
# class TrialObj(dict):
# class HighJumpCompetition(object):
#     def __init__(self, **kwargs):
#     def _set_jump_array(self, height_count: int, label : str = 'jump') -> None:
#     def has_retired(self):
#     def ranking_key(self) -> Tuple[int, Decimal, int, int]:
#     def cleared(self, height_count: int, height: Decimal) -> None:
#     def failed(self, height_count: int, height: Decimal) -> None:
#     def passed(self, height_count: int, height: Decimal) -> None:
#     def retired(self, height_count: int, height: Decimal) -> None:
#     def __init__(self, *args, **kwargs):
#     def __init__(self):
#     def add_jumper(self, **kwargs) -> None:
#     def set_bar_height(self, new_height: Decimal) -> None:
#     def check_started(self, bib: str, label: str = 'jumping') -> Jumper:
#     def cleared(self, bib: str) -> None:
#     def failed(self, bib: str) -> None:
#     def passed(self, bib: str) -> None:
#     def retired(self, bib: str) -> None:
#     def trials(self) -> List[Tuple[str, Decimal, str]]:
#     def trial_objs(self) -> List[TrialObj]:
#     def remaining(self) -> List[Jumper]:
#     def eliminated(self) -> List[Jumper]:
#     def _rankj(self) -> List[Jumper]:
#     def _rank(self, verbose: bool = False) -> None:
#     def bib_trial(self, bib: str, trial: str) -> None:
#     def from_matrix(cls, matrix: List[List[str]], to_nth_height: int = None, verbose: bool = False) -> HighJumpCompetition:
#     def _looks_like_height(self, txt:str) -> bool:
#     def _ensure_dicts_ordered(self, dikts: List[Dict[str, str]]) -> None:
#     def print_ranking(self):
#     def from_actions(self, actions: List[Tuple] = None) -> HighJumpCompetition:
#     def to_matrix(self, keys: List[str] = []) -> List[List[str]]:
#     def is_finished(self) -> bool:
#     def is_running(self) -> bool:
#         T = []
#         R = [keys + ['%.2f'%h for h in self.heights]]
#         J = sorted([([getattr(j,k) for k in keys],j) for j in self.ranked_jumpers])
# 
# Path: athlib/exceptions.py
# class RuleViolation(Exception):
#     """Exception to indicate incorrect athletics logic
# 
#     This may be used if, for example, there is a fourth
#     attempt at a high jump.  We use this as a form of
#     assertion within the code; others are welcome to as well.
#     """
#     pass


# Path: tests/test_highjump.py
from unittest import TestCase, main
from decimal import Decimal
from athlib.highjump import HighJumpCompetition, _012
from athlib.exceptions import RuleViolation

        # print grimsey.failures_at_height
        # print grimsey.consecutive_failures
        # print grimsey.attempts_by_height
        # if not for jump-off rules, it would be game over
        self.assertEqual(len(c.remaining), 2)
        self.assertEqual(c.state, 'jumpoff')

    def test_replay_through_jumpoff(self):
        "Run through a jumpoff to a draw"
        c = HighJumpCompetition.from_matrix(ESAA_2015_HJ)
        self.assertRaises(RuleViolation,c.failed,'53')

        # see who is winning
        maslen = c.jumpers_by_bib['85']
        field = c.jumpers_by_bib['77']
        grimsey = c.jumpers_by_bib['53']
        dwyer = c.jumpers_by_bib['81']

        self.assertEqual(field.place, 4)
        self.assertEqual(maslen.place, 3)

        self.assertEqual(grimsey.place, 1)
        self.assertEqual(dwyer.place, 1)

        self.assertEqual(len(c.remaining), 2)
        self.assertEqual(c.state, 'jumpoff')

    def test_replay_jumpoff_and_finish(self):
        "Run through a jumpoff to the final winner"
        c = HighJumpCompetition.from_matrix(_1066)

        self.assertRaises(RuleViolation,c.failed,'53')