Skip to content

Commit

Permalink
update function to return empty data.table + doc + tests (using new r…
Browse files Browse the repository at this point in the history
…ef properties)
  • Loading branch information
berthetclement committed Jul 10, 2024
1 parent 415565d commit 82438dd
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 24 deletions.
9 changes: 4 additions & 5 deletions R/readClusterDesc.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
#' \code{readClusterResDesc} : read renewable clusters (Antares >= V8.1)
#'
#' \code{readClusterSTDesc} : read st-storage clusters (Antares >= V8.6)
#'
#' If you have no clusters properties, `Null data.table (0 rows and 0 cols)` is returned.
#'
#' @examples
#'
Expand Down Expand Up @@ -185,11 +187,8 @@ readClusterSTDesc <- function(opts = simOptions()) {
res <- data.table::rbindlist(l = res, fill = TRUE)

# NO PROPERTIES CLUSTER FOUND
if(length(res) == 0){
warning("No properties found",
call. = FALSE)
return(NULL)
}
if(length(res) == 0)
return(data.table())

# output format conversion
res <- data.table::as.data.table(res)
Expand Down
2 changes: 2 additions & 0 deletions man/readClusterDesc.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

70 changes: 51 additions & 19 deletions tests/testthat/test-readClusterDesc.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ test_that("test read cluster", {
path_study_test <- studyPathS
opts_study_test <- setSimulationPath(path_study_test, simulation = "input")

#minimal columns
mandatory_cols <- c("area","cluster")

# function setSimulationPath() provide areas names with st-storage clusters
areas <- opts_study_test$areasWithClusters

Expand All @@ -17,18 +14,29 @@ test_that("test read cluster", {
# tests
testthat::expect_true("data.table" %in% class(input))
testthat::expect_true(all(areas %in% unique(input$area)))
testthat::expect_true(all(mandatory_cols %in% colnames(input)))
testthat::expect_true(nrow(input) == length(input$cluster))

# tests if all colnames are returned according to ref
ref_thermal <- antaresRead:::pkgEnv$inputProperties[
Category%in%"thermal"]
ref_thermal <- ref_thermal[`Version Antares` <=
opts_study_test$antaresVersion |
`Version Antares` %in% NA]

# "name" in INI file corresponding "cluster" in output
testthat::expect_true(all(
setdiff(ref_thermal$`INI Name`, "name")%in%
setdiff(colnames(input), c("area", "cluster"))))

# object returned is one line per area/cluster
testthat::expect_equal(nrow(input), nrow(unique(input)))
})

## Renewables ----
test_that("test read cluster renewables", {
path_study_test <- grep(pattern = "87", x = studyPathSV8, value = TRUE)
path_study_test <- grep(pattern = "test_case_study_v870",
x = studyPathSV8, value = TRUE)
opts_study_test <- setSimulationPath(path_study_test, simulation = "input")

#minimal columns
mandatory_cols <- c("area","cluster")

# function setSimulationPath() provide areas names with st-storage clusters
areas_res <- opts_study_test$areasWithResClusters

Expand All @@ -38,19 +46,30 @@ test_that("test read cluster renewables", {
# tests
testthat::expect_true("data.table" %in% class(input))
testthat::expect_true(all(areas_res %in% unique(input$area)))
testthat::expect_true(all(mandatory_cols %in% colnames(input)))
testthat::expect_true(nrow(input) == length(input$cluster))

# tests if all colnames are returned according to ref
ref_res <- antaresRead:::pkgEnv$inputProperties[
Category%in%"renewable"]
ref_res <- ref_res[`Version Antares` <=
opts_study_test$antaresVersion |
`Version Antares` %in% NA]

# "name" in INI file corresponding "cluster" in output
testthat::expect_true(all(
setdiff(ref_res$`INI Name`, "name")%in%
setdiff(colnames(input), c("area", "cluster"))))

# object returned is one line per area/cluster
testthat::expect_equal(nrow(input), nrow(unique(input)))
})

# v860 ----
## st-storage ----
test_that("test read cluster st-storage v860", {
path_study_test <- grep(pattern = "87", x = studyPathSV8, value = TRUE)
path_study_test <- grep(pattern = "test_case_study_v870",
x = studyPathSV8, value = TRUE)
opts_study_test <- setSimulationPath(path_study_test, simulation = "input")

#minimal columns
mandatory_cols <- c("area","cluster")

# function setSimulationPath() provide areas names with st-storage clusters
areas_st <- opts_study_test$areasWithSTClusters

Expand All @@ -61,15 +80,28 @@ test_that("test read cluster st-storage v860", {
testthat::expect_true("data.table" %in% class(input_st))
testthat::expect_true(all(
areas_st %in% unique(readClusterSTDesc()$area)))
testthat::expect_true(all(areas_st %in% unique(readClusterSTDesc()$area)))
testthat::expect_true(all(mandatory_cols %in% colnames(input_st)))
testthat::expect_true(nrow(input_st) == length(input_st$cluster))

# tests if all colnames are returned according to ref
ref_st <- antaresRead:::pkgEnv$inputProperties[
Category%in%"storage"]
ref_st <- ref_st[`Version Antares` <=
opts_study_test$antaresVersion |
`Version Antares` %in% NA]

# "name" in INI file corresponding "cluster" in output
testthat::expect_true(all(
setdiff(ref_st$`INI Name`, "name")%in%
setdiff(colnames(input_st), c("area", "cluster"))))

# object returned is one line per area/cluster
testthat::expect_equal(nrow(input_st), nrow(unique(input_st)))
})

# read empty study ----
test_that("test when study has no cluster (empty)", {
path_empty_study <- setup_study_empty(sourcedir_empty_study)
opts_study_test <- setSimulationPath(path_empty_study, simulation = "input")

readClusterDesc()
testthat::expect_equal(readClusterDesc(),
data.table::data.table())
})

0 comments on commit 82438dd

Please sign in to comment.