From 44acf048247613687a33f45cdf09fb6772f7b932 Mon Sep 17 00:00:00 2001 From: Dorchies David <david.dorchies@inrae.fr> Date: Tue, 26 Apr 2022 15:07:43 +0200 Subject: [PATCH] test: add test on get_result Refs #9 --- R/get_result.R | 9 +++++++-- tests/testthat/test-get_result.R | 13 +++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/R/get_result.R b/R/get_result.R index 4d28d58..c7265ec 100644 --- a/R/get_result.R +++ b/R/get_result.R @@ -32,6 +32,8 @@ get_result <- function(cfg, fun_format = NULL, m = read_bin_result_matrix(cfg, scenario, variant)) { + file <- attr(m, "file") + df_col <- get_result_tree(cfg, scenario, variant) filters <- paste(filters, collapse = " AND ") if (filters != "") { @@ -78,8 +80,9 @@ get_result <- function(cfg, class(m) <- c("SicResult", class(m)) if (!is.null(fun_format)) { - return(fun_format(m)) + m <- fun_format(m) } + attr(m, "file") <- file return(m) } @@ -123,7 +126,9 @@ read_bin_result_matrix <- function(cfg, scenario, variant = 0) { endian = "little") readBin(con, "raw", n = 4) # @todo check end file content close(con) - return(matrix(data, ncol = dims[2], byrow = TRUE)) + m <- matrix(data, ncol = dims[2], byrow = TRUE) + attr(m, "file") <- file + return(m) } diff --git a/tests/testthat/test-get_result.R b/tests/testthat/test-get_result.R index 3739dfd..5bb4768 100644 --- a/tests/testthat/test-get_result.R +++ b/tests/testthat/test-get_result.R @@ -27,3 +27,16 @@ test_that("get_result with tidy return a tidy result", { expect_equal(attr(result, "t"), seq(0, 86400, by = 60)) expect_type(result$bf, "integer") }) + +test_that("flow in first section must be equal to injected flow", { + t <- seq(0, 86400, by = 600) + dfTest <- data.frame(t = t, + v = 100 * sin((seq_along(t) - 1) * pi / 16) + 200) + input <- SicInput(dfTest, locations = SicLocation(list(Nd = 1, Pr = 1, Car = "Q"))) + + sic_run_unsteady(cfg, iniParams = c(1, 0, 0, 1, 1), sicInputs = input, params = list(DT = "600")) + result <- get_result(cfg, 1, 1, + filters = c("bf=1", "sn=1", "var='Q'"), + fun_format = compact_tidy_result) + expect_equal(result$values[1][[1]], dfTest$v) +}) -- GitLab