Skip to content
Snippets Groups Projects
Commit 782c6063 authored by Ruben Heinrich's avatar Ruben Heinrich
Browse files

[tests] added tests

parent c68af695
No related branches found
No related tags found
1 merge request!6Merge branch 7 fixed functionality into master
...@@ -14,7 +14,7 @@ test_that("export_prj works", { ...@@ -14,7 +14,7 @@ test_that("export_prj works", {
test_mode = TRUE) test_mode = TRUE)
prj_path <- (system.file("extdata/flow_free_expansion", prj_path <- (system.file("extdata/benchmarks/flow_free_expansion",
"flow_free_expansion.prj", package = "r2ogs6")) "flow_free_expansion.prj", package = "r2ogs6"))
read_in_prj(ogs6_obj, prj_path) read_in_prj(ogs6_obj, prj_path)
......
...@@ -27,20 +27,24 @@ test_that("to_node works for vectors", { ...@@ -27,20 +27,24 @@ test_that("to_node works for vectors", {
test_that("to_node works for attribute vectors", { test_that("to_node works for attribute vectors", {
my_attr_list <- list(a = c(id = 0, name = "Alice"), my_attr_list <- list(a = c(id = 0, name = "Alice"),
a = c(id = 3, name = "Bob")) b = c(id = 3))
attr_names = c("a") attr_node <- to_node(my_attr_list,
object_name = "my_attr_list",
c("a", "b"))
attr_node <- to_node(my_attr_list, NULL, c("a"))
attr_xml <- xml2::as_xml_document(attr_node) attr_xml <- xml2::as_xml_document(attr_node)
expect_equal(xml2::xml_attrs(xml2::xml_find_first(attr_xml, expect_equal(xml2::xml_attrs(xml2::xml_find_first(attr_xml,
"/my_attr_list/a")), "/my_attr_list/a")),
c(id = "0", name = "Alice")) c(id = "0", name = "Alice"))
expect_equal(xml2::xml_attrs(xml2::xml_find_first(attr_xml,
"/my_attr_list/b")),
c(id = "3"))
}) })
test_that("to_node works reads parameter names implicitly if not given", { test_that("to_node reads parameter names implicitly if not given", {
test_class <- function(x){ test_class <- function(x){
structure(list(x = x, structure(list(x = x,
......
test_that("read_in_points correctly reads point tibble from file", { test_that("read_in_points correctly reads point tibble from file", {
xml_doc <- validate_read_in_xml(system.file("extdata/flow_free_expansion", xml_doc <- validate_read_in_xml(
"cube_1x1x1.gml", system.file("extdata/benchmarks/flow_free_expansion",
package = "r2ogs6")) "cube_1x1x1.gml",
package = "r2ogs6"))
point_tibble <- read_in_points(xml_doc) point_tibble <- read_in_points(xml_doc)
expect_equal(length(point_tibble), 4) expect_equal(length(point_tibble), 4)
...@@ -14,9 +15,10 @@ test_that("read_in_points correctly reads point tibble from file", { ...@@ -14,9 +15,10 @@ test_that("read_in_points correctly reads point tibble from file", {
test_that("read_in_polylines correctly reads polyline list from file", { test_that("read_in_polylines correctly reads polyline list from file", {
xml_doc <- validate_read_in_xml(system.file("extdata/flow_free_expansion", xml_doc <- validate_read_in_xml(
"cube_1x1x1.gml", system.file("extdata/benchmarks/flow_free_expansion",
package = "r2ogs6")) "cube_1x1x1.gml",
package = "r2ogs6"))
polyline_list <- read_in_polylines(xml_doc) polyline_list <- read_in_polylines(xml_doc)
...@@ -30,9 +32,10 @@ test_that("read_in_polylines correctly reads polyline list from file", { ...@@ -30,9 +32,10 @@ test_that("read_in_polylines correctly reads polyline list from file", {
test_that("read_in_surfaces correctly reads surface list from file", { test_that("read_in_surfaces correctly reads surface list from file", {
xml_doc <- validate_read_in_xml(system.file("extdata/flow_free_expansion", xml_doc <- validate_read_in_xml(
"cube_1x1x1.gml", system.file("extdata/benchmarks/flow_free_expansion",
package = "r2ogs6")) "cube_1x1x1.gml",
package = "r2ogs6"))
surface_list <- read_in_surfaces(xml_doc) surface_list <- read_in_surfaces(xml_doc)
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
test_that("read_in works for process objects", { test_that("read_in works for process objects", {
prj_path <- (system.file("extdata/flow_free_expansion", prj_path <- (system.file("extdata/benchmarks/flow_free_expansion",
"flow_free_expansion.prj", package = "r2ogs6")) "flow_free_expansion.prj", package = "r2ogs6"))
ogs6_obj <- OGS6$new(sim_name = "sim", ogs6_obj <- OGS6$new(sim_name = "sim",
...@@ -29,7 +29,7 @@ test_that("read_in works for process objects", { ...@@ -29,7 +29,7 @@ test_that("read_in works for process objects", {
test_that("read_in works for medium objects", { test_that("read_in works for medium objects", {
prj_path <- (system.file("extdata/flow_free_expansion", prj_path <- (system.file("extdata/benchmarks/flow_free_expansion",
"flow_free_expansion.prj", package = "r2ogs6")) "flow_free_expansion.prj", package = "r2ogs6"))
ogs6_obj <- OGS6$new(sim_name = "sim", ogs6_obj <- OGS6$new(sim_name = "sim",
...@@ -48,7 +48,7 @@ test_that("read_in works for medium objects", { ...@@ -48,7 +48,7 @@ test_that("read_in works for medium objects", {
test_that("read_in works for time_loop objects", { test_that("read_in works for time_loop objects", {
prj_path <- (system.file("extdata/flow_free_expansion", prj_path <- (system.file("extdata/benchmarks/flow_free_expansion",
"flow_free_expansion.prj", package = "r2ogs6")) "flow_free_expansion.prj", package = "r2ogs6"))
ogs6_obj <- OGS6$new(sim_name = "sim", ogs6_obj <- OGS6$new(sim_name = "sim",
...@@ -70,7 +70,7 @@ test_that("read_in works for time_loop objects", { ...@@ -70,7 +70,7 @@ test_that("read_in works for time_loop objects", {
test_that("read_in works for parameter objects", { test_that("read_in works for parameter objects", {
prj_path <- (system.file("extdata/flow_free_expansion", prj_path <- (system.file("extdata/benchmarks/flow_free_expansion",
"flow_free_expansion.prj", package = "r2ogs6")) "flow_free_expansion.prj", package = "r2ogs6"))
ogs6_obj <- OGS6$new(sim_name = "sim", ogs6_obj <- OGS6$new(sim_name = "sim",
...@@ -91,7 +91,7 @@ test_that("read_in works for parameter objects", { ...@@ -91,7 +91,7 @@ test_that("read_in works for parameter objects", {
test_that("read_in works for process_variable objects", { test_that("read_in works for process_variable objects", {
prj_path <- (system.file("extdata/flow_free_expansion", prj_path <- (system.file("extdata/benchmarks/flow_free_expansion",
"flow_free_expansion.prj", package = "r2ogs6")) "flow_free_expansion.prj", package = "r2ogs6"))
ogs6_obj <- OGS6$new(sim_name = "sim", ogs6_obj <- OGS6$new(sim_name = "sim",
...@@ -109,7 +109,7 @@ test_that("read_in works for process_variable objects", { ...@@ -109,7 +109,7 @@ test_that("read_in works for process_variable objects", {
test_that("read_in works for nonlinear_solver objects", { test_that("read_in works for nonlinear_solver objects", {
prj_path <- (system.file("extdata/flow_free_expansion", prj_path <- (system.file("extdata/benchmarks/flow_free_expansion",
"flow_free_expansion.prj", package = "r2ogs6")) "flow_free_expansion.prj", package = "r2ogs6"))
ogs6_obj <- OGS6$new(sim_name = "sim", ogs6_obj <- OGS6$new(sim_name = "sim",
...@@ -133,7 +133,7 @@ test_that("read_in works for nonlinear_solver objects", { ...@@ -133,7 +133,7 @@ test_that("read_in works for nonlinear_solver objects", {
test_that("read_in works for linear_solver objects", { test_that("read_in works for linear_solver objects", {
prj_path <- (system.file("extdata/flow_free_expansion", prj_path <- (system.file("extdata/benchmarks/flow_free_expansion",
"flow_free_expansion.prj", package = "r2ogs6")) "flow_free_expansion.prj", package = "r2ogs6"))
ogs6_obj <- OGS6$new(sim_name = "sim", ogs6_obj <- OGS6$new(sim_name = "sim",
...@@ -152,3 +152,64 @@ test_that("read_in works for linear_solver objects", { ...@@ -152,3 +152,64 @@ test_that("read_in works for linear_solver objects", {
"-i bicgstab -p ilu -tol 1e-16 -maxiter 10000") "-i bicgstab -p ilu -tol 1e-16 -maxiter 10000")
expect_equal(ogs6_obj$linear_solvers[[1]]$eigen$error_tolerance, 1e-16) expect_equal(ogs6_obj$linear_solvers[[1]]$eigen$error_tolerance, 1e-16)
}) })
test_that("read_in works with newline value separation", {
prj_path <- (system.file("extdata/benchmarks/LiakopoulosHM",
"liakopoulos.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/curves/curve")
expect_equal(length(ogs6_obj$curves), 1)
expect_equal(length(ogs6_obj$curves[[1]]$coords), 61)
expect_equal(ogs6_obj$curves[[1]]$coords[[1]], 0.2)
expect_equal(length(ogs6_obj$curves[[1]]$values), 61)
expect_equal(ogs6_obj$curves[[1]]$values[[1]], 0.0)
})
test_that("read_in works for processes/include tags", {
prj_path <- (system.file("extdata/benchmarks/Elliptic/circle_radius_1",
"circle_1e1_axi.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_prj(ogs6_obj,
prj_path)
expect_equal(length(ogs6_obj$processes), 1)
expect_equal(names(ogs6_obj$processes)[[1]], "include")
})
test_that("read_in_prj works for EmbeddedFracturePermeability/cube.prj", {
prj_path <- (system.file("extdata/benchmarks/EmbeddedFracturePermeability/",
"cube.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_prj(ogs6_obj,
prj_path)
expect_equal(ogs6_obj$processes[[1]]$name, "HM")
})
...@@ -7,9 +7,9 @@ ...@@ -7,9 +7,9 @@
# }) # })
test_that("guess_structure works for simple r2ogs6 classes", { test_that("node_to_object works for simple r2ogs6 classes", {
prj_path <- (system.file("extdata/flow_free_expansion", prj_path <- (system.file("extdata/benchmarks/flow_free_expansion",
"flow_free_expansion.prj", package = "r2ogs6")) "flow_free_expansion.prj", package = "r2ogs6"))
ogs6_obj <- OGS6$new(sim_name = "sim", ogs6_obj <- OGS6$new(sim_name = "sim",
...@@ -27,6 +27,24 @@ test_that("guess_structure works for simple r2ogs6 classes", { ...@@ -27,6 +27,24 @@ test_that("guess_structure works for simple r2ogs6 classes", {
}) })
test_that("node_to_object works for nodes that have both attributes and text", {
vtu_path <- system.file("extdata/benchmarks/flow_free_expansion",
"cube_1x1x1.vtu",
package = "r2ogs6")
test_node <- xml2::read_xml("<test a = \"1\">some text</test>")
test_obj <- node_to_object(test_node,
xpath_expr = "\test")
expect_equal(length(test_obj), 2)
expect_equal(test_obj[["a"]], "1")
expect_equal(test_obj[["xml_text"]], "some text")
})
test_that("node_to_object works for simple lists", { test_that("node_to_object works for simple lists", {
my_xml <- xml2::read_xml("<a><b>1</b><b>2</b></a>") my_xml <- xml2::read_xml("<a><b>1</b><b>2</b></a>")
......
test_that("read_in_vtu works", {
vtu_path <- system.file("extdata/flow_free_expansion",
"cube_1x1x1.vtu",
package = "r2ogs6")
vtu_obj <- read_in_vtu(vtu_path = vtu_path)
expect_equal(vtu_obj$UnstructuredGrid$Piece$NumberOfPoints, "8")
})
...@@ -39,3 +39,36 @@ ...@@ -39,3 +39,36 @@
# }) # })
test_that("export_all_sim_files works", {
extdata_path <- system.file("extdata/", package = "r2ogs6")
test_path <- paste0(extdata_path, "/export_all_sim_files_test")
dir.create(test_path)
prj_path <- (system.file("extdata/benchmarks/Elliptic/circle_radius_1",
"circle_1e1_axi.prj", package = "r2ogs6"))
ogs6_obj <- OGS6$new(sim_name = "circle_1e1_axi",
sim_id = 1,
sim_path = test_path,
ogs_bin_path = "ogs_bin_path",
test_mode = TRUE)
read_in_prj(ogs6_obj,
prj_path)
# Now export all files
export_all_sim_files(ogs6_obj)
expect_equal(file.exists(paste0(test_path, "/circle_1e1_axi.prj")),
TRUE)
expect_equal(file.exists(paste0(test_path,
"/include/SteadyStateDiffusion.xml")),
TRUE)
# Tidy up by deleting the folder we created
unlink(test_path, recursive = TRUE)
})
# helper function to skip tests if we don't have python dependencies
skip_if_python_modules_missing <- function() {
used_modules <- c("vtk",
"vtk.numpy_interface.dataset_adapter",
"zlib")
lapply(used_modules, function(x){
if(!reticulate::py_module_available(x)){
skip(paste(x, "not available for testing"))
}
})
}
#===== 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$get_timestep_by_vtu_path(vtu_path = vtu_path)
expect_equal(timestep, "99.9999999999986")
})
test_that("OGS6_pvd$get_PointData_time_tibble works", {
skip_if_python_modules_missing()
pvd_path <- system.file("extdata/benchmarks/flow_no_strain",
"flow_no_strain.pvd",
package = "r2ogs6")
ogs6_pvd <- OGS6_pvd$new(pvd_path)
Names <- c("pressure",
"velocity")
time_tibble <- ogs6_pvd$get_PointData_time_tibble(Names = Names)
expect_equal(length(time_tibble), 2)
})
#===== OGS6_vtu =====
test_that("read_in_vtu works", {
vtu_path <- system.file("extdata/benchmarks/flow_free_expansion",
"cube_1x1x1.vtu",
package = "r2ogs6")
ogs6_vtu <- read_in_vtu(vtu_path = vtu_path)
expect_equal("vtkmodules.vtkCommonDataModel.vtkUnstructuredGrid" %in%
class(ogs6_vtu$vtkUnstructuredGrid), TRUE)
})
#===== generate_structured_mesh =====
#Add test...
#===== read_in_PointData_DataArray =====
test_that("read_in_PointData_DataArray works", {
skip_if_python_modules_missing()
vtu_path <- system.file("extdata/benchmarks/flow_free_expansion",
"flow_free_expansion_ts_1000_t_10000.000000.vtu",
package = "r2ogs6")
vtu_obj <- read_in_vtu(vtu_path)
pd_data_array <- vtu_obj$get_PointData_DataArray(Name = "HydraulicFlow")
expect_equal(class(pd_data_array), "array")
})
#===== General .vtk library tests =====
test_that("zlib decompressing works as expected", {
skip_if_python_modules_missing()
py_env <- reticulate::py_run_string(
paste(
"import zlib",
"test_data = bytearray('123', 'utf-8')",
"compr_data = zlib.compress(test_data)",
"decompr_data = zlib.decompress(compr_data)",
"check = test_data.decode('utf-8') == decompr_data.decode('utf-8')",
sep = "\n"
),
convert = TRUE
)
expect_equal(py_env$check, TRUE)
})
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment