commit 267ca24c627d39bec6637054a1d65895df3004f1
parent 6dca78ae4d781a8a05ebe1fa486bb5870695461d
Author: eamoncaddigan <eamon.caddigan@gmail.com>
Date: Mon, 18 Apr 2016 14:56:09 -0400
More tests.
Diffstat:
1 file changed, 20 insertions(+), 3 deletions(-)
diff --git a/tests/testthat/test_distanceFromPath.R b/tests/testthat/test_distanceFromPath.R
@@ -10,11 +10,14 @@ path <- matrix(c(-75.0268, 39.7065,
dimnames = list(c("17N", "N81", "KACY"),
c("lon", "lat")))
-fakeTrajectory <- function(waypoints) {
+numPoints <- 5
+
+fakeTrajectory <- function(waypoints, n = numPoints) {
trajectoryList <- vector("list", 2*nrow(waypoints)-1)
trajectoryList[[1]] <- waypoints[1, ]
for (i in seq(2, nrow(waypoints))) {
- trajectoryList[[(i-1)*2]] <- geosphere::gcIntermediate(path[i-1, ], path[i, ], 5)
+ trajectoryList[[(i-1)*2]] <- geosphere::gcIntermediate(waypoints[i-1, ],
+ waypoints[i, ], n)
trajectoryList[[(i-1)*2+1]] <- waypoints[i, ]
}
return(do.call(rbind, trajectoryList))
@@ -22,8 +25,22 @@ fakeTrajectory <- function(waypoints) {
trajectory <- fakeTrajectory(path)
-test_that("non-deviating paths have small distances", {
+test_that("non-deviating paths have small distances for all input types", {
expect_true(all(distanceFromPath(trajectory, path) < 1))
+ expect_true(all(distanceFromPath(cbind(trajectory, 3500), cbind(path, 3500)) < 1))
expect_true(all(distanceFromPath(sp::SpatialPoints(trajectory), sp::SpatialPoints(path)) < 1))
expect_true(all(distanceFromPath(as.data.frame(trajectory), as.data.frame(path)) < 1))
})
+
+test_that("small deviations look OK", {
+ flownPath <- rbind(path[1:2, ],
+ KORDE = c(-74.0948, 39.0976),
+ path[3, , drop = FALSE])
+ flownTrajectory <- fakeTrajectory(flownPath)
+ trajectoryDistance <- distanceFromPath(flownTrajectory, path)$horizontal
+ farthestPoint <- which.max(abs(trajectoryDistance))
+
+ expect_equal(farthestPoint, numPoints*2+3)
+ # left of course
+ expect_lt(trajectoryDistance[farthestPoint], 0)
+})