From b7dac0294df3a21ed37b2849fbc514d0c2575cb9 Mon Sep 17 00:00:00 2001
From: aheinri5 <Anna@netzkritzler.de>
Date: Fri, 25 Dec 2020 21:05:24 +0100
Subject: [PATCH] [tests] Modified tests

---
 tests/testthat/test-export_gml.R              | 46 ++++++++++++++++++
 .../testthat/test-generate_benchmark_script.R |  4 +-
 tests/testthat/test-ogs6.R                    | 24 +++++++++-
 tests/testthat/test-read_in_gml.R             |  9 ++--
 tests/testthat/test-scrape_benchmarks.R       | 48 +++++++++----------
 5 files changed, 101 insertions(+), 30 deletions(-)
 create mode 100644 tests/testthat/test-export_gml.R

diff --git a/tests/testthat/test-export_gml.R b/tests/testthat/test-export_gml.R
new file mode 100644
index 0000000..d549fa3
--- /dev/null
+++ b/tests/testthat/test-export_gml.R
@@ -0,0 +1,46 @@
+
+
+# test_that("export_gml works", {
+#
+#     test_gml <- r2ogs6_gml(
+#         name = "test_geometry",
+#         points = tibble::tibble(
+#             x = c(0, 0, 0, 0, 1, 1, 1, 1),
+#             y = c(0, 0, 1, 1, 0, 0, 1, 1),
+#             z = c(0, 1, 1, 0, 0, 1, 1, 0),
+#             name = c("origin", "", "", "", "", "", "", "")
+#         ),
+#         polylines = list(list(name = "test", c(1, 2, 3, 4, 1))),
+#         surfaces = list(list(name = "test", c(1, 2, 3), c(2, 3, 4)))
+#     )
+#
+#     path <- validate_is_dir_path(system.file("extdata/", package = "r2ogs6"))
+#
+#     filename <- paste0(path, "test_geometry.gml")
+#
+#     export_gml(test_gml, path)
+#
+#     expect_equal(file.exists(filename), TRUE)
+#
+#     #unlink(filename)
+# })
+
+
+test_that("converting tibble to list works", {
+
+    points = tibble::tibble(
+            x = c(0, 0, 0, 0, 1, 1, 1, 1),
+            y = c(0, 0, 1, 1, 0, 0, 1, 1),
+            z = c(0, 1, 1, 0, 0, 1, 1, 0),
+            name = c("origin", "", "", "", "", "", "", ""))
+
+    points_list <- setNames(split(points,
+                                  seq(nrow(points))),
+                            rep("point", nrow(points)))
+
+    points_list <- lapply(points_list, function(x){
+        as.list(x)
+    })
+
+    expect_equal("tbl_df" %in% class(points_list[[1]]), FALSE)
+})
diff --git a/tests/testthat/test-generate_benchmark_script.R b/tests/testthat/test-generate_benchmark_script.R
index 124f430..d698cc2 100644
--- a/tests/testthat/test-generate_benchmark_script.R
+++ b/tests/testthat/test-generate_benchmark_script.R
@@ -19,10 +19,10 @@ test_that("construct_add_call works", {
   list_call <- construct_add_call(my_list)
   expect_equal(list_call, "list(a = c(2, 3, 4),\nb = c(\"a\", \"b\", \"c\"))")
 
-  ogs_mesh <- OGS6_mesh$new("my_mesh")
+  ogs_mesh <- OGS6_vtu$new("my_mesh")
   ogs_mesh_call <- construct_add_call(ogs_mesh)
   expect_equal(ogs_mesh_call,
-               "ogs6_obj$add_mesh(OGS6_mesh$new(mesh_path = \"my_mesh\"))\n")
+               "ogs6_obj$add_vtu(OGS6_vtu$new(mesh_path = \"my_mesh\"))\n")
 
   ogs_param <- r2ogs6_parameter("a",
                                 "t",
diff --git a/tests/testthat/test-ogs6.R b/tests/testthat/test-ogs6.R
index 5a4ca1a..4713490 100644
--- a/tests/testthat/test-ogs6.R
+++ b/tests/testthat/test-ogs6.R
@@ -20,4 +20,26 @@ test_that("OGS6$clear() works as expected", {
     expect_equal(length(ogs6_obj$parameters), 1)
     expect_warning(ogs6_obj$clear(c("elephant", "parameters")))
     expect_equal(length(ogs6_obj$parameters), 0)
-})
\ No newline at end of file
+})
+
+
+test_that("add_component works", {
+
+    ogs6_obj <- OGS6$new(
+        sim_name = "sim",
+        sim_id = 1,
+        sim_path = "sim_path",
+        ogs_bin_path = "ogs_bin_path",
+        test_mode = TRUE
+    )
+
+    ogs6_obj$add_component(r2ogs6_parameter(
+        name = "pressure0",
+        type = "Constant",
+        values = 1e5
+    ))
+
+    expect_equal(length(ogs6_obj$parameters), 1)
+    expect_equal(ogs6_obj$parameters[[1]]$values, 1e5)
+})
+
diff --git a/tests/testthat/test-read_in_gml.R b/tests/testthat/test-read_in_gml.R
index 6413567..79e68de 100644
--- a/tests/testthat/test-read_in_gml.R
+++ b/tests/testthat/test-read_in_gml.R
@@ -2,7 +2,8 @@
 test_that("read_in_points correctly reads point tibble from file", {
 
     xml_doc <- validate_read_in_xml(system.file("extdata/flow_free_expansion",
-                                                "cube_1x1x1.gml", package = "r2ogs6"))
+                                                "cube_1x1x1.gml",
+                                                package = "r2ogs6"))
 
     point_tibble <- read_in_points(xml_doc)
     expect_equal(length(point_tibble), 4)
