Skip to content

Commit

Permalink
Issue #3 Added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Kharude, Sachin committed Mar 28, 2020
1 parent f8bb9e2 commit 73db592
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
40 changes: 38 additions & 2 deletions tests/test_measurement.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
LineString, MultiLineString, MultiPoint, MultiPolygon,
Point, Polygon)

from turfpy.measurement import (bbox, bbox_polygon, center, envelope,
rhumb_destination, rhumb_distance, square)
from turfpy.measurement import (along, bbox, bbox_polygon, center, envelope,
midpoint, nearest_point, rhumb_destination,
rhumb_distance, square)


def test_bbox_point():
Expand Down Expand Up @@ -164,3 +165,38 @@ def test_square():
bbox = [-20, -20, -15, 0]
res = square(bbox)
assert res == [-27.5, -20, -7.5, 0]


def test_along():
ls = LineString([(-83, 30), (-84, 36), (-78, 41)])
res = along(ls, 200, 'mi')
assert res["type"] == "Feature"
assert res["geometry"]["type"] == "Point"
c0, c1 = list(map(lambda x: round(x, 4), res["geometry"]["coordinates"]))
assert c0 == -83.4609
assert c1 == 32.8678


def test_midpoint():
point1 = Point((144.834823, -37.771257))
point2 = Point((145.14244, -37.830937))
mp = midpoint(point1, point2)
assert mp["type"] == "Feature"
assert mp["geometry"]["type"] == "Point"
c0, c1 = list(map(lambda x: round(x, 4), mp["geometry"]["coordinates"]))
assert c0 == 144.9886
assert c1 == -37.8012


def test_nearest_point():
f1 = Feature(geometry=Point((28.96991729736328, 41.01190001748873)))
f2 = Feature(geometry=Point((28.948459, 41.024204)))
f3 = Feature(geometry=Point((28.938674, 41.013324)))
fc = FeatureCollection([f1, f2, f3])
t = Feature(geometry=Point((28.973865, 41.011122)))
np = nearest_point(t, fc)
assert np["type"] == "Feature"
assert np["geometry"]["type"] == "Point"
c0, c1 = list(map(lambda x: round(x, 4), np["geometry"]["coordinates"]))
assert c0 == 28.9699
assert c1 == 41.0119
4 changes: 3 additions & 1 deletion turfpy/measurement.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,9 @@ def nearest_point(target_point: Feature, points: FeatureCollection) -> Feature:
:param points: FeatureCollection of points.
:return: a Point Feature from the FeatureCollection which is closest to the reference
Point.
Example:-
Example:
>>> from turfpy.measurement import nearest_point
>>> from geojson import Point, Feature, FeatureCollection
>>> f1 = Feature(geometry=Point([28.96991729736328,41.01190001748873]))
Expand Down

0 comments on commit 73db592

Please sign in to comment.