test_get3dCoords.R (1198B)
1 library(flightpathr) 2 context("get3dCoords") 3 4 library(geosphere) 5 6 kacy <- c(-74.5771667, 39.4575833) 7 k17n <- c(-75.0330031, 39.7054758) 8 vcn <- c(-74.9671439, 39.5376711) 9 10 expect_unnamed_equal <- function(mat1, mat2) { 11 eval(bquote(expect_equal(unname(.(mat1)), unname(.(mat2))))) 12 } 13 14 test_that("flighttrajectories are recognized", { 15 distMeters <- distHaversine(kacy, k17n) 16 # distMeters m * (1 hr / 100 nmi) * (1 nmi / 1852 m) * (3600 s / 1 hr) 17 timeSec <- round(distMeters * (1/100) * (3600/1852)) 18 trajectoryMat <- cbind(gcIntermediate(kacy, k17n, n = timeSec-2, addStartEnd = TRUE), 19 alt = rep(2500, timeSec)) 20 trajectory <- createTrajectory(trajectoryMat[, "lon"], 21 trajectoryMat[, "lat"], 22 trajectoryMat[, "alt"]) 23 24 expect_unnamed_equal(get3dCoords(trajectory), trajectoryMat) 25 }) 26 27 test_that("flightpaths are recognized", { 28 pathMat <- rbind(kacy, vcn, k17n) 29 30 path1 <- createPath(pathMat[, 1], pathMat[, 2]) 31 path2 <- createPath(pathMat[, 1], pathMat[, 2], 7500) 32 33 expect_unnamed_equal(get3dCoords(path1), cbind(pathMat, NA)) 34 expect_unnamed_equal(get3dCoords(path2), cbind(pathMat, 7500)) 35 })