Skip to content

Commit

Permalink
Add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonGlazer committed Mar 14, 2024
1 parent a673de6 commit 60fe6f9
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/EnergyPlus/ScheduleManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4510,6 +4510,7 @@ namespace ScheduleManager {
std::fill(dayTypeFilter.begin(), dayTypeFilter.end(), false);
switch (days) {
case DayTypeGroup::Weekday:
// Sun Mon Tues Wed Thur Fri Sat Sun Summer Winter Cust1 Cust2
dayTypeFilter = {false, true, true, true, true, true, false, false, false, false, false, false};
break;
case DayTypeGroup::WeekEndHoliday:
Expand All @@ -4526,7 +4527,7 @@ namespace ScheduleManager {
int WkSch = state.dataScheduleMgr->Schedule(ScheduleIndex).WeekSchedulePointer(iDayOfYear);
auto &weekSch = state.dataScheduleMgr->WeekSchedule(WkSch);
for (int jType = 1; jType <= maxDayTypes; ++jType) {
if (dayTypeFilter[jType -1]) {
if (dayTypeFilter[jType - 1]) {
auto &daySch = state.dataScheduleMgr->DaySchedule;
MinValue = min(MinValue, minval(daySch(weekSch.DaySchedulePointer(jType)).TSValue));
MaxValue = max(MaxValue, maxval(daySch(weekSch.DaySchedulePointer(jType)).TSValue));
Expand All @@ -4539,7 +4540,6 @@ namespace ScheduleManager {
return std::make_pair(MinValue, MaxValue);
}


std::string GetScheduleName(EnergyPlusData &state, int const ScheduleIndex)
{
// FUNCTION INFORMATION:
Expand Down
99 changes: 99 additions & 0 deletions tst/EnergyPlus/unit/ScheduleManager.unit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1563,3 +1563,102 @@ TEST_F(EnergyPlusFixture, ShadowCalculation_CSV_extra_parenthesis)
iHour = 24;
EXPECT_EQ(0.00000000, state->dataScheduleMgr->DaySchedule(iDay).TSValue(TS, iHour));
}

TEST_F(EnergyPlusFixture, getScheduleMinMaxByDayType_test)
{
// J.Glazer - March 2024

std::string const idf_objects = delimited_string({
"ScheduleTypeLimits,",
" Any Number; !- Name",
" ",
"Schedule:Compact,",
" HighLow01,",
" Any Number,",
" Through: 12/31,",
" For: WeekDays CustomDay1 CustomDay2,",
" Until: 8:00,0.42,",
" Until: 11:00,0.75,",
" Until: 12:00,0.80,",
" Until: 13:00,0.40,",
" Until: 14:00,0.87,",
" Until: 18:00,0.75,",
" Until: 19:00,0.50,",
" Until: 24:00,0.40,",
" For: Weekends Holiday,",
" Until: 8:00,0.30,",
" Until: 24:00,0.83,",
" For: SummerDesignDay,",
" Until: 24:00,0.95,",
" For: WinterDesignDay,",
" Until: 24:00,0.15;",
" ",
"Schedule:Compact,",
" HighLow02,",
" Any Number,",
" Through: 4/30,",
" For: WeekDays CustomDay1 CustomDay2,",
" Until: 24:00,0.21,",
" For: Weekends Holiday,",
" Until: 24:00,0.65,",
" For: SummerDesignDay,",
" Until: 24:00,0.79,",
" For: WinterDesignDay,",
" Until: 24:00,0.18,",
" Through: 12/31,",
" For: WeekDays CustomDay1 CustomDay2,",
" Until: 24:00,0.73,",
" For: Weekends Holiday,",
" Until: 24:00,0.27,",
" For: SummerDesignDay,",
" Until: 24:00,0.85,",
" For: WinterDesignDay,",
" Until: 24:00,0.25;",
" ",
});

ASSERT_TRUE(process_idf(idf_objects));

state->dataGlobal->NumOfTimeStepInHour = 4;
state->dataGlobal->MinutesPerTimeStep = 15;
state->dataGlobal->TimeStepZone = 0.25;

Real64 schMin;
Real64 schMax;

std::tie(schMin, schMax) = getScheduleMinMaxByDayType(*state, -1, DayTypeGroup::Weekday);
EXPECT_EQ(1.0, schMin);
EXPECT_EQ(1.0, schMax);

std::tie(schMin, schMax) = getScheduleMinMaxByDayType(*state, 0, DayTypeGroup::Weekday);
EXPECT_EQ(0.0, schMin);
EXPECT_EQ(0.0, schMax);

int index = GetScheduleIndex(*state, "HIGHLOW01");

std::tie(schMin, schMax) = getScheduleMinMaxByDayType(*state, index, DayTypeGroup::Weekday);
EXPECT_EQ(0.40, schMin);
EXPECT_EQ(0.87, schMax);

std::tie(schMin, schMax) = getScheduleMinMaxByDayType(*state, index, DayTypeGroup::WeekEndHoliday);
EXPECT_EQ(0.30, schMin);
EXPECT_EQ(0.83, schMax);

std::tie(schMin, schMax) = getScheduleMinMaxByDayType(*state, index, DayTypeGroup::DesignDay);
EXPECT_EQ(0.15, schMin);
EXPECT_EQ(0.95, schMax);

index = GetScheduleIndex(*state, "HIGHLOW02");

std::tie(schMin, schMax) = getScheduleMinMaxByDayType(*state, index, DayTypeGroup::Weekday);
EXPECT_EQ(0.21, schMin);
EXPECT_EQ(0.73, schMax);

std::tie(schMin, schMax) = getScheduleMinMaxByDayType(*state, index, DayTypeGroup::WeekEndHoliday);
EXPECT_EQ(0.27, schMin);
EXPECT_EQ(0.65, schMax);

std::tie(schMin, schMax) = getScheduleMinMaxByDayType(*state, index, DayTypeGroup::DesignDay);
EXPECT_EQ(0.18, schMin);
EXPECT_EQ(0.85, schMax);
}

5 comments on commit 60fe6f9

@nrel-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix10314-AddingScheduleColumns (JasonGlazer) - Win64-Windows-10-VisualStudio-16: OK (2767 of 2767 tests passed, 0 test warnings)

Build Badge Test Badge

@nrel-bot-2b
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix10314-AddingScheduleColumns (JasonGlazer) - x86_64-Linux-Ubuntu-22.04-gcc-11.4: OK (3596 of 3596 tests passed, 653 test warnings)

Messages:\n

  • 653 tests had: EIO diffs.

Build Badge Test Badge

@nrel-bot-3
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix10314-AddingScheduleColumns (JasonGlazer) - x86_64-MacOS-10.18-clang-15.0.0: OK (3555 of 3555 tests passed, 650 test warnings)

Messages:\n

  • 650 tests had: EIO diffs.

Build Badge Test Badge

@nrel-bot-2
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix10314-AddingScheduleColumns (JasonGlazer) - x86_64-Linux-Ubuntu-22.04-gcc-11.4-UnitTestsCoverage-Debug: OK (1979 of 1979 tests passed, 0 test warnings)

Build Badge Test Badge Coverage Badge

@nrel-bot-2c
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix10314-AddingScheduleColumns (JasonGlazer) - x86_64-Linux-Ubuntu-22.04-gcc-11.4-IntegrationCoverage-Debug: OK (791 of 791 tests passed, 0 test warnings)

Build Badge Test Badge Coverage Badge

Please sign in to comment.