Пример #1
0
TEST_F(ModelFixture, ComponentWatcher_FromScratch) {
  // create schedule component
  Model justASchedule;
  ScheduleTypeLimits typeLimits(justASchedule);
  typeLimits.setName("Fraction");
  typeLimits.setLowerLimitValue(0.0);
  typeLimits.setUpperLimitValue(1.0);
  typeLimits.setNumericType("Continuous");
  ScheduleCompact schedule(justASchedule);
  EXPECT_TRUE(schedule.setPointer(OS_Schedule_CompactFields::ScheduleTypeLimitsName,
                                  typeLimits.handle()));
  Component scheduleComponent = schedule.createComponent();

  // create model with Lights objects and insert schedule component
  Model justLights;
  LightsDefinition lightsDefinition(justLights);
  Lights light1(lightsDefinition);
  OptionalComponentData ocd = justLights.insertComponent(scheduleComponent);

  // get ComponentData object
  ASSERT_TRUE(ocd);
  ComponentData componentData = *ocd;
  UUID versionUUID = componentData.versionUUID();

  // setting lighting schedule does not invalidate schedule component, or change its version UUID
  OptionalScheduleCompact oSchedule = componentData.primaryComponentObject().optionalCast<ScheduleCompact>();
  ASSERT_TRUE(oSchedule);
  schedule = *oSchedule;
  EXPECT_TRUE(light1.setSchedule(schedule));
  ASSERT_TRUE(componentData.initialized());
  EXPECT_EQ(versionUUID,componentData.versionUUID());

  // changing data field in componentObject does not invalidate schedule component, but does change version UUID
  StringVector values;
  values.push_back("Through: 12/31");
  IdfExtensibleGroup eg = componentData.primaryComponentObject().pushExtensibleGroup(values);
  EXPECT_FALSE(eg.empty());
  ASSERT_TRUE(componentData.initialized());
  EXPECT_NE(versionUUID,componentData.versionUUID());
  versionUUID = componentData.versionUUID();

  // changing type limits used by schedule in component invalidates the component
  Handle h = componentData.handle();
  EXPECT_TRUE(justLights.isMember(h));
  ScheduleTypeLimits newTypeLimits = typeLimits.clone(justLights).cast<ScheduleTypeLimits>();
  EXPECT_FALSE(newTypeLimits.handle() == typeLimits.handle());
  EXPECT_TRUE(schedule.setPointer(OS_Schedule_CompactFields::ScheduleTypeLimitsName,newTypeLimits.handle()));
  EXPECT_FALSE(componentData.initialized());
  EXPECT_FALSE(justLights.isMember(h));
}
Пример #2
0
 bool ScheduleYear_Impl::setScheduleTypeLimits(const ScheduleTypeLimits& scheduleTypeLimits) {
   if (scheduleTypeLimits.model() != model()) {
     return false;
   }
   if (!candidateIsCompatibleWithCurrentUse(scheduleTypeLimits)) {
     return false;
   }
   return setPointer(OS_Schedule_YearFields::ScheduleTypeLimitsName, scheduleTypeLimits.handle());
 }
 bool ScheduleVariableInterval_Impl::setScheduleTypeLimits(const ScheduleTypeLimits& scheduleTypeLimits) {
   if (scheduleTypeLimits.model() != model()) { return false; }
   return setPointer(OS_Schedule_VariableIntervalFields::ScheduleTypeLimitsName,scheduleTypeLimits.handle());
 }
