Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
a-zakir committed Jan 6, 2025
1 parent a1f7df7 commit eb64775
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 31 deletions.
8 changes: 3 additions & 5 deletions src/libs/antares/study/parts/short-term-storage/container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,12 @@ bool STStorageInput::createSTStorageClustersFromIniFile(const fs::path& path)
return true;
}

static bool loadHours(std::string hoursStr,
AdditionalConstraints& additionalConstraints)
static bool loadHours(std::string hoursStr, AdditionalConstraints& additionalConstraints)
{
std::erase_if(hoursStr, ::isspace);
// Validate the entire string format
if (std::regex fullFormatRegex(R"(^(\[\d+(,\d+)*\])(,(\[\d+(,\d+)*\]))*$)"); !std::regex_match(
hoursStr,
fullFormatRegex))
if (std::regex fullFormatRegex(R"(^(\[\d+(,\d+)*\])(,(\[\d+(,\d+)*\]))*$)");
!std::regex_match(hoursStr, fullFormatRegex))
{
logs.error() << "In constraint " << additionalConstraints.name
<< ": Input string does not match the required format: " << hoursStr << '\n';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -616,8 +616,6 @@ BOOST_AUTO_TEST_CASE(loadAdditionalConstraints_InvalidHours)
std::filesystem::remove_all(testPath);
}



BOOST_AUTO_TEST_CASE(loadAdditionalConstraints_MissingFile)
{
ShortTermStorage::STStorageInput storageInput;
Expand Down Expand Up @@ -957,17 +955,22 @@ BOOST_AUTO_TEST_CASE(Load_disabled)
}

BOOST_DATA_TEST_CASE(loadAdditionalConstraints_InvalidHoursFormat,
bdata::make({"","[]", "[ ]", "[\t]",
"[\r]", "[\f]", "[\v]"
,"[1, nol]",
"[; 3,2,1]",
"[1, 12345678901]",
"[1, 12345",
"1]",
"[1,]",
"[1,,2]",
"[a]",
"[1, 2], , [3]"}),
bdata::make({"",
"[]",
"[ ]",
"[\t]",
"[\r]",
"[\f]",
"[\v]",
"[1, nol]",
"[; 3,2,1]",
"[1, 12345678901]",
"[1, 12345",
"1]",
"[1,]",
"[1,,2]",
"[a]",
"[1, 2], , [3]"}),
hours)
{
std::filesystem::path testPath = getFolder() / "test_data";
Expand All @@ -992,19 +995,17 @@ BOOST_DATA_TEST_CASE(loadAdditionalConstraints_InvalidHoursFormat,
std::filesystem::remove_all(testPath);
}

BOOST_DATA_TEST_CASE(loadAdditionalConstraints_ValidHoursFormats,
bdata::make({
"[1],[1],[3,2,1]",
"[\r1,\t2]",
"[\v1\f,\t2],\f\v\t[4]",
"[\f\v1]\t\t",
"\t\v\t[1 ], [ 1, 2,3] "
,
" [4,5 ]"
,
"[1 2 3 , 11 3]"
}),
hours)
BOOST_DATA_TEST_CASE(
loadAdditionalConstraints_ValidHoursFormats,
bdata::make(
{"[1],[1],[3,2,1]",
"[\r1,\t2]",
"[\v1\f,\t2],\f\v\t[4]",
"[\f\v1]\t\t",
"\t\v\t[1 ], [ 1, 2,3] ",
" [4,5 ]",
"[1 2 3 , 11 3]"}),
hours)
{
std::filesystem::path testPath = getFolder() / "test_data";
std::filesystem::create_directory(testPath);
Expand Down

0 comments on commit eb64775

Please sign in to comment.