flightpathr

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

commit ecebba57703c4810a5ef7c43b8ffea21c4096558
parent d56a686cf97800d13c2b0c90e9dc30786af13db9
Author: eamoncaddigan <eamon.caddigan@gmail.com>
Date:   Wed, 21 Sep 2016 14:08:15 -0400

Tests for is.flightpath() and more for createPath().

Diffstat:
Mtests/testthat/test_createPath.R | 59+++++++++++++++++++++++++++++++----------------------------
1 file changed, 31 insertions(+), 28 deletions(-)

diff --git a/tests/testthat/test_createPath.R b/tests/testthat/test_createPath.R @@ -10,36 +10,39 @@ pathMat <- matrix(c(-74.5771667, 39.4575833, nrow = 3, byrow = TRUE, dimnames = list(c("KACY", "VCN", "K17N"), c("lon", "lat"))) +path <- createPath(pathMat[, "lon"], pathMat[, "lat"]) -test_that("Handling paths with no altitude", { - path <- createPath(pathMat[, "lon"], pathMat[, "lat"]) +test_that("Simple flightpath creation works", { expect_equal(path$longitude, pathMat[, "lon"]) expect_equal(path$latitude, pathMat[, "lat"]) - expect_equal(path$altitude, rep(NA, nrow(pathMat))) }) -# test_that("Bearing and groundspeed calculations are correct", { -# expect_equal(trajectory$timestamp, seq(1, timeSec)) -# expect_equal(trajectory$groundspeed, rep(100, timeSec), tolerance = 0.5) -# expect_equal(trajectory$bearing[1:(timeSec-1)], -# bearing(trajectoryMat[1:(timeSec-1), ], trajectoryMat[2:timeSec, ])) -# }) -# -# test_that("Input types are checked", { -# expect_error(createTrajectory(paste(trajectoryMat[, "lon"]), trajectoryMat[, "lat"]), -# "\"longitude\" must be a numeric vector") -# expect_error(createTrajectory(trajectoryMat[, "lon"], paste(trajectoryMat[, "lat"])), -# "\"latitude\" must be a numeric vector") -# expect_error(createTrajectory(trajectoryMat[, "lon"], trajectoryMat[, "lat"], paste(rep(2500, timeSec))), -# "\"altitude\" must be a numeric vector") -# }) -# -# test_that("Input lengths are checked", { -# expect_error(createTrajectory(trajectoryMat[, "lon"], trajectoryMat[1, "lat"]), -# paste("Vector \"latitude\" has length = 1, expected length =", timeSec)) -# # Altitude can have length of 1 or timeSec, otherwise there should be an error -# expect_error(createTrajectory(trajectoryMat[, "lon"], trajectoryMat[, "lat"], rep(2500, 2)), -# paste("Vector \"altitude\" has length = 2, expected length =", timeSec)) -# expect_equal(createTrajectory(trajectoryMat[, "lon"], trajectoryMat[, "lat"], 2500)$altitude, -# rep(2500, timeSec)) -# }) +test_that("Longitude and latitude checking works", { + expect_error(createPath(paste(pathMat[, "lon"]), pathMat[, "lat"]), + "\"longitude\" must be a numeric vector") + expect_error(createPath(pathMat[, "lon"], paste(pathMat[, "lat"])), + "\"latitude\" must be a numeric vector") + expect_error(createPath(pathMat[, "lon"], pathMat[1:2, "lat"]), + "\"latitude\" and \"longitude\" length mismatch") + +}) + +test_that("Altitudes are handled appropriately", { + altitude <- runif(nrow(pathMat), 2500, 4500) + expect_equal(createPath(pathMat[, "lon"], pathMat[, "lat"], altitude)$altitude, + altitude) + expect_equal(createPath(pathMat[, "lon"], pathMat[, "lat"], altitude[1])$altitude, + rep(altitude[1], nrow(pathMat))) + expect_equal(createPath(pathMat[, "lon"], pathMat[, "lat"])$altitude, + rep(NA, nrow(pathMat))) + + expect_error(createPath(pathMat[, "lon"], pathMat[, "lat"], altitude[1:2]), + "\"altitude\" has incorrect length") + expect_error(createPath(pathMat[, "lon"], pathMat[, "lat"], paste(altitude)), + "\"altitude\" must be NA or a numeric vector") +}) + +test_that("Trajectories are identified", { + expect_true(is.flightpath(path)) + expect_false(is.flightpath(pathMat)) +})