Skip to content

Commit cb51a10

Browse files
committed
Add indirect tests for _s_bar via arrow_score function
1 parent 8b9c6c4 commit cb51a10

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

archeryutils/handicaps/handicap_scheme.py

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ def _pairwise(iterable):
5555

5656
itr.pairwise = _pairwise
5757

58+
5859
class HandicapScheme(ABC):
5960
r"""
6061
Abstract Base Class to represent a generic handicap scheme.

archeryutils/handicaps/tests/test_handicaps.py

+67
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@
7373
Pass.at_target(36, "10_zone", 122, 30, False),
7474
],
7575
)
76+
kings_900_rec = Round(
77+
"Kings 900 (recurve)",
78+
[
79+
Pass(30, Target.from_spec({0.08: 10, 0.12: 8, 0.16: 7, 0.20: 6}, 40, 18, True)),
80+
Pass(30, Target.from_spec({0.08: 10, 0.12: 8, 0.16: 7, 0.20: 6}, 40, 18, True)),
81+
Pass(30, Target.from_spec({0.08: 10, 0.12: 8, 0.16: 7, 0.20: 6}, 40, 18, True)),
82+
],
83+
)
7684

7785

7886
class TestHandicapScheme:
@@ -376,6 +384,51 @@ def test_different_target_faces(
376384

377385
assert arrow_score_direct == pytest.approx(arrow_score_expected)
378386

387+
def test_empty_spec(self):
388+
"""
389+
Check expected score is zero when no target rings are defined.
390+
"""
391+
target = Target.from_spec({}, 10, 10)
392+
s_bar = hc.arrow_score(50, target, "AGB")
393+
assert s_bar == 0
394+
395+
def test_unsorted_spec(self):
396+
"""
397+
Check expected score is insensitive to order of input spec.
398+
"""
399+
400+
def _target(spec):
401+
return Target.from_spec(spec, 10, 10)
402+
403+
s_bar = hc.arrow_score(50, _target({0.1: 1, 0.2: 2, 0.3: 3}), "AA")
404+
s_bar_reversed = hc.arrow_score(50, _target({0.3: 3, 0.2: 2, 0.1: 1}), "AA")
405+
s_bar_unordered = hc.arrow_score(50, _target({0.1: 1, 0.3: 3, 0.2: 2}), "AA")
406+
407+
assert s_bar_unordered == s_bar_reversed == s_bar
408+
409+
def test_decimal_ring_scores(self):
410+
"""
411+
Check expected score can be calculated for non integer ring scores
412+
413+
Uses a target with integer ring scores at twice the value for comparison
414+
"""
415+
target_int = Target.from_spec({0.1: 3, 0.2: 5}, 10, 10)
416+
target_dec = Target.from_spec({0.1: 1.5, 0.2: 2.5}, 10, 10)
417+
418+
s_bar_int = hc.arrow_score(30, target_int, "AGB")
419+
s_bar_dec = hc.arrow_score(30, target_dec, "AGB")
420+
421+
assert s_bar_int == 2 * s_bar_dec
422+
423+
def test_array_handicaps(self):
424+
"""
425+
Check expected score can be calculated for an array of input handicap values
426+
"""
427+
handicaps = np.array([10, 20, 30, 40])
428+
target = Target.from_spec({0.1: 3, 0.2: 5}, 10, 10)
429+
s_bar = hc.arrow_score(handicaps, target, "AGB")
430+
assert len(s_bar) == len(handicaps)
431+
379432

380433
class TestScoreForPasses:
381434
"""
@@ -598,6 +651,13 @@ def test_rounded_round_score(
598651
hc_sys.score_for_round(20.0, test_round, None, True) == round_score_expected
599652
)
600653

654+
def test_calculation_custom_scoring(self):
655+
"""
656+
Check that score can be calculated for a round with custom scoring
657+
"""
658+
659+
assert hc.score_for_round(20.0, kings_900_rec, "AGB", None, True) == 896.0
660+
601661

602662
class TestHandicapFromScore:
603663
"""
@@ -851,3 +911,10 @@ def test_decimal(
851911
)
852912

853913
assert handicap == pytest.approx(handicap_expected)
914+
915+
def test_calculation_custom_scoring(self):
916+
"""
917+
Check that handicap can be calculated for a round with custom scoring
918+
"""
919+
920+
assert hc.handicap_from_score(896, kings_900_rec, "AGB", int_prec=True) == 20

0 commit comments

Comments
 (0)