|
73 | 73 | Pass.at_target(36, "10_zone", 122, 30, False),
|
74 | 74 | ],
|
75 | 75 | )
|
| 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 | +) |
76 | 84 |
|
77 | 85 |
|
78 | 86 | class TestHandicapScheme:
|
@@ -374,6 +382,51 @@ def test_different_target_faces(
|
374 | 382 |
|
375 | 383 | assert arrow_score_direct == pytest.approx(arrow_score_expected)
|
376 | 384 |
|
| 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 | + |
377 | 430 |
|
378 | 431 | class TestScoreForPasses:
|
379 | 432 | """
|
@@ -582,6 +635,13 @@ def test_rounded_round_score(
|
582 | 635 | hc_sys.score_for_round(20.0, test_round, None, True) == round_score_expected
|
583 | 636 | )
|
584 | 637 |
|
| 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 | + |
585 | 645 |
|
586 | 646 | class TestHandicapFromScore:
|
587 | 647 | """
|
@@ -835,3 +895,10 @@ def test_decimal(
|
835 | 895 | )
|
836 | 896 |
|
837 | 897 | 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 |
0 commit comments