From aed4ce489ff4975d386a6edee987ecb44e5aa7bb Mon Sep 17 00:00:00 2001 From: aheinri5 <Anna@netzkritzler.de> Date: Sun, 7 Feb 2021 23:20:30 +0100 Subject: [PATCH] [tests] updated tests, removed sim_id --- tests/testthat/test-export_prj.R | 1 - tests/testthat/test-ogs6.R | 2 - tests/testthat/test-ogs6_ensemble.R | 1 - .../testthat/{test-gml.R => test-ogs6_gml.R} | 16 ++- tests/testthat/test-ogs6_pvd.R | 97 ++++++++++++++++ .../testthat/{test-vtu.R => test-ogs6_vtu.R} | 104 +----------------- tests/testthat/test-read_in_prj.R | 10 -- tests/testthat/test-read_in_utils.R | 1 - tests/testthat/test-sim_utils.R | 1 - 9 files changed, 114 insertions(+), 119 deletions(-) rename tests/testthat/{test-gml.R => test-ogs6_gml.R} (85%) create mode 100644 tests/testthat/test-ogs6_pvd.R rename tests/testthat/{test-vtu.R => test-ogs6_vtu.R} (54%) diff --git a/tests/testthat/test-export_prj.R b/tests/testthat/test-export_prj.R index c49bf68..51ee090 100644 --- a/tests/testthat/test-export_prj.R +++ b/tests/testthat/test-export_prj.R @@ -8,7 +8,6 @@ test_that("export_prj works", { # Define prj_path and OGS6 object, then read in .prj file ogs6_obj <- OGS6$new(sim_name = "flow_free_expansion", - sim_id = 1, sim_path = test_path) diff --git a/tests/testthat/test-ogs6.R b/tests/testthat/test-ogs6.R index 9b1d820..d18113e 100644 --- a/tests/testthat/test-ogs6.R +++ b/tests/testthat/test-ogs6.R @@ -5,7 +5,6 @@ test_that("OGS6$clear() works as expected", { ogs6_obj <- OGS6$new( sim_name = "sim", - sim_id = 1, sim_path = "sim_path") ogs6_obj$add(r2ogs6_parameter( @@ -24,7 +23,6 @@ test_that("OGS6$add() works", { ogs6_obj <- OGS6$new( sim_name = "sim", - sim_id = 1, sim_path = "sim_path") ogs6_obj$add(r2ogs6_parameter( diff --git a/tests/testthat/test-ogs6_ensemble.R b/tests/testthat/test-ogs6_ensemble.R index 9c90c51..304af14 100644 --- a/tests/testthat/test-ogs6_ensemble.R +++ b/tests/testthat/test-ogs6_ensemble.R @@ -5,7 +5,6 @@ test_that("OGS6_Ensemble initialization works", { ogs6_obj <- OGS6$new( sim_name = "sim", - sim_id = 1, sim_path = "sim_path") ogs6_obj$add(r2ogs6_parameter( diff --git a/tests/testthat/test-gml.R b/tests/testthat/test-ogs6_gml.R similarity index 85% rename from tests/testthat/test-gml.R rename to tests/testthat/test-ogs6_gml.R index 1840cb0..e3536f7 100644 --- a/tests/testthat/test-gml.R +++ b/tests/testthat/test-ogs6_gml.R @@ -1,3 +1,17 @@ + + +test_that("OGS6_gml initialization works", { + + gml <- OGS6_gml$new(name = "my_gml", + points = tibble::tibble(x = c(0, 0), + y = c(1, 1), + z = c(0, 1)), + polylines = list(list("my_line", c(1, 0, 1)))) + + expect_equal(length(gml$points), 3) +}) + + test_that("validate_points works", { point_list <- list(x = c(0, 0), y = c(1, 1), z = c(0, 1)) @@ -66,4 +80,4 @@ test_that("validate_surfaces works", { expect_error(validate_surfaces(surface_tibble)) #...(WIP) -}) \ No newline at end of file +}) diff --git a/tests/testthat/test-ogs6_pvd.R b/tests/testthat/test-ogs6_pvd.R new file mode 100644 index 0000000..8aa6881 --- /dev/null +++ b/tests/testthat/test-ogs6_pvd.R @@ -0,0 +1,97 @@ + + +test_that("OGS6_pvd initialization works", { + + pvd_path <- system.file("extdata/benchmarks/flow_no_strain", + "flow_no_strain.pvd", + package = "r2ogs6") + + ogs6_pvd <- OGS6_pvd$new(pvd_path) + + expect_equal(length(ogs6_pvd$vtu_paths), 2) + expect_equal(ogs6_pvd$vtu_paths[[1]], + "flow_no_strain_ts_0_t_0.000000.vtu") + expect_equal(ogs6_pvd$vtu_paths[[2]], + "flow_no_strain_ts_1000_t_100.000000.vtu") +}) + + +test_that("OGS6_pvd$get_timestep_by_vtu_path works", { + + pvd_path <- system.file("extdata/benchmarks/flow_no_strain", + "flow_no_strain.pvd", + package = "r2ogs6") + + ogs6_pvd <- OGS6_pvd$new(pvd_path) + + vtu_path <- "flow_no_strain_ts_1000_t_100.000000.vtu" + + timestep <- ogs6_pvd$timestep_by_vtu(vtu_path = vtu_path) + + expect_equal(timestep, 99.9999999999986) +}) + + +test_that("OGS6_pvd$get_point_data_at works", { + + pvd_path <- system.file("extdata/benchmarks/flow_no_strain", + "flow_no_strain.pvd", + package = "r2ogs6") + + ogs6_pvd <- OGS6_pvd$new(pvd_path) + + + tbl_from_id <- ogs6_pvd$get_point_data(0, + keys = c("epsilon_xx", + "epsilon_xy")) + + # Test for DataArray where NumberOfComponents == 1 + tbl_from_coords <- ogs6_pvd$get_point_data_at(coordinates = c(0, 0, 0), + keys = c("epsilon_xx", + "epsilon_xy")) + + expect_equal(tbl_from_coords$epsilon_xx, tbl_from_id$epsilon_xx) + expect_equal(tbl_from_coords$epsilon_xy, tbl_from_id$epsilon_xy) +}) + + +test_that("OGS6_pvd$get_point_data works", { + + pvd_path <- system.file("extdata/benchmarks/flow_no_strain", + "flow_no_strain.pvd", + package = "r2ogs6") + + ogs6_pvd <- OGS6_pvd$new(pvd_path) + + # Test for DataArray where NumberOfComponents == 1 + tbl_simple <- ogs6_pvd$get_point_data(point_ids = c(0, 1, 2), + keys = c("epsilon_xx", + "epsilon_xy")) + + expect_equal(nrow(tbl_simple), 6) + + # Test for DataArray where NumberOfComponents(displacement) == 2 + tbl_nocomp <- ogs6_pvd$get_point_data(point_ids = c(0, 1, 2), + keys = c("displacement", + "epsilon_xx")) + + expect_equal(nrow(tbl_nocomp), 6) +}) + + +test_that("OGS6_pvd$get_cell_data works", { + + pvd_path <- system.file("extdata/benchmarks/flow_no_strain", + "flow_no_strain.pvd", + package = "r2ogs6") + + ogs6_pvd <- OGS6_pvd$new(pvd_path) + + # Test for DataArray where NumberOfComponents(displacement) == 2 + tbl_nocomp <- ogs6_pvd$get_cell_data( + cell_ids = c(0, 1, 2), + keys = c("permeability", + "principal_stress_values")) + + expect_equal(nrow(tbl_nocomp), 6) +}) diff --git a/tests/testthat/test-vtu.R b/tests/testthat/test-ogs6_vtu.R similarity index 54% rename from tests/testthat/test-vtu.R rename to tests/testthat/test-ogs6_vtu.R index 9132649..84e0520 100644 --- a/tests/testthat/test-vtu.R +++ b/tests/testthat/test-ogs6_vtu.R @@ -13,106 +13,6 @@ skip_if_python_modules_missing <- function() { } -#===== OGS6_pvd ===== - - -test_that("OGS6_pvd initialization works", { - - pvd_path <- system.file("extdata/benchmarks/flow_no_strain", - "flow_no_strain.pvd", - package = "r2ogs6") - - ogs6_pvd <- OGS6_pvd$new(pvd_path) - - expect_equal(length(ogs6_pvd$vtu_paths), 2) - expect_equal(ogs6_pvd$vtu_paths[[1]], - "flow_no_strain_ts_0_t_0.000000.vtu") - expect_equal(ogs6_pvd$vtu_paths[[2]], - "flow_no_strain_ts_1000_t_100.000000.vtu") -}) - - -test_that("OGS6_pvd$get_timestep_by_vtu_path works", { - - pvd_path <- system.file("extdata/benchmarks/flow_no_strain", - "flow_no_strain.pvd", - package = "r2ogs6") - - ogs6_pvd <- OGS6_pvd$new(pvd_path) - - vtu_path <- "flow_no_strain_ts_1000_t_100.000000.vtu" - - timestep <- ogs6_pvd$timestep_by_vtu(vtu_path = vtu_path) - - expect_equal(timestep, 99.9999999999986) -}) - - -test_that("OGS6_pvd$get_point_data_at works", { - - pvd_path <- system.file("extdata/benchmarks/flow_no_strain", - "flow_no_strain.pvd", - package = "r2ogs6") - - ogs6_pvd <- OGS6_pvd$new(pvd_path) - - - tbl_from_id <- ogs6_pvd$get_point_data(0, - Names = c("epsilon_xx", - "epsilon_xy")) - - # Test for DataArray where NumberOfComponents == 1 - tbl_from_coords <- ogs6_pvd$get_point_data_at(coordinates = c(0, 0, 0), - Names = c("epsilon_xx", - "epsilon_xy")) - - expect_equal(tbl_from_coords$epsilon_xx, tbl_from_id$epsilon_xx) - expect_equal(tbl_from_coords$epsilon_xy, tbl_from_id$epsilon_xy) -}) - - -test_that("OGS6_pvd$get_point_data works", { - - pvd_path <- system.file("extdata/benchmarks/flow_no_strain", - "flow_no_strain.pvd", - package = "r2ogs6") - - ogs6_pvd <- OGS6_pvd$new(pvd_path) - - # Test for DataArray where NumberOfComponents == 1 - tbl_simple <- ogs6_pvd$get_point_data(point_ids = c(0, 1, 2), - Names = c("epsilon_xx", - "epsilon_xy")) - - expect_equal(nrow(tbl_simple), 6) - - # Test for DataArray where NumberOfComponents(displacement) == 2 - tbl_nocomp <- ogs6_pvd$get_point_data(point_ids = c(0, 1, 2), - Names = c("displacement", - "epsilon_xx")) - - expect_equal(nrow(tbl_nocomp), 6) -}) - - -test_that("OGS6_pvd$get_cell_data works", { - - pvd_path <- system.file("extdata/benchmarks/flow_no_strain", - "flow_no_strain.pvd", - package = "r2ogs6") - - ogs6_pvd <- OGS6_pvd$new(pvd_path) - - # Test for DataArray where NumberOfComponents(displacement) == 2 - tbl_nocomp <- ogs6_pvd$get_cell_data( - cell_ids = c(0, 1, 2), - Names = c("permeability", - "principal_stress_values")) - - expect_equal(nrow(tbl_nocomp), 6) -}) - - #===== OGS6_vtu ===== @@ -169,13 +69,13 @@ test_that("OGS6_vtu$get_point_data_at() works", { vtu_obj <- OGS6_vtu$new(vtu_path = vtu_path) tbl <- vtu_obj$get_point_data_at(c(0.01, 0, 0), - Names = "epsilon_xx") + keys = "epsilon_xx") expect_equal(tbl$epsilon_xx, 3.282899e-15) bigger_tbl <- vtu_obj$get_point_data_at(list(c(0.01, 0, 0), c(0.42, 0, 0)), - Names = "epsilon_xx") + keys = "epsilon_xx") expect_equal(bigger_tbl$epsilon_xx[[2]], 1.233661e-16) }) diff --git a/tests/testthat/test-read_in_prj.R b/tests/testthat/test-read_in_prj.R index 8acb7b2..6961351 100644 --- a/tests/testthat/test-read_in_prj.R +++ b/tests/testthat/test-read_in_prj.R @@ -6,7 +6,6 @@ test_that("read_in works for process objects", { "flow_free_expansion.prj", package = "r2ogs6")) ogs6_obj <- OGS6$new(sim_name = "sim", - sim_id = 1, sim_path = "sim_path") read_in(ogs6_obj, @@ -31,7 +30,6 @@ test_that("read_in works for medium objects", { "flow_free_expansion.prj", package = "r2ogs6")) ogs6_obj <- OGS6$new(sim_name = "sim", - sim_id = 1, sim_path = "sim_path") read_in(ogs6_obj, @@ -48,7 +46,6 @@ test_that("read_in works for time_loop objects", { "flow_free_expansion.prj", package = "r2ogs6")) ogs6_obj <- OGS6$new(sim_name = "sim", - sim_id = 1, sim_path = "sim_path") read_in(ogs6_obj, @@ -68,7 +65,6 @@ test_that("read_in works for parameter objects", { "flow_free_expansion.prj", package = "r2ogs6")) ogs6_obj <- OGS6$new(sim_name = "sim", - sim_id = 1, sim_path = "sim_path") read_in(ogs6_obj, @@ -87,7 +83,6 @@ test_that("read_in works for process_variable objects", { "flow_free_expansion.prj", package = "r2ogs6")) ogs6_obj <- OGS6$new(sim_name = "sim", - sim_id = 1, sim_path = "sim_path") read_in(ogs6_obj, @@ -103,7 +98,6 @@ test_that("read_in works for nonlinear_solver objects", { "flow_free_expansion.prj", package = "r2ogs6")) ogs6_obj <- OGS6$new(sim_name = "sim", - sim_id = 1, sim_path = "sim_path") read_in(ogs6_obj, @@ -125,7 +119,6 @@ test_that("read_in works for linear_solver objects", { "flow_free_expansion.prj", package = "r2ogs6")) ogs6_obj <- OGS6$new(sim_name = "sim", - sim_id = 1, sim_path = "sim_path") read_in(ogs6_obj, @@ -146,7 +139,6 @@ test_that("read_in works with newline value separation", { "liakopoulos.prj", package = "r2ogs6")) ogs6_obj <- OGS6$new(sim_name = "sim", - sim_id = 1, sim_path = "sim_path") read_in(ogs6_obj, @@ -167,7 +159,6 @@ test_that("read_in_prj works for processes/include tags", { "circle_1e1_axi.prj", package = "r2ogs6")) ogs6_obj <- OGS6$new(sim_name = "sim", - sim_id = 1, sim_path = "sim_path") read_in_prj(ogs6_obj, @@ -185,7 +176,6 @@ test_that("read_in_prj works for EmbeddedFracturePermeability/cube.prj", { "cube.prj", package = "r2ogs6")) ogs6_obj <- OGS6$new(sim_name = "sim", - sim_id = 1, sim_path = "sim_path") read_in_prj(ogs6_obj, diff --git a/tests/testthat/test-read_in_utils.R b/tests/testthat/test-read_in_utils.R index 699aef8..d0e8f4c 100644 --- a/tests/testthat/test-read_in_utils.R +++ b/tests/testthat/test-read_in_utils.R @@ -6,7 +6,6 @@ test_that("node_to_object works for simple r2ogs6 classes", { "flow_free_expansion.prj", package = "r2ogs6")) ogs6_obj <- OGS6$new(sim_name = "sim", - sim_id = 1, sim_path = "sim_path") read_in(ogs6_obj, prj_path, "/OpenGeoSysProject/parameters/parameter") diff --git a/tests/testthat/test-sim_utils.R b/tests/testthat/test-sim_utils.R index 91741ee..32ce99f 100644 --- a/tests/testthat/test-sim_utils.R +++ b/tests/testthat/test-sim_utils.R @@ -62,7 +62,6 @@ test_that("ogs_export_sim_files works", { "circle_1e1_axi.prj", package = "r2ogs6")) ogs6_obj <- OGS6$new(sim_name = "circle_1e1_axi", - sim_id = 1, sim_path = test_path) read_in_prj(ogs6_obj, -- GitLab