flightpathr

Tools to analyze aircraft and flight path data.
git clone https://git.eamoncaddigan.net/flightpathr.git
Log | Files | Refs | README | LICENSE

test_createPath.R (1872B)


      1 library(flightpathr)
      2 context("createPath")
      3 
      4 library(geosphere)
      5 
      6 # Data for a flight path
      7 pathMat <- matrix(c(-74.5771667, 39.4575833,
      8                     -74.9671439, 39.5376711,
      9                     -75.0330031, 39.7054758),
     10                   nrow = 3, byrow = TRUE,
     11                   dimnames = list(c("KACY", "VCN", "K17N"),
     12                                   c("lon", "lat")))
     13 path <- createPath(pathMat[, "lon"], pathMat[, "lat"])
     14 
     15 test_that("Simple flightpath creation works", {
     16   expect_equal(path$longitude, pathMat[, "lon"])
     17   expect_equal(path$latitude, pathMat[, "lat"])
     18 })
     19 
     20 test_that("Longitude and latitude checking works", {
     21   expect_error(createPath(paste(pathMat[, "lon"]), pathMat[, "lat"]),
     22                "\"longitude\" must be a numeric vector")
     23   expect_error(createPath(pathMat[, "lon"], paste(pathMat[, "lat"])),
     24                "\"latitude\" must be a numeric vector")
     25   expect_error(createPath(pathMat[, "lon"], pathMat[1:2, "lat"]),
     26                "\"latitude\" and \"longitude\" length mismatch")
     27 
     28 })
     29 
     30 test_that("Altitudes are handled appropriately", {
     31   altitude <- runif(nrow(pathMat), 2500, 4500)
     32   expect_equal(createPath(pathMat[, "lon"], pathMat[, "lat"], altitude)$altitude,
     33                altitude)
     34   expect_equal(createPath(pathMat[, "lon"], pathMat[, "lat"], altitude[1])$altitude,
     35                rep(altitude[1], nrow(pathMat)))
     36   expect_equal(createPath(pathMat[, "lon"], pathMat[, "lat"])$altitude,
     37                rep(NA, nrow(pathMat)))
     38 
     39   expect_error(createPath(pathMat[, "lon"], pathMat[, "lat"], altitude[1:2]),
     40                "\"altitude\" has incorrect length")
     41   expect_error(createPath(pathMat[, "lon"], pathMat[, "lat"], paste(altitude)),
     42                "\"altitude\" must be NA or a numeric vector")
     43 })
     44 
     45 test_that("Trajectories are identified", {
     46   expect_true(is.flightpath(path))
     47   expect_false(is.flightpath(pathMat))
     48 })