Skip to content

Commit

Permalink
Add unit test.
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonGlazer committed Aug 16, 2019
1 parent bc2235a commit 94ec000
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/EnergyPlus/EconomicLifeCycleCost.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1494,7 +1494,7 @@ namespace EconomicLifeCycleCost {
int curResource;
int nUsePriceEsc;

for (int iCashFlow = 1; iCashFlow <= numCashFlow; ++iCashFlow) {
for (int iCashFlow = 1; iCashFlow <= numCashFlow; ++iCashFlow) {
if (CashFlow(iCashFlow).pvKind == pvkEnergy) {
curResource = CashFlow(iCashFlow).Resource - ResourceTypeInitialOffset;
if ((curResource >= 1) && (curResource < NumOfResourceTypes)) {
Expand Down
62 changes: 62 additions & 0 deletions tst/EnergyPlus/unit/EconomicLifeCycleCost.unit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -415,3 +415,65 @@ TEST_F(EnergyPlusFixture, EconomicLifeCycleCost_ProcessMaxInput)
EXPECT_EQ(1.099, UseAdjustment(1).Adjustment(99));
EXPECT_EQ(1.100, UseAdjustment(1).Adjustment(100));
}

TEST_F(EnergyPlusFixture, EconomicLifeCycleCost_ComputeEscalatedEnergyCosts)
{
lengthStudyYears = 5;

numCashFlow = 1;
CashFlow.allocate(numCashFlow);
CashFlow(1).pvKind = pvkEnergy;
CashFlow(1).Resource = 1001;
CashFlow(1).yrAmount.allocate(lengthStudyYears);
CashFlow(1).yrAmount(1) = 100;
CashFlow(1).yrAmount(2) = 100;
CashFlow(1).yrAmount(3) = 100;
CashFlow(1).yrAmount(4) = 100;
CashFlow(1).yrAmount(5) = 100;

numResourcesUsed = 1;

EscalatedEnergy.allocate(lengthStudyYears, 1);
EscalatedTotEnergy.allocate(lengthStudyYears);
EscalatedTotEnergy = 0.0;

ComputeEscalatedEnergyCosts();
EXPECT_NEAR(EscalatedEnergy(1, 1), 100., 0.001);
EXPECT_NEAR(EscalatedEnergy(2, 1), 100., 0.001);
EXPECT_NEAR(EscalatedEnergy(3, 1), 100., 0.001);
EXPECT_NEAR(EscalatedEnergy(4, 1), 100., 0.001);
EXPECT_NEAR(EscalatedEnergy(5, 1), 100., 0.001);

EXPECT_NEAR(EscalatedTotEnergy(1), 100., 0.001);
EXPECT_NEAR(EscalatedTotEnergy(2), 100., 0.001);
EXPECT_NEAR(EscalatedTotEnergy(3), 100., 0.001);
EXPECT_NEAR(EscalatedTotEnergy(4), 100., 0.001);
EXPECT_NEAR(EscalatedTotEnergy(5), 100., 0.001);

numUsePriceEscalation = 1;
UsePriceEscalation.allocate(numUsePriceEscalation);
UsePriceEscalation(1).resource = 1001;
UsePriceEscalation(1).Escalation.allocate(lengthStudyYears);
UsePriceEscalation(1).Escalation(1) = 1.03;
UsePriceEscalation(1).Escalation(2) = 1.05;
UsePriceEscalation(1).Escalation(3) = 1.07;
UsePriceEscalation(1).Escalation(4) = 1.11;
UsePriceEscalation(1).Escalation(5) = 1.15;

//reset this variable to zero
EscalatedTotEnergy = 0.0;

ComputeEscalatedEnergyCosts();
EXPECT_NEAR(EscalatedEnergy(1, 1), 103., 0.001);
EXPECT_NEAR(EscalatedEnergy(2, 1), 105., 0.001);
EXPECT_NEAR(EscalatedEnergy(3, 1), 107., 0.001);
EXPECT_NEAR(EscalatedEnergy(4, 1), 111., 0.001);
EXPECT_NEAR(EscalatedEnergy(5, 1), 115., 0.001);

EXPECT_NEAR(EscalatedTotEnergy(1), 103., 0.001);
EXPECT_NEAR(EscalatedTotEnergy(2), 105., 0.001);
EXPECT_NEAR(EscalatedTotEnergy(3), 107., 0.001);
EXPECT_NEAR(EscalatedTotEnergy(4), 111., 0.001);
EXPECT_NEAR(EscalatedTotEnergy(5), 115., 0.001);

}

6 comments on commit 94ec000

@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.

FixLCC_Escalataion_6144 (JasonGlazer) - x86_64-Linux-Ubuntu-18.04-gcc-7.4: OK (2507 of 2507 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.

FixLCC_Escalataion_6144 (JasonGlazer) - x86_64-Linux-Ubuntu-18.04-cppcheck: OK (0 of 0 tests passed, 0 test warnings)

Build 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.

FixLCC_Escalataion_6144 (JasonGlazer) - x86_64-Linux-Ubuntu-18.04-custom_check: OK (9 of 9 tests passed, 0 test warnings)

Build 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.

FixLCC_Escalataion_6144 (JasonGlazer) - x86_64-Linux-Ubuntu-18.04-gcc-7.4-UnitTestsCoverage-Debug: OK (1137 of 1137 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.

FixLCC_Escalataion_6144 (JasonGlazer) - x86_64-Linux-Ubuntu-18.04-gcc-7.4-IntegrationCoverage-Debug: OK (668 of 669 tests passed, 0 test warnings)

Failures:\n

integration Test Summary

  • Passed: 668
  • Failed: 1

Build Badge Test Badge Coverage Badge

@nrel-bot
Copy link

Choose a reason for hiding this comment

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

FixLCC_Escalataion_6144 (JasonGlazer) - Win64-Windows-10-VisualStudio-16: OK (2467 of 2467 tests passed, 0 test warnings)

Build Badge Test Badge

Please sign in to comment.