From d82b538b7a7a0a1b593657a073eaef8f888ca6b0 Mon Sep 17 00:00:00 2001 From: nuest Date: Mon, 15 Jan 2018 13:11:59 +0100 Subject: [PATCH] increase test coverage --- R/measurement.R | 5 +++-- tests/testthat/test_boxes.R | 5 +++++ tests/testthat/test_measurements.R | 4 ++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/R/measurement.R b/R/measurement.R index 666fea3..f3aa657 100644 --- a/R/measurement.R +++ b/R/measurement.R @@ -106,8 +106,9 @@ parse_get_measurements_params = function (params) { if (is.null(params$phenomenon) | is.na(params$phenomenon)) stop('Parameter "phenomenon" is required') - if (!is.na(params$from) && is.na(params$to)) - stop('specify "from" only together with "to"') + if ((!is.na(params$from) && is.na(params$to)) || + (!is.na(params$to) && is.na(params$from)) + ) stop('specify "from" only together with "to"') if ( (!is.null(params$bbox) && !is.null(params$boxes)) || diff --git a/tests/testthat/test_boxes.R b/tests/testthat/test_boxes.R index ccc4915..0638a39 100644 --- a/tests/testthat/test_boxes.R +++ b/tests/testthat/test_boxes.R @@ -17,6 +17,11 @@ test_that("a list of all boxes can be retrieved and returns a sensebox data.fram expect_true(any("sensebox" %in% class(boxes))) }) +test_that("both from and to are required when requesting boxes, error otherwise", { + expect_error(osem_boxes(from = as.POSIXct("2017-01-01")), "must be used together") + expect_error(osem_boxes(to = as.POSIXct("2017-01-01")), "must be used together") +}) + test_that("a list of boxes with exposure filter returns only the requested exposure", { check_api() diff --git a/tests/testthat/test_measurements.R b/tests/testthat/test_measurements.R index 3cbe6a3..ffbc701 100644 --- a/tests/testthat/test_measurements.R +++ b/tests/testthat/test_measurements.R @@ -91,3 +91,7 @@ test_that("measurements can be retrieved for a time period", { expect_true(all(measurements$createdAt > from_date)) }) +test_that("both from and to are required when requesting measurements, error otherwise", { + expect_error(osem_measurements(x = "Temperature", from = as.POSIXct("2017-01-01")), "only together with") + expect_error(osem_measurements(x = "Temperature", to = as.POSIXct("2017-01-01")), "only together with") +})