From ed5c8777d100b8a4c0ffaa81b72bb96dda7aabe3 Mon Sep 17 00:00:00 2001 From: mark Date: Wed, 10 Aug 2016 11:18:04 +0200 Subject: [PATCH] added tests for nr of time points, sites --- pkg/R/parse_outfile.R | 31 +++++++++++++++++++++++++++++++ pkg/tests/testthat/test_trim.R | 6 +++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/pkg/R/parse_outfile.R b/pkg/R/parse_outfile.R index a7f94ca..906096d 100644 --- a/pkg/R/parse_outfile.R +++ b/pkg/R/parse_outfile.R @@ -28,6 +28,37 @@ print.tof <- function(x,...){ cat(x) } + +#' Extract nr of times from \code{tof} object +#' +#' @param x An object of class \code{tof} +#' +#' @return \code{numeric} +#' @family parse_output +#' @keywords internal +get_n_site <- function(x){ + mm <- regexpr("Site[[:blank:]]{5,}.*?\n",x) + s <- regmatches(x,mm) + get_num(s) +} + + +#' Extract nr of sites from \code{tof} object +#' +#' @param x An object of class \code{tof} +#' +#' @return \code{numeric} +#' @family parse_output +#' @keywords internal +get_n_time <- function(x){ + mm <- regexpr("Time[[:blank:]]{5,}.*?\n",x) + s <- regmatches(x,mm) + get_num(s) +} + + + + #' Extract time indices from \code{tof} object #' #' @param x An object of class \code{tof} diff --git a/pkg/tests/testthat/test_trim.R b/pkg/tests/testthat/test_trim.R index 732e9e5..d4cdda4 100644 --- a/pkg/tests/testthat/test_trim.R +++ b/pkg/tests/testthat/test_trim.R @@ -4,7 +4,11 @@ test_that("skylark-1d model",{ tc <- read_tcf("outfiles/skylark-1d.tcf") m <- trim(tc) to <- read_tof("outfiles/skylark-1d.out") - + + # data basics + expect_equal(m$nsite, get_n_site(to)) + expect_equal(m$ntime, get_n_time(to)) + # time index check tgt <- get_time_indices(to) out <- index(m,"both")