diff --git a/base/visualization/DESCRIPTION b/base/visualization/DESCRIPTION index 201bffdada4..2aece439bdd 100644 --- a/base/visualization/DESCRIPTION +++ b/base/visualization/DESCRIPTION @@ -42,10 +42,12 @@ Imports: stringr(>= 1.1.0) Suggests: grid, + mockery, png, raster, sp, - testthat (>= 1.0.2) + testthat (>= 1.0.2), + withr License: BSD_3_clause + file LICENSE Copyright: Authors LazyLoad: yes diff --git a/base/visualization/R/plots.R b/base/visualization/R/plots.R index f93f3eacf10..3f1395305bc 100644 --- a/base/visualization/R/plots.R +++ b/base/visualization/R/plots.R @@ -188,7 +188,7 @@ iqr <- function(x) { ##' ##' Used to add raw data or summary statistics to the plot of a distribution. ##' The height of Y is arbitrary, and can be set to optimize visualization. -##' If SE estimates are available, the se wil be plotted +##' If SE estimates are available, the SE will be plotted ##' @name plot_data ##' @aliases plot.data ##' @title Add data to plot diff --git a/base/visualization/man/plot_data.Rd b/base/visualization/man/plot_data.Rd index b54ad1dbca8..37d741dbd0b 100644 --- a/base/visualization/man/plot_data.Rd +++ b/base/visualization/man/plot_data.Rd @@ -24,7 +24,7 @@ Add data to an existing plot or create a new one \details{ Used to add raw data or summary statistics to the plot of a distribution. The height of Y is arbitrary, and can be set to optimize visualization. -If SE estimates are available, the se wil be plotted +If SE estimates are available, the SE will be plotted } \examples{ \dontrun{plot_data(data.frame(Y = c(1, 2), se = c(1,2)), base.plot = NULL, ymax = 10)} diff --git a/base/visualization/tests/testthat/data/urbana_subdaily_test.nc b/base/visualization/tests/testthat/data/urbana_subdaily_test.nc new file mode 100644 index 00000000000..3e7ceef3671 Binary files /dev/null and b/base/visualization/tests/testthat/data/urbana_subdaily_test.nc differ diff --git a/base/visualization/tests/testthat/test.add_icon.R b/base/visualization/tests/testthat/test.add_icon.R new file mode 100644 index 00000000000..d487b87714e --- /dev/null +++ b/base/visualization/tests/testthat/test.add_icon.R @@ -0,0 +1,7 @@ +test_that("`add_icon()` able to create the correct output file", { + withr::with_dir(tempdir(), { + add_icon(1, 2, 3) + # check if file exists + expect_true(file.exists("Rplots.pdf")) + }) +}) \ No newline at end of file diff --git a/base/visualization/tests/testthat/test.plot_data.R b/base/visualization/tests/testthat/test.plot_data.R new file mode 100644 index 00000000000..25264be0474 --- /dev/null +++ b/base/visualization/tests/testthat/test.plot_data.R @@ -0,0 +1,7 @@ +test_that("`plot_data()` able to create a new plot for data passed to it", { + withr::with_dir(tempdir(), { + res <- plot_data(data.frame(Y = c(1, 2), se = c(1,2), trt = c(1, 2)), base.plot = NULL, ymax = 10) + print(res) + expect_true(file.exists(paste0(getwd(), "/Rplots.pdf"))) + }) +}) \ No newline at end of file diff --git a/base/visualization/tests/testthat/test.plot_netcdf.R b/base/visualization/tests/testthat/test.plot_netcdf.R new file mode 100644 index 00000000000..c0e32252adc --- /dev/null +++ b/base/visualization/tests/testthat/test.plot_netcdf.R @@ -0,0 +1,21 @@ +test_that("`data.fetch()` able to return aggregated data with the correct label", { + nc <- ncdf4::nc_open("./data/urbana_subdaily_test.nc") + on.exit(ncdf4::nc_close(nc)) + + res <- data.fetch("time", nc, mean) + expect_equal(attr(res, "lbl"), "days since 1700-01-01T00:00:00Z") + + res <- data.fetch("air_temperature", nc, mean) + expect_equal(attr(res, "lbl"), "3-hourly Air Temperature at 2m in K") +}) + +test_that("`plot_netcdf()` able to correctly plot the netcdf file data and create the plot file at the desired location", { + nc <- ncdf4::nc_open("./data/urbana_subdaily_test.nc") + withr::with_dir(tempdir(), { + mockery::stub(plot_netcdf, 'ncdf4::nc_open', nc) + res <- plot_netcdf("./data/urbana_subdaily_test.nc", "time", "air_temperature", year = 2010) + + # check if file exists + expect_true(file.exists("Rplots.pdf")) + }) +}) \ No newline at end of file