Skip to content

Commit

Permalink
fix to 2 digits for minor
Browse files Browse the repository at this point in the history
  • Loading branch information
berthetclement committed Oct 14, 2024
1 parent f9a2449 commit 89ab72e
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
8 changes: 4 additions & 4 deletions R/setSimulationPath.R
Original file line number Diff line number Diff line change
Expand Up @@ -685,15 +685,15 @@ setSimulationPath <- function(path, simulation = NULL) {
}

#' @title Convert the Antares number version
#' @description From V9.0, system version is 9.0 (1 digit for minor) instead of 900
#' @description From V9.0, system version is 9.0 (2 digit for minor) instead of 900
#'
#' @param antares_version ``numeric` Antares number version.
#'
#' @return `numeric` value according to study version
#'
#' @keywords internal
.transform_antares_version <- function(antares_version) {
antares_version <- format(antares_version, nsmall = 1)
antares_version <- format(antares_version, nsmall = 2)

# Split major and minor parts
antares_version_splitted <- unlist(strsplit(antares_version, split = "\\."))
Expand All @@ -702,8 +702,8 @@ setSimulationPath <- function(path, simulation = NULL) {
minor <- antares_version_splitted[2]

# max 1 digit for minor
if (nchar(minor) > 1)
stop("Invalid antares_version format, good format is like '9.0'",
if (nchar(minor) > 2)
stop("Invalid antares_version format, good format is like '9.99'",
call. = FALSE)

# convert to numeric for package understanding
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[antares]
version = 9.9
version = 9.99
caption = study_name
created = 1702567142
lastsave = 1702634579
Expand Down
2 changes: 1 addition & 1 deletion man/dot-transform_antares_version.Rd

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

6 changes: 3 additions & 3 deletions tests/testthat/test-setSimulationPath.R
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,10 @@ test_that("read new format version from .antares file", {
expect_equal(.transform_antares_version(version_value), 900)

# exception max digit minor
expect_error(.transform_antares_version(9.01),
expect_error(.transform_antares_version(9.111),
regexp = "Invalid antares_version format")

# read right format file
# read right format file (9.99)
antares_file <- file.path(test_path_files,
"antares_version_files",
"antares_version_float_2digit.antares")
Expand All @@ -239,7 +239,7 @@ test_that("read new format version from .antares file", {
version_value <- file_to_read$antares$version

# test right conversion for package
expect_equal(.transform_antares_version(version_value), 990)
expect_equal(.transform_antares_version(version_value), 999)
})

## study ----
Expand Down

0 comments on commit 89ab72e

Please sign in to comment.