Skip to content

Commit

Permalink
Update Pass, load_rounds and test_cases to assume cm as default targe…
Browse files Browse the repository at this point in the history
…t diameter
  • Loading branch information
TomHall2020 committed Jan 10, 2024
1 parent e411b81 commit 5dc07fc
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 73 deletions.
22 changes: 11 additions & 11 deletions archeryutils/handicaps/tests/test_handicap_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,39 @@
# pylint: disable=duplicate-code

from typing import Union

import numpy as np
from numpy.typing import NDArray
import pytest
from numpy.typing import NDArray

import archeryutils.handicaps.handicap_equations as hc_eq
import archeryutils.handicaps.handicap_functions as hc_func
from archeryutils.rounds import Round, Pass

from archeryutils.rounds import Pass, Round

hc_params = hc_eq.HcParams()

# Define rounds used in these functions
york = Round(
"York",
[
Pass(72, 1.22, "5_zone", 100, "yard", False),
Pass(48, 1.22, "5_zone", 80, "yard", False),
Pass(24, 1.22, "5_zone", 60, "yard", False),
Pass(72, 122, "5_zone", 100, "yard", False),
Pass(48, 122, "5_zone", 80, "yard", False),
Pass(24, 122, "5_zone", 60, "yard", False),
],
)
hereford = Round(
"Hereford",
[
Pass(72, 1.22, "5_zone", 80, "yard", False),
Pass(48, 1.22, "5_zone", 60, "yard", False),
Pass(24, 1.22, "5_zone", 50, "yard", False),
Pass(72, 122, "5_zone", 80, "yard", False),
Pass(48, 122, "5_zone", 60, "yard", False),
Pass(24, 122, "5_zone", 50, "yard", False),
],
)
metric122_30 = Round(
"Metric 122-30",
[
Pass(36, 1.22, "10_zone", 30, "metre", False),
Pass(36, 1.22, "10_zone", 30, "metre", False),
Pass(36, 122, "10_zone", 30, "metre", False),
Pass(36, 122, "10_zone", 30, "metre", False),
],
)

Expand Down
76 changes: 38 additions & 38 deletions archeryutils/handicaps/tests/test_handicaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,79 +3,79 @@
# => disable for handicap tests
# pylint: disable=duplicate-code

from typing import Tuple, List
from typing import List, Tuple

import numpy as np
import pytest
from pytest_mock import MockerFixture

import archeryutils.handicaps.handicap_equations as hc_eq
import archeryutils.handicaps.handicap_functions as hc_func
from archeryutils.rounds import Pass, Round
from archeryutils.targets import Target
from archeryutils.rounds import Round, Pass


hc_params = hc_eq.HcParams()

# Define rounds used in these functions
york = Round(
"York",
[
Pass(72, 1.22, "5_zone", 100, "yard", False),
Pass(48, 1.22, "5_zone", 80, "yard", False),
Pass(24, 1.22, "5_zone", 60, "yard", False),
Pass(72, 122, "5_zone", 100, "yard", False),
Pass(48, 122, "5_zone", 80, "yard", False),
Pass(24, 122, "5_zone", 60, "yard", False),
],
)
hereford = Round(
"Hereford",
[
Pass(72, 1.22, "5_zone", 80, "yard", False),
Pass(48, 1.22, "5_zone", 60, "yard", False),
Pass(24, 1.22, "5_zone", 50, "yard", False),
Pass(72, 122, "5_zone", 80, "yard", False),
Pass(48, 122, "5_zone", 60, "yard", False),
Pass(24, 122, "5_zone", 50, "yard", False),
],
)
western = Round(
"Western",
[
Pass(48, 1.22, "5_zone", 60, "yard", False),
Pass(48, 1.22, "5_zone", 50, "yard", False),
Pass(48, 122, "5_zone", 60, "yard", False),
Pass(48, 122, "5_zone", 50, "yard", False),
],
)
vegas300 = Round(
"Vegas 300",
[
Pass(30, 0.4, "10_zone", 20, "yard", True),
Pass(30, 40, "10_zone", 20, "yard", True),
],
)
wa1440_90 = Round(
"WA1440 90m",
[
Pass(36, 1.22, "10_zone", 90, "metre", False),
Pass(36, 1.22, "10_zone", 70, "metre", False),
Pass(36, 0.8, "10_zone", 50, "metre", False),
Pass(36, 0.8, "10_zone", 30, "metre", False),
Pass(36, 122, "10_zone", 90, "metre", False),
Pass(36, 122, "10_zone", 70, "metre", False),
Pass(36, 80, "10_zone", 50, "metre", False),
Pass(36, 80, "10_zone", 30, "metre", False),
],
)
wa1440_70 = Round(
"WA1440 70m",
[
Pass(36, 1.22, "10_zone", 70, "metre", False),
Pass(36, 1.22, "10_zone", 60, "metre", False),
Pass(36, 0.8, "10_zone", 50, "metre", False),
Pass(36, 0.8, "10_zone", 30, "metre", False),
Pass(36, 122, "10_zone", 70, "metre", False),
Pass(36, 122, "10_zone", 60, "metre", False),
Pass(36, 80, "10_zone", 50, "metre", False),
Pass(36, 80, "10_zone", 30, "metre", False),
],
)
wa720_70 = Round(
"WA 720 70m",
[
Pass(36, 1.22, "10_zone", 70, "metre", False),
Pass(36, 1.22, "10_zone", 70, "metre", False),
Pass(36, 122, "10_zone", 70, "metre", False),
Pass(36, 122, "10_zone", 70, "metre", False),
],
)
metric122_30 = Round(
"Metric 122-30",
[
Pass(36, 1.22, "10_zone", 30, "metre", False),
Pass(36, 1.22, "10_zone", 30, "metre", False),
Pass(36, 122, "10_zone", 30, "metre", False),
Pass(36, 122, "10_zone", 30, "metre", False),
],
)

