diff --git a/R/get_result.R b/R/get_result.R index 4d28d58b63ff138268881b05070b56d2a504fa10..c7265ec320ae41c95b4d592ab7bc42896557f78e 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 3739dfd72dbd2c886cf6182a37c089b9ded18bc1..5bb4768a7d19ebbf4398d1745bee1f21bd0820a3 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) +})