TEST_F(EnergyPlusFixture,ReverseTranslator_ScheduleDayInterval) { // ScheduleDayInterval time entries contain the string 'Until: ' that must be // stripped off before constructing a Time object. We are also more lenient in // making this optional. Workspace ws(StrictnessLevel::Draft,IddFileType(IddFileType::EnergyPlus)); OptionalWorkspaceObject owo = ws.addObject(IdfObject(IddObjectType::Schedule_Day_Interval)); ASSERT_TRUE(owo); WorkspaceObject object = *owo; object.setName("Heating Setpoint Design Day"); StringVector groupValues(2u); groupValues[0] = std::string("Until: 12:00"); groupValues[1] = std::string("21.1"); object.pushExtensibleGroup(groupValues); groupValues[0] = std::string("24:00"); groupValues[1] = std::string("20.5"); object.pushExtensibleGroup(groupValues); ReverseTranslator translator; Model model = translator.translateWorkspace(ws); EXPECT_TRUE(translator.errors().empty()); // There are warnings related to ws being a partial model. EXPECT_TRUE(translator.untranslatedIdfObjects().empty()); ScheduleDayVector daySchedules = model.getModelObjects<ScheduleDay>(); ASSERT_EQ(1u,daySchedules.size()); ScheduleDay daySchedule = daySchedules[0]; DoubleVector values = daySchedule.values(); ASSERT_EQ(2u,values.size()); EXPECT_DOUBLE_EQ(21.1,values[0]); EXPECT_DOUBLE_EQ(20.5,values[1]); TimeVector times = daySchedule.times(); ASSERT_EQ(2u,times.size()); EXPECT_EQ(Time(0,12,0),times[0]); EXPECT_EQ(Time(0,24,0),times[1]); }
//-***************************************************************************** void validateTimeSampling( const AbcA::TimeSampling &timeSampling, const AbcA::TimeSamplingType &timeSamplingType, const TimeVector &timeVector, const size_t numSamplesPerCycle, const chrono_t timePerCycle ) { const chrono_t period = timeSamplingType.getTimePerCycle(); TESTING_MESSAGE_ASSERT( period == timePerCycle, "calculated cycle period does not match given time/cycle" ); std::cout << "***********************************************************" << std::endl; if ( timeSamplingType.isUniform() ) { std::cout << "time sampling type is uniform" << std::endl; } if ( timeSamplingType.isCyclic() ) { std::cout << "time sampling type is cyclic" << std::endl; } if ( timeSamplingType.isAcyclic() ) { std::cout << "time sampling type is acyclic" << std::endl; } std::cout << "Number of samples per cycle is " << timeSamplingType.getNumSamplesPerCycle() << std::endl << std::endl; std::cout << "Given times:" << std::endl; for ( size_t i = 0 ; i < timeVector.size() ; ++i ) { std::cout << i << ": " << timeVector[i] << " " << std::endl; } std::cout << std::endl << "with a period of " << period << std::endl << std::endl; TESTING_MESSAGE_ASSERT( timeSamplingType.isAcyclic() || numSamplesPerCycle == timeSampling.getNumStoredTimes(), "Number of samples given doesn't match number returned" ); //-************************************************************************* // acyclic case if ( timePerCycle == AbcA::TimeSamplingType::AcyclicTimePerCycle() || numSamplesPerCycle == AbcA::TimeSamplingType::AcyclicNumSamples() ) { TESTING_MESSAGE_ASSERT( timePerCycle == AbcA::TimeSamplingType::AcyclicTimePerCycle() && numSamplesPerCycle == AbcA::TimeSamplingType::AcyclicNumSamples(), "Given time and samples per cycle should be infinite." ); TESTING_MESSAGE_ASSERT( timeSamplingType.isAcyclic(), "Time sampling should be acyclic." ); } // uniform case else if ( numSamplesPerCycle == 1 ) { TESTING_MESSAGE_ASSERT( timeSamplingType.isUniform(), "Time sampling should be uniform." ); } // cyclic case else if ( numSamplesPerCycle > 0 && timePerCycle > 0.0 ) { TESTING_MESSAGE_ASSERT( timeSamplingType.isCyclic(), "Time sampling should be cyclic." ); } else { TESTING_MESSAGE_ASSERT( false, "Could not validate time sampling." ); } }