From 48c4cd27b5d6795c46bf32bf0ce6e233387e5c69 Mon Sep 17 00:00:00 2001 From: aheinri5 <Anna@netzkritzler.de> Date: Fri, 11 Dec 2020 12:03:16 +0100 Subject: [PATCH] [tests] Linebreaks --- tests/testthat/test-export_prj.R | 30 ++++++++ .../testthat/test-generate_benchmark_script.R | 10 +++ tests/testthat/test-gml.R | 69 +++++++++++++++++++ 3 files changed, 109 insertions(+) create mode 100644 tests/testthat/test-export_prj.R create mode 100644 tests/testthat/test-gml.R diff --git a/tests/testthat/test-export_prj.R b/tests/testthat/test-export_prj.R new file mode 100644 index 0000000..89e45af --- /dev/null +++ b/tests/testthat/test-export_prj.R @@ -0,0 +1,30 @@ + +test_that("export_prj works", { + + # Get extdata directory and create folder for the test + extdata_path <- system.file("extdata/", package = "r2ogs6") + test_path <- paste0(extdata_path, "/export_prj_test") + dir.create(test_path) + + # 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, + ogs_bin_path = "ogs_bin_path", + test_mode = TRUE) + + + prj_path <- (system.file("extdata/flow_free_expansion", + "flow_free_expansion.prj", package = "r2ogs6")) + + read_in_prj(ogs6_obj, prj_path) + + # Now export it + export_prj(ogs6_obj) + + expect_equal(file.exists(paste0(test_path, "/flow_free_expansion.prj")), + TRUE) + + # Tidy up by deleting the folder we created + unlink(test_path, recursive = TRUE) +}) diff --git a/tests/testthat/test-generate_benchmark_script.R b/tests/testthat/test-generate_benchmark_script.R index 83bc9c0..cbdc7a8 100644 --- a/tests/testthat/test-generate_benchmark_script.R +++ b/tests/testthat/test-generate_benchmark_script.R @@ -53,4 +53,14 @@ test_that("delete_nulls_from_str works", { test_str_2 <- delete_nulls_from_str(test_str_2) expect_equal(test_str_2, "r2ogs6_object(two = 3)") +}) + + +test_that("delete_keywords_from_str works", { + + test_str <- "r2ogs6_object(a = \"foo\", repeat = \"bar\")" + + test_str <- delete_keywords_from_str(test_str) + expect_equal(test_str, "r2ogs6_object(a = \"foo\", \"bar\")") + }) \ No newline at end of file diff --git a/tests/testthat/test-gml.R b/tests/testthat/test-gml.R new file mode 100644 index 0000000..4671683 --- /dev/null +++ b/tests/testthat/test-gml.R @@ -0,0 +1,69 @@ +test_that("validate_points works", { + + point_list <- list(x = c(0, 0), y = c(1, 1), z = c(0, 1)) + + #Check class (should expect a tibble, not a list) + expect_error(validate_points(point_list)) + + point_tibble_inv_0 <- tibble::tibble(a = c(0, 0), b = c(1, 1), c = c(0, 1)) + point_tibble_inv_1 <- tibble::tibble(x = c(0, 0), y = c(1, 1), z = c(0)) + point_tibble_inv_2 <- tibble::tibble(x = c(0, 0), y = c(1, 1), z = c(0, 1), + name = c("oh", "oh")) + + #Check column names + expect_error(validate_points(point_tibble_inv_0)) + + #Check if duplicate points and point names are detected + expect_error(validate_points(point_tibble_inv_1)) + expect_warning(validate_points(point_tibble_inv_2)) + + point_tibble_val <- tibble::tibble(x = c(0, 0), y = c(1, 1), z = c(0, 1), + name = c("this", "works")) + point_tibble_val_2 <- tibble::tibble(x = c(0, 0), y = c(1, 1), z = c(0, 1)) + + expect_invisible(validate_points(point_tibble_val)) + expect_invisible(validate_points(point_tibble_val_2)) +}) + + +test_that("validate_polylines works", { + + polyline_list_inv_1 <- list(list(name = "wrong_length", + c(0, 1), + c(1, 2))) + polyline_list_inv_2 <- list(list(name = "wrong_points", + c("a", "b", "c"))) + + expect_error(validate_polylines(polyline_list_inv_1)) + expect_error(validate_polylines(polyline_list_inv_2)) + + polyline_list_val_0 <- list(list(name = "cool", + c(1, 2))) + polyline_list_val_1 <- list(list(name = "also cool", + c(1, 2, 4, 5, 1))) + + expect_invisible(validate_polylines(polyline_list_val_0)) + expect_invisible(validate_polylines(polyline_list_val_1)) + + polylines = list( + list("front_left", + c(0, 1)) + ) + + polylines <- validate_polylines(polylines) + + expect_equal(names(polylines), "polyline") + expect_equal(names(polylines[[1]])[[1]], "name") +}) + + +test_that("validate_surfaces works", { + + surface_tibble <- tibble::tibble(name = "tibble", + surface = c(c(0, 1, 2), c(1, 2, 3))) + + #Check class (should expect a list, not a tibble) + expect_error(validate_surfaces(surface_tibble)) + + #...(WIP) +}) \ No newline at end of file -- GitLab