Skip to content

Commit

Permalink
Add unit test for #7481
Browse files Browse the repository at this point in the history
  • Loading branch information
jmarrec committed Oct 28, 2019
1 parent 0e6e9c0 commit 785782e
Showing 1 changed file with 128 additions and 0 deletions.
128 changes: 128 additions & 0 deletions tst/EnergyPlus/unit/OutputReportTabular.unit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
#include <EnergyPlus/DataSurfaces.hh>
#include <EnergyPlus/DataZoneEnergyDemands.hh>
#include <EnergyPlus/DataZoneEquipment.hh>
#include <EnergyPlus/ElectricPowerServiceManager.hh>
#include <EnergyPlus/General.hh>
#include <EnergyPlus/HeatBalanceManager.hh>
#include <EnergyPlus/HeatBalanceSurfaceManager.hh>
Expand Down Expand Up @@ -7653,3 +7654,130 @@ TEST_F(SQLiteFixture, WriteSourceEnergyEndUseSummary_TestPerArea) {

EnergyPlus::sqlite->sqliteCommit();
}

TEST_F(SQLiteFixture, OutputReportTabular_EndUseBySubcategorySQL)
{
EnergyPlus::sqlite->sqliteBegin();
EnergyPlus::sqlite->createSQLiteSimulationsRecord(1, "EnergyPlus Version", "Current Time");

OutputReportTabular::displayTabularBEPS = true;
OutputReportTabular::displayDemandEndUse = true;
OutputReportTabular::displayLEEDSummary = true;

OutputReportTabular::WriteTabularFiles = true;

SetupUnitConversions();
OutputReportTabular::unitsStyle = OutputReportTabular::unitsStyleInchPound;

// Needed to avoid crash (from ElectricPowerServiceManager.hh)
createFacilityElectricPowerServiceObject();

SetPredefinedTables();

Real64 extLitUse;

SetupOutputVariable("Exterior Lights Electric Energy",
OutputProcessor::Unit::J,
extLitUse,
"Zone",
"Sum",
"Lite1",
_,
"Electricity",
"Exterior Lights",
"General");
SetupOutputVariable("Exterior Lights Electric Energy",
OutputProcessor::Unit::J,
extLitUse,
"Zone",
"Sum",
"Lite2",
_,
"Electricity",
"Exterior Lights",
"AnotherEndUseSubCat");
SetupOutputVariable("Exterior Lights Electric Energy",
OutputProcessor::Unit::J,
extLitUse,
"Zone",
"Sum",
"Lite3",
_,
"Electricity",
"Exterior Lights",
"General");

DataGlobals::DoWeathSim = true;
DataGlobals::TimeStepZone = 1.0;
displayTabularBEPS = true;
// OutputProcessor::TimeValue.allocate(2);

auto timeStep = 1.0;

SetupTimePointers("Zone", timeStep);
SetupTimePointers("HVAC", timeStep);

TimeValue.at(OutputProcessor::TimeStepType::TimeStepZone).TimeStep = 60;
TimeValue.at(OutputProcessor::TimeStepType::TimeStepSystem).TimeStep = 60;

GetInputOutputTableSummaryReports();

extLitUse = 1.01;

DataEnvironment::Month = 12;

UpdateMeterReporting();
UpdateDataandReport(OutputProcessor::TimeStepType::TimeStepZone);
GatherBEPSResultsForTimestep(OutputProcessor::TimeStepType::TimeStepZone);
GatherPeakDemandForTimestep(OutputProcessor::TimeStepType::TimeStepZone);
EXPECT_EQ(extLitUse * 3, gatherEndUseBEPS(1, DataGlobalConstants::endUseExteriorLights));
// General
EXPECT_EQ(extLitUse * 2, gatherEndUseSubBEPS(1, DataGlobalConstants::endUseExteriorLights, 1));
// AnotherEndUseSubCat
EXPECT_EQ(extLitUse * 1, gatherEndUseSubBEPS(2, DataGlobalConstants::endUseExteriorLights, 1));

UpdateMeterReporting();
UpdateDataandReport(OutputProcessor::TimeStepType::TimeStepZone);
GatherBEPSResultsForTimestep(OutputProcessor::TimeStepType::TimeStepZone);
GatherPeakDemandForTimestep(OutputProcessor::TimeStepType::TimeStepZone);
EXPECT_EQ(extLitUse * 6, gatherEndUseBEPS(1, DataGlobalConstants::endUseExteriorLights));
// General
EXPECT_EQ(extLitUse * 4, gatherEndUseSubBEPS(1, DataGlobalConstants::endUseExteriorLights, 1));
// AnotherEndUseSubCat
EXPECT_EQ(extLitUse * 2, gatherEndUseSubBEPS(2, DataGlobalConstants::endUseExteriorLights, 1));

UpdateMeterReporting();
UpdateDataandReport(OutputProcessor::TimeStepType::TimeStepZone);
GatherBEPSResultsForTimestep(OutputProcessor::TimeStepType::TimeStepZone);
GatherPeakDemandForTimestep(OutputProcessor::TimeStepType::TimeStepZone);
EXPECT_EQ(extLitUse * 9, gatherEndUseBEPS(1, DataGlobalConstants::endUseExteriorLights));
// General
EXPECT_EQ(extLitUse * 6, gatherEndUseSubBEPS(1, DataGlobalConstants::endUseExteriorLights, 1));
// AnotherEndUseSubCat
EXPECT_EQ(extLitUse * 3, gatherEndUseSubBEPS(2, DataGlobalConstants::endUseExteriorLights, 1));

OutputReportTabular::WriteBEPSTable();
OutputReportTabular::WriteDemandEndUseSummary();

EnergyPlus::sqlite->sqliteCommit();

// We test for Heating and Total, since they should be the same
std::vector<std::string> testReportNames = {"AnnualBuildingUtilityPerformanceSummary", "DemandEndUseComponentsSummary"};


for (auto& reportName: testReportNames) {

std::string query("SELECT RowName From TabularDataWithStrings"
" WHERE TableName = 'End Uses By Subcategory'"
" AND ColumnName = 'Subcategory'"
" AND ReportName = '" + reportName + "'"
" AND Value = 'AnotherEndUseSubCat'");

auto result = queryResult(query, "TabularDataWithStrings");

ASSERT_EQ(1ul, result.size()) << "Query crashed for reportName=" << reportName;

// Add informative message if failed
EXPECT_EQ("Exterior Lighting", result[0][0]) << "Failed for reportName=" << reportName;
}
}

0 comments on commit 785782e

Please sign in to comment.