|
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:
|
@@ -376,6 +384,51 @@ def test_different_target_faces(
|
376 | 384 |
|
377 | 385 | assert arrow_score_direct == pytest.approx(arrow_score_expected)
|
378 | 386 |
|
| 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 | + |
379 | 432 |
|
380 | 433 | class TestScoreForPasses:
|
381 | 434 | """
|
@@ -598,6 +651,13 @@ def test_rounded_round_score(
|
598 | 651 | hc_sys.score_for_round(20.0, test_round, None, True) == round_score_expected
|
599 | 652 | )
|
600 | 653 |
|
| 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 | + |
601 | 661 |
|
602 | 662 | class TestHandicapFromScore:
|
603 | 663 | """
|
@@ -851,3 +911,10 @@ def test_decimal(
|
851 | 911 | )
|
852 | 912 |
|
853 | 913 | 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