Skip to content

Commit

Permalink
Add unit test for ExpressAsCashFlows. Clean up some initialization th…
Browse files Browse the repository at this point in the history
…at we causing problems with visualizing Objexx arrays.
  • Loading branch information
JasonGlazer committed Aug 16, 2019
1 parent 42d955c commit 3affe8a
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 7 deletions.
10 changes: 5 additions & 5 deletions src/EnergyPlus/EconomicLifeCycleCost.hh
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ namespace EconomicLifeCycleCost {

// Default Constructor
RecurringCostsType()
: category(costCatMaintenance), startOfCosts(startServicePeriod), yearsFromStart(0), monthsFromStart(0), totalMonthsFromStart(0),
: category(costCatMaintenance), cost(0.0), startOfCosts(startServicePeriod), yearsFromStart(0), monthsFromStart(0), totalMonthsFromStart(0),
repeatPeriodYears(0), repeatPeriodMonths(0), totalRepeatPeriodMonths(0), annualEscalationRate(0.0)
{
}
Expand All @@ -216,7 +216,7 @@ namespace EconomicLifeCycleCost {

// Default Constructor
NonrecurringCostType()
: category(costCatConstruction), startOfCosts(startServicePeriod), yearsFromStart(0), monthsFromStart(0), totalMonthsFromStart(0)
: category(costCatConstruction), cost(0.0), startOfCosts(startServicePeriod), yearsFromStart(0), monthsFromStart(0), totalMonthsFromStart(0)
{
}
};
Expand All @@ -232,7 +232,7 @@ namespace EconomicLifeCycleCost {
// last year is baseDateYear + lengthStudyYears - 1

// Default Constructor
UsePriceEscalationType() : escalationStartYear(0), escalationStartMonth(0)
UsePriceEscalationType() : resource(0), escalationStartYear(0), escalationStartMonth(0)
{
}
};
Expand All @@ -246,7 +246,7 @@ namespace EconomicLifeCycleCost {
// last year is baseDateYear + lengthStudyYears - 1

// Default Constructor
UseAdjustmentType()
UseAdjustmentType() : resource(0)
{
}
};
Expand All @@ -267,7 +267,7 @@ namespace EconomicLifeCycleCost {
Array1D<Real64> yrPresVal; // present value by year, first year is baseDateYear

// Default Constructor
CashFlowType() : pvKind(0)
CashFlowType() : SourceKind(0), pvKind(0), Resource(0), Category(0), presentValue(0.), orginalCost(0.)
{
}
};
Expand Down
96 changes: 94 additions & 2 deletions tst/EnergyPlus/unit/EconomicLifeCycleCost.unit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,19 @@

// EnergyPlus Headers
#include <DataGlobals.hh>
#include <DataGlobalConstants.hh>
#include <EconomicTariff.hh>

#include <EconomicLifeCycleCost.hh>

#include "Fixtures/EnergyPlusFixture.hh"

using namespace EnergyPlus;
using namespace EnergyPlus::EconomicLifeCycleCost;

using namespace EnergyPlus::DataGlobalConstants;
using namespace EnergyPlus::EconomicTariff;

TEST_F(EnergyPlusFixture, EconomicLifeCycleCost_GetInput)
{

Expand Down Expand Up @@ -480,8 +486,6 @@ TEST_F(EnergyPlusFixture, EconomicLifeCycleCost_ComputeEscalatedEnergyCosts)

TEST_F(EnergyPlusFixture, EconomicLifeCycleCost_MonthToMonthNumber)
{
ShowMessage("Begin Test: OutputReportTabularTest, ConfirmSetUnitsStyleFromString");

EXPECT_EQ(1, MonthToMonthNumber("January",1));
EXPECT_EQ(2, MonthToMonthNumber("February",1));
EXPECT_EQ(3, MonthToMonthNumber("March",1));
Expand All @@ -498,3 +502,91 @@ TEST_F(EnergyPlusFixture, EconomicLifeCycleCost_MonthToMonthNumber)
}


TEST_F(EnergyPlusFixture, EconomicLifeCycleCost_ExpressAsCashFlows)
{
baseDateYear = 2020;
baseDateMonth = 1;

serviceDateYear = 2023;
serviceDateMonth = 1;

lengthStudyYears = 5;
lengthStudyTotalMonths = lengthStudyYears * 12;


numTariff = 1;
tariff.allocate(1);
tariff(1).isSelected = true;
tariff(1).resourceNum = 1001;
tariff(1).ptTotal = 1;
econVar.allocate(1);
econVar(1).values.allocate(12);
econVar(1).values(1) = 101.;
econVar(1).values(2) = 102.;
econVar(1).values(3) = 103.;
econVar(1).values(4) = 104.;
econVar(1).values(5) = 105.;
econVar(1).values(6) = 106.;
econVar(1).values(7) = 107.;
econVar(1).values(8) = 108.;
econVar(1).values(9) = 109.;
econVar(1).values(10) = 110.;
econVar(1).values(11) = 111.;
econVar(1).values(12) = 112.;

numNonrecurringCost = 1;
NonrecurringCost.allocate(1);
NonrecurringCost(1).name = "MiscConstruction";
NonrecurringCost(1).name = "MiscConstruction";
NonrecurringCost(1).category = costCatConstruction;
NonrecurringCost(1).cost = 123456.;
NonrecurringCost(1).startOfCosts == startServicePeriod;
NonrecurringCost(1).totalMonthsFromStart = 10;

ExpressAsCashFlows();

EXPECT_NEAR(CashFlow(17).mnAmount(47), 123456., 0.001); // 36 months plus 10 months plus one month

// first year
EXPECT_NEAR(CashFlow(18).mnAmount(37), 101., 0.001);
EXPECT_NEAR(CashFlow(18).mnAmount(38), 102., 0.001);
EXPECT_NEAR(CashFlow(18).mnAmount(39), 103., 0.001);
EXPECT_NEAR(CashFlow(18).mnAmount(40), 104., 0.001);
EXPECT_NEAR(CashFlow(18).mnAmount(41), 105., 0.001);
EXPECT_NEAR(CashFlow(18).mnAmount(42), 106., 0.001);
EXPECT_NEAR(CashFlow(18).mnAmount(43), 107., 0.001);
EXPECT_NEAR(CashFlow(18).mnAmount(44), 108., 0.001);
EXPECT_NEAR(CashFlow(18).mnAmount(45), 109., 0.001);
EXPECT_NEAR(CashFlow(18).mnAmount(46), 110., 0.001);
EXPECT_NEAR(CashFlow(18).mnAmount(47), 111., 0.001);
EXPECT_NEAR(CashFlow(18).mnAmount(48), 112., 0.001);
// second year
EXPECT_NEAR(CashFlow(18).mnAmount(49), 101., 0.001);
EXPECT_NEAR(CashFlow(18).mnAmount(50), 102., 0.001);
EXPECT_NEAR(CashFlow(18).mnAmount(51), 103., 0.001);
EXPECT_NEAR(CashFlow(18).mnAmount(52), 104., 0.001);
EXPECT_NEAR(CashFlow(18).mnAmount(53), 105., 0.001);
EXPECT_NEAR(CashFlow(18).mnAmount(54), 106., 0.001);
EXPECT_NEAR(CashFlow(18).mnAmount(55), 107., 0.001);
EXPECT_NEAR(CashFlow(18).mnAmount(56), 108., 0.001);
EXPECT_NEAR(CashFlow(18).mnAmount(57), 109., 0.001);
EXPECT_NEAR(CashFlow(18).mnAmount(58), 110., 0.001);
EXPECT_NEAR(CashFlow(18).mnAmount(59), 111., 0.001);
EXPECT_NEAR(CashFlow(18).mnAmount(60), 112., 0.001);

EXPECT_NEAR(CashFlow(18).yrAmount(4), 1278., 0.001);
EXPECT_NEAR(CashFlow(18).yrAmount(5), 1278., 0.001);

EXPECT_NEAR(CashFlow(costCatEnergy).yrAmount(4), 1278., 0.001);
EXPECT_NEAR(CashFlow(costCatEnergy).yrAmount(5), 1278., 0.001);

EXPECT_NEAR(CashFlow(costCatTotEnergy).yrAmount(4), 1278., 0.001);
EXPECT_NEAR(CashFlow(costCatTotEnergy).yrAmount(5), 1278., 0.001);

EXPECT_NEAR(CashFlow(costCatConstruction).yrAmount(4), 123456, 0.001);
EXPECT_NEAR(CashFlow(costCatTotCaptl).yrAmount(4), 123456, 0.001);

EXPECT_NEAR(CashFlow(costCatTotGrand).yrAmount(4), 1278. + 123456., 0.001);
EXPECT_NEAR(CashFlow(costCatTotGrand).yrAmount(5), 1278., 0.001);
}

6 comments on commit 3affe8a

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

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

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

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: OK (2509 of 2509 tests passed, 0 test warnings)

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.

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

Build Badge Test Badge Coverage 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-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 (2469 of 2469 tests passed, 0 test warnings)

Build Badge Test Badge

Please sign in to comment.