diff --git a/tests/testthat/test-export_utils.R b/tests/testthat/test-export_utils.R index e37200deb7f79ee98b935637d0d8e0130a121b20..b623c401cff0f81059d2da5b09331acb9494450f 100644 --- a/tests/testthat/test-export_utils.R +++ b/tests/testthat/test-export_utils.R @@ -94,26 +94,15 @@ test_that("to_node works for simple classes", { test_that("to_node works for classes that have lists as parameters", { - linear_solver <- r2ogs6_linear_solver( - name = "general_linear_solver", - eigen = list( - solver_type = "BiCGSTAB", - precon_type = "ILUT", - max_iteration_step = 10000, - error_tolerance = 1e-16 - ), - lis = "-i bicgstab -p ilu -tol 1e-16 -maxiter 10000" - ) + insitu <- r2ogs6_insitu(c("script_1", + "script_2", + "script_3")) - linear_solver_node <- to_node(linear_solver) - linear_solver_xml <- xml2::as_xml_document(linear_solver_node) + insitu_node <- to_node(insitu) + insitu_xml <- xml2::as_xml_document(insitu_node) - expect_equal(length(xml2::xml_find_all(linear_solver_xml, - "/linear_solver/eigen/*")), 4) - expect_equal(xml2::xml_text( - xml2::xml_find_all(linear_solver_xml, - "/linear_solver/eigen/precon_type")), - "ILUT") + expect_equal(length(xml2::xml_find_all(insitu_xml, + "/insitu/scripts/*")), 3) }) @@ -155,7 +144,7 @@ test_that("to_node works for classes that have attributes", { tl_process <- r2ogs6_tl_process( ref = "HM", nonlinear_solver = "basic_newton", - convergence_criterion = list( + convergence_criterion = r2ogs6_convergence_criterion( type = "PerComponentDeltaX", norm_type = "NORM2", reltols = "5e-8 1e10 1e10" diff --git a/tests/testthat/test-generate_benchmark_script.R b/tests/testthat/test-generate_benchmark_script.R index b1c8e882bb4c3df797a91e319995988193c8f030..5cc3f319ec32a784f16dd20c43fd154e2b6db292 100644 --- a/tests/testthat/test-generate_benchmark_script.R +++ b/tests/testthat/test-generate_benchmark_script.R @@ -24,7 +24,8 @@ test_that("construct_add_call works", { expect_equal(ogs_param_call, paste0("ogs6_obj$add_parameter(", "r2ogs6_parameter(name = \"a\",\n", "type = \"t\",\n", - "values = c(0, 1)))\n")) + "values = c(0, 1),\n", + "value = NULL))\n")) ogs_mesh <- r2ogs6_mesh("my_mesh") ogs_mesh_call <- construct_add_call(ogs_mesh) diff --git a/tests/testthat/test-generate_class.R b/tests/testthat/test-generate_class.R index 2c9ae347d247dc11e452a66e9a5ccb674836cd04..e88560be931ed92183cf24ec346aa9729fbc7b96 100644 --- a/tests/testthat/test-generate_class.R +++ b/tests/testthat/test-generate_class.R @@ -1,9 +1,9 @@ -test_that("flags_to_str works", { +test_that("flags_to_con_str works", { flags <- c(a = TRUE, b = TRUE, c = FALSE) - str <- flags_to_str(flags) + str <- flags_to_con_str(flags) - expect_equal(str, "a, b, c = NULL") + expect_equal(str, "a,\nb,\nc = NULL") }) diff --git a/tests/testthat/test-prj_time_loop.R b/tests/testthat/test-prj_time_loop.R index 418ce618245af09da2eeea4e7e12f289e12c503b..82032bc3a4765a82724d0746bdb1c3ae1ef1e593 100644 --- a/tests/testthat/test-prj_time_loop.R +++ b/tests/testthat/test-prj_time_loop.R @@ -37,19 +37,3 @@ test_that("new_r2ogs6_time_loop basic validation is working", { ) }) - - -test_that("new_r2ogs6_tl_process basic validation is working", { - - - -}) - - -test_that("new_r2ogs6_tl_output basic validation is working", { - - - -}) - - diff --git a/tests/testthat/test-read_in_prj.R b/tests/testthat/test-read_in_prj.R index 7663729f22700edd8aef4a3f3424cbf3ad990b80..00de6fdac87a67b7d9497855c44f2ab1784eeb1d 100644 --- a/tests/testthat/test-read_in_prj.R +++ b/tests/testthat/test-read_in_prj.R @@ -1,6 +1,22 @@ -#processes +test_that("read_in works for process objects", { + + prj_path <- (system.file("extdata/flow_free_expansion", + "flow_free_expansion.prj", package = "r2ogs6")) + + ogs6_obj <- OGS6$new(sim_name = "sim", + sim_id = 1, + sim_path = "sim_path", + ogs_bin_path = "ogs_bin_path", + test_mode = TRUE) + + read_in(ogs6_obj, + prj_path, + "/OpenGeoSysProject/processes/process") + + expect_equal(length(ogs6_obj$processes), 1) +}) @@ -15,9 +31,9 @@ test_that("read_in works for medium objects", { ogs_bin_path = "ogs_bin_path", test_mode = TRUE) - read_in(ogs6_obj, prj_path, "media", "medium", - subclasses_names = c(phase = "r2ogs6_medium_phase", - property = "r2ogs6_medium_property")) + read_in(ogs6_obj, + prj_path, + "/OpenGeoSysProject/media/medium") expect_equal(length(ogs6_obj$media), 1) }) @@ -34,12 +50,9 @@ test_that("read_in works for time_loop objects", { ogs_bin_path = "ogs_bin_path", test_mode = TRUE) - read_in(ogs6_obj, prj_path, "time_loop", "time_loop", - subclasses_names = - c(process = "r2ogs6_tl_process", - output = "r2ogs6_tl_output", - global_processes_coupling = - "r2ogs6_global_processes_coupling")) + read_in(ogs6_obj, + prj_path, + "/OpenGeoSysProject/time_loop") expect_equal(is.null(ogs6_obj$time_loop), FALSE) }) @@ -56,12 +69,14 @@ test_that("read_in works for parameter objects", { ogs_bin_path = "ogs_bin_path", test_mode = TRUE) - read_in(ogs6_obj, prj_path, "parameters", "parameter") + read_in(ogs6_obj, + prj_path, + "/OpenGeoSysProject/parameters/parameter") expect_equal(length(ogs6_obj$parameters), 7) expect_equal(ogs6_obj$parameters[[1]]$name, "E") expect_equal(ogs6_obj$parameters[[1]]$type, "Constant") - expect_equal(ogs6_obj$parameters[[1]]$values, 10e9) + expect_equal(ogs6_obj$parameters[[1]]$value, 10e9) }) test_that("read_in works for process_variable objects", { @@ -75,9 +90,9 @@ test_that("read_in works for process_variable objects", { ogs_bin_path = "ogs_bin_path", test_mode = TRUE) - read_in(ogs6_obj, prj_path, "process_variables", "process_variable", - subclasses_names = c(boundary_condition = - "r2ogs6_boundary_condition")) + read_in(ogs6_obj, + prj_path, + "/OpenGeoSysProject/process_variables/process_variable") expect_equal(length(ogs6_obj$process_variables), 2) }) @@ -93,13 +108,16 @@ test_that("read_in works for nonlinear_solver objects", { ogs_bin_path = "ogs_bin_path", test_mode = TRUE) - read_in(ogs6_obj, prj_path, "nonlinear_solvers", "nonlinear_solver") + read_in(ogs6_obj, + prj_path, + "/OpenGeoSysProject/nonlinear_solvers/nonlinear_solver") expect_equal(length(ogs6_obj$nonlinear_solvers), 1) expect_equal(ogs6_obj$nonlinear_solvers[[1]]$name, "basic_newton") expect_equal(ogs6_obj$nonlinear_solvers[[1]]$type, "Newton") expect_equal(ogs6_obj$nonlinear_solvers[[1]]$max_iter, 50) - expect_equal(ogs6_obj$nonlinear_solvers[[1]]$linear_solver, "general_linear_solver") + expect_equal(ogs6_obj$nonlinear_solvers[[1]]$linear_solver, + "general_linear_solver") }) @@ -114,13 +132,13 @@ test_that("read_in works for linear_solver objects", { ogs_bin_path = "ogs_bin_path", test_mode = TRUE) - read_in(ogs6_obj, prj_path, "linear_solvers", "linear_solver") + read_in(ogs6_obj, + prj_path, + "/OpenGeoSysProject/linear_solvers/linear_solver") expect_equal(length(ogs6_obj$linear_solvers), 1) expect_equal(ogs6_obj$linear_solvers[[1]]$name, "general_linear_solver") - expect_equal(ogs6_obj$linear_solvers[[1]]$lis, "-i bicgstab -p ilu -tol 1e-16 -maxiter 10000") - expect_equal(ogs6_obj$linear_solvers[[1]]$eigen, list(solver_type = "BiCGSTAB", - precon_type = "ILUT", - max_iteration_step = 10000, - error_tolerance = 1e-16)) + expect_equal(ogs6_obj$linear_solvers[[1]]$lis, + "-i bicgstab -p ilu -tol 1e-16 -maxiter 10000") + expect_equal(ogs6_obj$linear_solvers[[1]]$eigen$error_tolerance, 1e-16) }) diff --git a/tests/testthat/test-read_in_utils.R b/tests/testthat/test-read_in_utils.R index 1adcf8cc2ed9fd6d85b984000bfc3a4f967f0343..0779066c36d17abb0b909d227fe7f4172feeac78 100644 --- a/tests/testthat/test-read_in_utils.R +++ b/tests/testthat/test-read_in_utils.R @@ -18,12 +18,12 @@ test_that("guess_structure works", { ogs_bin_path = "ogs_bin_path", test_mode = TRUE) - read_in(ogs6_obj, prj_path, "parameters", "parameter") + read_in(ogs6_obj, prj_path, "/OpenGeoSysProject/parameters/parameter") expect_equal(length(ogs6_obj$parameters), 7) expect_equal(ogs6_obj$parameters[[1]]$name, "E") expect_equal(ogs6_obj$parameters[[1]]$type, "Constant") - expect_equal(ogs6_obj$parameters[[1]]$values, 10e9) + expect_equal(ogs6_obj$parameters[[1]]$value, 10e9) }) diff --git a/tests/testthat/test-scrape_benchmarks.R b/tests/testthat/test-scrape_benchmarks.R index 2b5154cc4a7243f59e5a8f31e8395c305c07e94b..445ccbe52078df90e9c077af6664cc0bef353ee1 100644 --- a/tests/testthat/test-scrape_benchmarks.R +++ b/tests/testthat/test-scrape_benchmarks.R @@ -13,7 +13,7 @@ test_that("download_benchmark works", { - path <- paste0(system.file("extdata/benchmarks/", package = "r2ogs6"), "/") + path <- system.file("extdata/benchmarks/", package = "r2ogs6") download_benchmark( prj_url = paste0("https://gitlab.opengeosys.org/ogs/ogs/-/raw/master/", diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R new file mode 100644 index 0000000000000000000000000000000000000000..8a67e071a66a6aef1d777de03762af1d5b7768a2 --- /dev/null +++ b/tests/testthat/test-utils.R @@ -0,0 +1,34 @@ + + +test_that("select_fitting_subclass works for medium objects", { + + subclass_names <- get_subclass_names("r2ogs6_medium") + + for(i in seq_len(length(subclass_names))){ + names(subclass_names)[[i]] <- + get_class_tag_name(subclass_names[[i]]) + } + + subclass_name <- + select_fitting_subclass("phase/properties/property", + subclass_names) + + expect_equal(subclass_name, "r2ogs6_ph_property") +}) + + +test_that("select_fitting_subclass works for linear_solver objects", { + + subclass_names <- get_subclass_names("r2ogs6_linear_solver") + + for(i in seq_len(length(subclass_names))){ + names(subclass_names)[[i]] <- + get_class_tag_name(subclass_names[[i]]) + } + + subclass_name <- + select_fitting_subclass("linear_solvers/linear_solver/eigen", + subclass_names) + + expect_equal(subclass_name, "r2ogs6_eigen") +})