Expand Down Expand Up @@ -387,7 +387,7 @@ def test_different_handicap_systems(
"""
arrow_score = hc_eq.arrow_score(
target=Target(0.40, "10_zone_5_ring_compound", 20.0, "metre", indoor),
target=Target(40, "10_zone_5_ring_compound", 20.0, "metre", indoor),
handicap=20.0,
hc_sys=hc_system,
hc_dat=hc_params,
Expand Down Expand Up @@ -420,7 +420,7 @@ def test_different_target_faces(
Check correct arrow scores returned for different target faces
"""
arrow_score = hc_eq.arrow_score(
target=Target(0.80, target_face, 50.0, "metre", False),
target=Target(80, target_face, 50.0, "metre", False),
handicap=38.0,
hc_sys="AGB",
hc_dat=hc_params,
Expand Down Expand Up @@ -490,9 +490,9 @@ def test_float_round_score(
test_round = Round(
"MyRound",
[
Pass(10, 1.22, "10_zone", 100, "metre", False),
Pass(10, 0.80, "10_zone", 80, "metre", False),
Pass(10, 1.22, "5_zone", 60, "metre", False),
Pass(10, 122, "10_zone", 100, "metre", False),
Pass(10, 80, "10_zone", 80, "metre", False),
Pass(10, 122, "5_zone", 60, "metre", False),
],
)

Expand Down Expand Up @@ -525,9 +525,9 @@ def test_rounded_round_score(
test_round = Round(
"MyRound",
[
Pass(10, 1.22, "10_zone", 100, "metre", False),
Pass(10, 0.80, "10_zone", 80, "metre", False),
Pass(10, 1.22, "5_zone", 60, "metre", False),
Pass(10, 122, "10_zone", 100, "metre", False),
Pass(10, 80, "10_zone", 80, "metre", False),
Pass(10, 122, "5_zone", 60, "metre", False),
],
)

Expand Down Expand Up @@ -624,8 +624,8 @@ def test_score_over_max(self) -> None:
test_round = Round(
"TestRound",
[
Pass(10, 1.22, "10_zone", 50, "metre", False),
Pass(10, 0.80, "10_zone", 50, "metre", False),
Pass(10, 122, "10_zone", 50, "metre", False),
Pass(10, 80, "10_zone", 50, "metre", False),
],
)

Expand All @@ -645,8 +645,8 @@ def test_score_of_zero(self) -> None:
test_round = Round(
"TestRound",
[
Pass(10, 1.22, "10_zone", 50, "metre", False),
Pass(10, 0.80, "10_zone", 50, "metre", False),
Pass(10, 122, "10_zone", 50, "metre", False),
Pass(10, 80, "10_zone", 50, "metre", False),
],
)

Expand All @@ -666,8 +666,8 @@ def test_score_below_zero(self) -> None:
test_round = Round(
"TestRound",
[
Pass(10, 1.22, "10_zone", 50, "metre", False),
Pass(10, 0.80, "10_zone", 50, "metre", False),
Pass(10, 122, "10_zone", 50, "metre", False),
Pass(10, 80, "10_zone", 50, "metre", False),
],
)

Expand Down
6 changes: 3 additions & 3 deletions archeryutils/load_rounds.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""Module to load round data from json files into DotDicts."""
import json
from pathlib import Path
import warnings
from typing import Union, List, Dict, Any
from pathlib import Path
from typing import Any, Dict, List, Union

from archeryutils.rounds import Pass, Round

Expand Down Expand Up @@ -107,7 +107,7 @@ def read_json_to_round_dict(json_filelist: Union[str, List[str]]) -> Dict[str, R
passes = [
Pass(
pass_i["n_arrows"],
pass_i["diameter"] / 100,
pass_i["diameter"],
pass_i["scoring"],
pass_i["distance"],
dist_unit=pass_i["dist_unit"],
Expand Down
6 changes: 3 additions & 3 deletions archeryutils/rounds.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""Classes to define a Pass and Round for archery applications."""
from typing import List, Union, Tuple
from typing import List, Tuple, Union

from archeryutils.targets import Target
from archeryutils.constants import YARD_TO_METRE
from archeryutils.targets import Target


class Pass:
Expand All @@ -17,7 +17,7 @@ class Pass:
n_arrows : int
number of arrows in this pass
diameter : float
face diameter in [metres]
face diameter in [centimetres]
scoring_system : str
target face/scoring system type
distance : float
Expand Down
37 changes: 19 additions & 18 deletions archeryutils/tests/test_rounds.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Tests for Pass and Round classes"""
from typing import Union, Tuple
from typing import Tuple, Union

import pytest

from archeryutils.rounds import Pass, Round
Expand Down Expand Up @@ -27,28 +28,28 @@ def test_default_distance_unit(self) -> None:
"""
Check that Pass() returns distance in metres when units not specified.
"""
test_pass = Pass(36, 1.22, "5_zone", 50)
test_pass = Pass(36, 122, "5_zone", 50)
assert test_pass.native_dist_unit == "metre"

def test_default_location(self) -> None:
"""
Check that Pass() returns indoor=False when indoor not specified.
"""
test_pass = Pass(36, 1.22, "5_zone", 50, "metre")
test_pass = Pass(36, 122, "5_zone", 50, "metre")
assert test_pass.indoor is False

def test_negative_arrows(self) -> None:
"""
Check that Pass() uses abs(narrows).
"""
test_pass = Pass(-36, 1.22, "5_zone", 50, "metre")
test_pass = Pass(-36, 122, "5_zone", 50, "metre")
assert test_pass.n_arrows == 36

def test_properties(self) -> None:
"""
Check that Pass properties are set correctly
"""
test_pass = Pass(36, 1.22, "5_zone", 50, "metre", False)
test_pass = Pass(36, 122, "5_zone", 50, "metre", False)
assert test_pass.distance == 50.0
assert test_pass.native_dist_unit == "metre"
assert test_pass.diameter == 1.22
Expand All @@ -74,7 +75,7 @@ def test_max_score(
"""
Check that Pass.max_score() method is functioning correctly
"""
test_pass = Pass(100, 1.22, face_type, 50, "metre", False)
test_pass = Pass(100, 122, face_type, 50, "metre", False)
assert test_pass.max_score() == max_score_expected


Expand Down Expand Up @@ -102,9 +103,9 @@ def test_max_score(self) -> None:
test_round = Round(
"MyRound",
[
Pass(100, 1.22, "5_zone", 50, "metre", False),
Pass(100, 1.22, "5_zone", 40, "metre", False),
Pass(100, 1.22, "5_zone", 30, "metre", False),
Pass(100, 122, "5_zone", 50, "metre", False),
Pass(100, 122, "5_zone", 40, "metre", False),
Pass(100, 122, "5_zone", 30, "metre", False),
],
)
assert test_round.max_score() == 2700
Expand Down Expand Up @@ -135,9 +136,9 @@ def test_max_distance(
test_round = Round(
"MyRound",
[
Pass(10, 1.22, "5_zone", 100, unit, False),
Pass(10, 1.22, "5_zone", 80, unit, False),
Pass(10, 1.22, "5_zone", 60, unit, False),
Pass(10, 122, "5_zone", 100, unit, False),
Pass(10, 122, "5_zone", 80, unit, False),
Pass(10, 122, "5_zone", 60, unit, False),
],
)
assert test_round.max_distance(unit=get_unit) == max_dist_expected
Expand All @@ -150,9 +151,9 @@ def test_max_distance_out_of_order(self) -> None:
test_round = Round(
"MyRound",
[
Pass(10, 1.22, "5_zone", 80, "metre", False),
Pass(10, 1.22, "5_zone", 100, "metre", False),
Pass(10, 1.22, "5_zone", 60, "metre", False),
Pass(10, 122, "5_zone", 80, "metre", False),
Pass(10, 122, "5_zone", 100, "metre", False),
Pass(10, 122, "5_zone", 60, "metre", False),
],
)
assert test_round.max_distance() == 100
Expand All @@ -164,9 +165,9 @@ def test_get_info(self, capsys: pytest.CaptureFixture[str]) -> None:
test_round = Round(
"MyRound",
[
Pass(10, 1.22, "5_zone", 100, "metre", False),
Pass(20, 1.22, "5_zone", 80, "yards", False),
Pass(30, 0.80, "5_zone", 60, "metre", False),
Pass(10, 122, "5_zone", 100, "metre", False),
Pass(20, 122, "5_zone", 80, "yards", False),
Pass(30, 80, "5_zone", 60, "metre", False),
],
)
test_round.get_info()
Expand Down

0 comments on commit 5dc07fc

Please sign in to comment.