diff --git a/tst/EnergyPlus/unit/OutputReportTabular.unit.cc b/tst/EnergyPlus/unit/OutputReportTabular.unit.cc index 918a741fb6a..32a342f2ba2 100644 --- a/tst/EnergyPlus/unit/OutputReportTabular.unit.cc +++ b/tst/EnergyPlus/unit/OutputReportTabular.unit.cc @@ -71,6 +71,7 @@ #include #include #include +#include #include #include #include @@ -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 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; + } +}