Skip to content

Commit fb81c76

Browse files
committed
Add indirect tests for _s_bar via arrow_score function
1 parent ea6c3e7 commit fb81c76

File tree

3 files changed

+68
-1
lines changed

3 files changed

+68
-1
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
setattr(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:
@@ -374,6 +382,51 @@ def test_different_target_faces(
374382

375383
assert arrow_score_direct == pytest.approx(arrow_score_expected)
376384

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

378431
class TestScoreForPasses:
379432
"""
@@ -582,6 +635,13 @@ def test_rounded_round_score(
582635
hc_sys.score_for_round(20.0, test_round, None, True) == round_score_expected
583636
)
584637

638+
def test_calculation_custom_scoring(self):
639+
"""
640+
Check that score can be calculated for a round with custom scoring
641+
"""
642+
643+
assert hc.score_for_round(20.0, kings_900_rec, "AGB", None, True) == 896.0
644+
585645

586646
class TestHandicapFromScore:
587647
"""
@@ -835,3 +895,10 @@ def test_decimal(
835895
)
836896

837897
assert handicap == pytest.approx(handicap_expected)
898+
899+
def test_calculation_custom_scoring(self):
900+
"""
901+
Check that handicap can be calculated for a round with custom scoring
902+
"""
903+
904+
assert hc.handicap_from_score(896, kings_900_rec, "AGB", int_prec=True) == 20

archeryutils/targets.py

-1
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,6 @@ def get_face_spec(self) -> FaceSpec:
347347
spec : dict
348348
Mapping of target ring sizes in [metres] to score
349349
"""
350-
351350
system = self.scoring_system
352351
tar_dia = self.diameter
353352

0 commit comments

Comments
 (0)