TEST_F(ModelFixture, ScheduleTypeRegistry_GetOrCreateScheduleTypeLimits) {
  {
    Model model;

    ScheduleType scheduleType = ScheduleTypeRegistry::instance().getScheduleType("People", "Activity Level");

    ASSERT_TRUE(scheduleType.lowerLimitValue);
    EXPECT_EQ(0.0, scheduleType.lowerLimitValue.get());
    EXPECT_FALSE(scheduleType.upperLimitValue);

    ScheduleTypeLimits limits = ScheduleTypeRegistry::instance().getOrCreateScheduleTypeLimits(scheduleType, model);
    ScheduleTypeLimits limits2 = ScheduleTypeRegistry::instance().getOrCreateScheduleTypeLimits(scheduleType, model);

    EXPECT_EQ(limits.handle(), limits2.handle());

    EXPECT_TRUE(isCompatible(scheduleType, limits));
  }

  {
    Model model;

    ScheduleType scheduleType = ScheduleTypeRegistry::instance().getScheduleType("RefrigerationCase", "Refrigerated Case Restocking");

    ASSERT_TRUE(scheduleType.lowerLimitValue);
    EXPECT_EQ(0.0, scheduleType.lowerLimitValue.get());
    EXPECT_FALSE(scheduleType.upperLimitValue);

    ScheduleTypeLimits limits = ScheduleTypeRegistry::instance().getOrCreateScheduleTypeLimits(scheduleType, model);
    ScheduleTypeLimits limits2 = ScheduleTypeRegistry::instance().getOrCreateScheduleTypeLimits(scheduleType, model);

    EXPECT_EQ(limits.handle(), limits2.handle());

    EXPECT_TRUE(isCompatible(scheduleType, limits));
  }

  {
    Model model;

    ScheduleType scheduleType = ScheduleTypeRegistry::instance().getScheduleType("ThermostatSetpointDualSetpoint", "Heating Setpoint Temperature");
    
    EXPECT_FALSE(scheduleType.lowerLimitValue);
    EXPECT_FALSE(scheduleType.upperLimitValue);

    ScheduleTypeLimits limits = ScheduleTypeRegistry::instance().getOrCreateScheduleTypeLimits(scheduleType, model);
    ScheduleTypeLimits limits2 = ScheduleTypeRegistry::instance().getOrCreateScheduleTypeLimits(scheduleType, model);

    EXPECT_EQ(limits.handle(), limits2.handle());
    EXPECT_EQ("Temperature", limits.name().get());

    EXPECT_TRUE(isCompatible(scheduleType, limits));

    ASSERT_EQ(1u, model.getConcreteModelObjectsByName<ScheduleTypeLimits>("Temperature").size());
    EXPECT_EQ("Temperature", model.getConcreteModelObjectsByName<ScheduleTypeLimits>("Temperature")[0].name().get());

    ModelObject scheduleType2 = limits.clone();
    EXPECT_EQ("Temperature 1", scheduleType2.name().get());

    EXPECT_EQ(2u, model.getConcreteModelObjectsByName<ScheduleTypeLimits>("Temperature").size());

    limits.remove();

    ASSERT_EQ(1u, model.getConcreteModelObjectsByName<ScheduleTypeLimits>("Temperature").size());
    EXPECT_EQ("Temperature 1", model.getConcreteModelObjectsByName<ScheduleTypeLimits>("Temperature 1")[0].name().get());

    limits = ScheduleTypeRegistry::instance().getOrCreateScheduleTypeLimits(scheduleType, model);
    EXPECT_EQ(limits.handle(), scheduleType2.handle());
    EXPECT_EQ("Temperature 1", limits.name().get());
  }

  {
    Model model;
    for (auto className : ScheduleTypeRegistry::instance().classNames()){
      for (auto scheduleType : ScheduleTypeRegistry::instance().getScheduleTypesByClassName(className)){
        ScheduleTypeLimits limits = ScheduleTypeRegistry::instance().getOrCreateScheduleTypeLimits(scheduleType, model);
        ScheduleTypeLimits limits2 = ScheduleTypeRegistry::instance().getOrCreateScheduleTypeLimits(scheduleType, model);

        EXPECT_EQ(limits.handle(), limits2.handle());

        EXPECT_EQ(ScheduleTypeLimits::units(scheduleType.unitType, false), ScheduleTypeLimits::units(limits.unitType(), false));

        EXPECT_TRUE(isCompatible(scheduleType, limits));
      }
    }
  }

}