@@ -14,7 +15,8 @@ test_that("read_in_points correctly reads point tibble 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",
-                                                "cube_1x1x1.gml", package = "r2ogs6"))
+                                                "cube_1x1x1.gml",
+                                                package = "r2ogs6"))
 
     polyline_list <- read_in_polylines(xml_doc)
 
@@ -27,7 +29,8 @@ test_that("read_in_polylines correctly reads polyline 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",
-                                                "cube_1x1x1.gml", package = "r2ogs6"))
+                                                "cube_1x1x1.gml",
+                                                package = "r2ogs6"))
 
     surface_list <- read_in_surfaces(xml_doc)
 
diff --git a/tests/testthat/test-scrape_benchmarks.R b/tests/testthat/test-scrape_benchmarks.R
index 0d993d1..81f7da1 100644
--- a/tests/testthat/test-scrape_benchmarks.R
+++ b/tests/testthat/test-scrape_benchmarks.R
@@ -10,27 +10,27 @@
 # })
 
 
-test_that("download_benchmark works", {
-
-    # Get extdata directory and create folder for the test
-
-    extdata_path <- system.file("extdata/", package = "r2ogs6")
-
-    path <- paste0(extdata_path, "/dl_benchmark_test")
-
-    dir.create(path)
-
-    download_benchmark(
-        prj_url = paste0("https://gitlab.opengeosys.org/ogs/ogs/-/raw/master/",
-                         "Tests/Data/HydroMechanics/IdealGas/flow_no_strain/",
-                         "flow_no_strain.prj"),
-        path = path)
-
-    expect_equal(file.exists(paste0(path, "/flow_no_strain.prj")), TRUE)
-    expect_equal(file.exists(paste0(path, "/square_1x1.gml")), TRUE)
-    expect_equal(file.exists(paste0(path, "/square_1x1_quad8_1e2.vtu")), TRUE)
-
-    # Tidy up by deleting the folder we created
-
-    unlink(path, recursive = TRUE)
-})
+# test_that("download_benchmark works", {
+#
+#     # Get extdata directory and create folder for the test
+#
+#     extdata_path <- system.file("extdata/", package = "r2ogs6")
+#
+#     path <- paste0(extdata_path, "/dl_benchmark_test")
+#
+#     dir.create(path)
+#
+#     download_benchmark(
+#         prj_url = paste0("https://gitlab.opengeosys.org/ogs/ogs/-/raw/master/",
+#                          "Tests/Data/HydroMechanics/IdealGas/flow_no_strain/",
+#                          "flow_no_strain.prj"),
+#         path = path)
+#
+#     expect_equal(file.exists(paste0(path, "/flow_no_strain.prj")), TRUE)
+#     expect_equal(file.exists(paste0(path, "/square_1x1.gml")), TRUE)
+#     expect_equal(file.exists(paste0(path, "/square_1x1_quad8_1e2.vtu")), TRUE)
+#
+#     # Tidy up by deleting the folder we created
+#
+#     unlink(path, recursive = TRUE)
+# })
-- 
GitLab