Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add helper classes tests #46

Merged
merged 5 commits into from
Jul 19, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 83 additions & 2 deletions tests/helper_classes_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
import pytest
from helpers import proto_test_case

from extremitypathfinder.helper_classes import AngleRepresentation
from extremitypathfinder import helper_classes
from extremitypathfinder.helper_classes import AngleRepresentation, Polygon, Vertex

helper_classes.origin = Vertex((-5.0, -5.0))


class HelperClassesTest(unittest.TestCase):
Expand Down Expand Up @@ -52,7 +55,7 @@ def test_angle_repr(self):
# angle %360!
# rep(p1) > rep(p2) <=> angle(p1) > angle(p2)
# rep(p1) = rep(p2) <=> angle(p1) = angle(p2)
# repr value in [0.0 : 4.0[
# repr value in [0.0 : 4.0]

def value_test_fct(input):
np_2D_coord_vector = np.array(input)
Expand All @@ -71,6 +74,84 @@ def value_test_fct(input):

proto_test_case(data, value_test_fct)

def test_vertex_translation(self):
data = [
([1.0, 1.0], [6.0, 6.0]),
([0.0, 0.0], [5.0, 5.0]),
([-12.0, -3.0], [-7.0, 2.0]),
([-4.0, 5.0], [1.0, 10.0]),
([3.0, -2.0], [8.0, 3.0]),
]

def translation_test_fct(input):
return Vertex(input).get_coordinates_translated().tolist()

proto_test_case(data, translation_test_fct)

def test_vertex_angle_repr(self):
data = [
([0.0, -5.0], 0.0),
([-5.0, 0.0], 1.0),
([-6.0, -5.0], 2.0),
([-5.0, -6.0], 3.0),
]

def angle_repr_test_fct(input):
return Vertex(input).get_angle_representation()

proto_test_case(data, angle_repr_test_fct)

def test_vertex_distance_to_origin(self):
data = [
([0.0, 0.0], np.sqrt(50)),
([-5.0, 0.0], 5.0),
([0.0, -5], 5.0),
([-3.0, -2.0], np.sqrt(13)),
([2.0, 5.0], np.sqrt(149)),
]

def dist_to_origin_test_fct(input):
return Vertex(input).get_distance_to_origin()

proto_test_case(data, dist_to_origin_test_fct)

def test_polygon_bad_input(self):
with pytest.raises(ValueError) as err:
Polygon([(0, 0), (1, 1)], is_hole=False)
assert "not a valid polygon" in str(err)

def test_polygon_extremities(self):
data = [
(
[
(0, 0),
(10, 0),
(9, 5),
(10, 10),
(0, 10),
],
[(9, 5)],
),
(
[
(0, 0),
(-2, -2),
(-3, -2.5),
(-3, -4),
(2, -3),
(1, 2.5),
(0, -1),
],
[(0, -1), (-2, -2)],
),
]

def find_extremities_test_fct(input):
extremities = Polygon(input, is_hole=False).extremities
return [tuple(e.coordinates) for e in extremities]

proto_test_case(data, find_extremities_test_fct)


if __name__ == "__main__":
suite = unittest.TestLoader().loadTestsFromTestCase(HelperClassesTest)
Expand Down