Skip to content

Commit

Permalink
Merge pull request #148 from rte-antares-rpackage/feature/remove_bc870
Browse files Browse the repository at this point in the history
removeBindingConstraint() updated from code review comment + tests
  • Loading branch information
berthetclement authored Mar 28, 2024
2 parents 659e3f1 + 986743b commit bad682d
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 9 deletions.
12 changes: 7 additions & 5 deletions R/removeBindingConstraint.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,15 @@ removeBindingConstraint <- function(name = NULL,
assertthat::assert_that(inherits(opts, "simOptions"))

# some checks for "group" parameter according to study version
if(!opts$antaresVersion >= 870 & !is.null(group))
stop("Parameter 'group' is only for Antares study version >= v8.7.0",
call. = FALSE)
if(opts$antaresVersion >= 870){
if(!is.null(name) & !is.null(group))
if(!is.null(group)){
if(!opts$antaresVersion >= 870){
stop("Parameter 'group' is only for Antares study version >= v8.7.0",
call. = FALSE)
}
else if(!is.null(name)){
stop("You can only delete binding constraint by id/name or by group",
call. = FALSE)
}
}

# API block
Expand Down
43 changes: 39 additions & 4 deletions tests/testthat/test-removeBindingConstraint.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,44 @@

# v710 ----
## error function calls with bc group ----
test_that("removeBindingConstraint with name group", {
# read / open template study
setup_study(studies, sourcedir)
opts <- antaresRead::setSimulationPath(studyPath, 1)

# delete
testthat::expect_error(
removeBindingConstraint(name = "fake",
group = "group_fake",
opts = opts),
regexp = "Parameter 'group' is only for Antares study version >= v8.7.0"
)

# remove temporary study
unlink(x = studyPath, recursive = TRUE)
})

# v870 ----

## error function calls ----
test_that("removeBindingConstraint v8.7.0 error call", {
# read / open template study
setup_study_last(dir_path = sourcedir_last_study)
opts_test <- antaresRead::setSimulationPath(study_latest_version, "input")

# read
bc_v870 <- readBindingConstraints(opts = opts_test)

bc_names_v870 <- names(bc_v870)

group_to_delete <- bc_v870$bc_1$properties$group

# delete
testthat::expect_error(
removeBindingConstraint(name = bc_names_v870[1],
group = "group_to_delete",
opts = opts_test),
regexp = "You can only delete binding constraint by"
)
})
## one name ----
test_that("removeBindingConstraint v8.7.0 by name", {
# read / open template study
Expand Down Expand Up @@ -43,8 +80,6 @@ test_that("removeBindingConstraint v8.7.0 by name", {
testthat::expect_false(bc_names_v870[3] %in%
names(readBindingConstraints(opts = opts_test)))



# remove temporary study
unlink(x = study_latest_version, recursive = TRUE)

Expand Down

0 comments on commit bad682d

Please sign in to comment.