From e35840a0e90a6a0bc6bbc739f47625f8fea1f24a Mon Sep 17 00:00:00 2001 From: "BERTHET Clement (Externe)" Date: Mon, 11 Dec 2023 14:12:18 +0100 Subject: [PATCH] fix some tests with new study test 870 --- tests/testthat/test-readBindingConstraints.R | 66 +++++++++++++++----- tests/testthat/test-readClusterDesc.R | 10 +-- tests/testthat/test-readInputTS.R | 10 +-- 3 files changed, 62 insertions(+), 24 deletions(-) diff --git a/tests/testthat/test-readBindingConstraints.R b/tests/testthat/test-readBindingConstraints.R index ef30ebb5..7a58701a 100644 --- a/tests/testthat/test-readBindingConstraints.R +++ b/tests/testthat/test-readBindingConstraints.R @@ -1,17 +1,53 @@ -test_that("readBindingConstraint", { +context("bindingConstraints") + +# >= v710 ---- +opts <- setSimulationPath(studyPathS, 0) + +test_that("returns an object of class 'bindingConstraints'", { + constraints <- readBindingConstraints(opts) + expect_is(constraints, "bindingConstraints") +}) + +test_that("summary.bindingConstraints",{ + constraints <- readBindingConstraints(opts) + sumConstraints <- summary(constraints) + expect_is(sumConstraints, "data.frame") + expect_true(all(c("enabled", "timeStep", "equation") %in% + names(sumConstraints))) +}) + + +test_that("Both operator",{ + constraints <- readBindingConstraints(opts) + constraints[[1]]$operator <- "both" + sumConstraints <- summary(constraints) + expect_is(sumConstraints, "data.frame") + expect_true(all(c("enabled", "timeStep", "equation") %in% + names(sumConstraints))) +}) + +##delete study ---- +#unlink(studyPathS, recursive = TRUE) + +# >= v800 ---- +# +opts <- antaresRead::setSimulationPath(studyPathSV8[1], "input") + +test_that("test if exist data value file", { + bc <- antaresRead::readBindingConstraints(opts = opts) + + # test class object return + testthat::expect_equal(class(bc), "bindingConstraints") + + names_bc_test <- paste0(names(bc), ".txt") + path_test_bc <- paste0(file.path(opts$inputPath, "bindingconstraints", names_bc_test)) - # test for versions v710 v800 v850 - all_path_studies <- c(studyPathS, studyPathSV8) - sapply(all_path_studies, function(study) { - opts <- antaresRead::setSimulationPath(study, "input") - - bc <- antaresRead::readBindingConstraints(opts = opts) - # test class object return - testthat::expect_equal(class(bc), "bindingConstraints") - - names_bc_test <- paste0(names(bc), ".txt") - path_test_bc <- paste0(file.path(opts$inputPath, "bindingconstraints", names_bc_test)) - # test if values files exists - testthat::expect_true(all(unlist(lapply(path_test_bc, file.exists)))) - }) + # test if values files exists + testthat::expect_true(all(unlist(lapply(path_test_bc, file.exists)))) }) + + +# >= v870 ---- +# + + diff --git a/tests/testthat/test-readClusterDesc.R b/tests/testthat/test-readClusterDesc.R index f62dd764..55fedb29 100644 --- a/tests/testthat/test-readClusterDesc.R +++ b/tests/testthat/test-readClusterDesc.R @@ -1,9 +1,10 @@ +# read study ---- + # latest version +path_study_test <- grep(pattern = "87", x = studyPathSV8, value = TRUE) +opts_study_test <- setSimulationPath(path_study_test, simulation = "input") ## v860 ---- -path_study_test <- grep(pattern = "86", x = studyPathSV8, value = TRUE) -opts_study_test <- setSimulationPath(path_study_test, simulation = "input") - test_that("test read cluster st-storage v860", { # function setSimulationPath() provide areas names with st-storage clusters @@ -14,5 +15,6 @@ test_that("test read cluster st-storage v860", { # tests testthat::expect_true("data.table" %in% class(input_st)) - testthat::expect_true(areas_st %in% unique(readClusterSTDesc()$area)) + testthat::expect_true(all( + areas_st %in% unique(readClusterSTDesc()$area))) }) diff --git a/tests/testthat/test-readInputTS.R b/tests/testthat/test-readInputTS.R index e7129140..1fbc3e81 100644 --- a/tests/testthat/test-readInputTS.R +++ b/tests/testthat/test-readInputTS.R @@ -1,7 +1,7 @@ #Copyright © 2016 RTE Réseau de transport d’électricité -# v710---- +# >= v710---- context("Function readInputTS") sapply(studyPathS, function(studyPath){ @@ -125,12 +125,12 @@ test_that("readInputTs must work if we change opts$timeIdMin and opts$timeIdMax" } }) - -# v860---- - -path_study_test <- grep(pattern = "86", x = studyPathSV8, value = TRUE) +# read latest version study +path_study_test <- grep(pattern = "87", x = studyPathSV8, value = TRUE) opts_study_test <- setSimulationPath(path_study_test, simulation = "input") +# >= v860---- + test_that("readInputTs mingen file v860", { # to read 8760