commit 3ae38668544e31a25af45d80449e87ab9cae1869
parent 0e65a18504509a130f8b8dd7a6891965e67d89f5
Author: eamoncaddigan <eamon.caddigan@gmail.com>
Date: Wed, 14 Sep 2016 11:36:23 -0400
More tests for calculateTCPA
Diffstat:
1 file changed, 19 insertions(+), 1 deletion(-)
diff --git a/tests/testthat/test_calculateTCPA.R b/tests/testthat/test_calculateTCPA.R
@@ -6,6 +6,8 @@ library(geosphere)
kacy <- c(-74.5771667, 39.4575833)
kphl <- c(-75.2408658, 39.8722494)
+meterPer200Knots <- 0.009719
+
test_that("correct tCPA for head-on collision", {
trajectory1 <- createTrajectory(kacy[1], kacy[2],
bearing = bearingRhumb(kacy, kphl),
@@ -15,6 +17,22 @@ test_that("correct tCPA for head-on collision", {
groundspeed = 200)
expect_equal(calculateTCPA(trajectory1, trajectory2),
- distGeo(kacy, kphl)/2 * 0.009719,
+ distGeo(kacy, kphl)/2 * meterPer200Knots,
tolerance = 1)
})
+
+test_that("TCPA for actual trajectories", {
+ numPoints <- round(distGeo(kacy, kphl) * meterPer200Knots)
+ coords <- gcIntermediate(kacy, kphl,
+ n = numPoints)
+ trajectory1 <- createTrajectory(coords[, "lon"], coords[, "lat"])
+ trajectory2 <- createTrajectory(rev(coords[, "lon"]), rev(coords[, "lat"]))
+ tcpaVector <- calculateTCPA(trajectory1, trajectory2)
+
+ expect_equal(tcpaVector[seq(ceiling(numPoints/2)+1, numPoints)],
+ 0 * seq(ceiling(numPoints/2)+1, numPoints))
+
+ expect_equal(diff(tcpaVector[seq(1, floor(numPoints/2))]),
+ -1*diff(seq(1, floor(numPoints/2))),
+ tolerance = 1e-3)
+})