当前位置: 首页>>代码示例>>C++>>正文


C++ OptionalQuantity::units方法代码示例

本文整理汇总了C++中OptionalQuantity::units方法的典型用法代码示例。如果您正苦于以下问题:C++ OptionalQuantity::units方法的具体用法?C++ OptionalQuantity::units怎么用?C++ OptionalQuantity::units使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OptionalQuantity的用法示例。


在下文中一共展示了OptionalQuantity::units方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: testVec

TEST_F(UnitsFixture,QuantityConverter_OSQuantityVector) {
    // basic conversion
    OSQuantityVector testVec(createIPEnergy(),2u,100.0);
    Quantity testQ(100.0,createIPEnergy());

    OSQuantityVector resultVec = convert(testVec,UnitSystem(UnitSystem::Wh));
    OptionalQuantity resultQ = convert(testQ,UnitSystem(UnitSystem::Wh));
    ASSERT_EQ(2u,resultVec.size());
    ASSERT_TRUE(resultQ);
    EXPECT_EQ(resultQ.get(),resultVec.getQuantity(0));
    EXPECT_EQ(resultQ.get(),resultVec.getQuantity(1));
    EXPECT_EQ(resultQ->system(),resultVec.system());

    resultVec = convert(testVec,resultQ->units());
    resultQ = convert(testQ,resultQ->units());
    ASSERT_EQ(2u,resultVec.size());
    ASSERT_TRUE(resultQ);
    EXPECT_EQ(resultQ.get(),resultVec.getQuantity(0));
    EXPECT_EQ(resultQ.get(),resultVec.getQuantity(1));
    EXPECT_EQ(resultQ->system(),resultVec.system());

    // temperature conversion
    testVec = OSQuantityVector(createCelsiusTemperature(),2u,20.0);
    testQ = Quantity(20.0,createCelsiusTemperature());
    resultVec = convert(testVec,UnitSystem(UnitSystem::Fahrenheit));
    resultQ = convert(testQ,UnitSystem(UnitSystem::Fahrenheit));
    ASSERT_EQ(2u,resultVec.size());
    ASSERT_TRUE(resultQ);
    EXPECT_EQ(resultQ.get().units(),resultVec.units());
    // not sure why these aren't quite getting the precision we would like
    EXPECT_NEAR(resultQ.get().value(),resultVec.getQuantity(0).value(),1.0E-12);
    EXPECT_NEAR(resultQ.get().value(),resultVec.getQuantity(1).value(),1.0E-12);
    EXPECT_EQ(resultQ->system(),resultVec.system());
    EXPECT_TRUE(resultVec.isAbsolute());
    EXPECT_TRUE(resultQ->isAbsolute());

    testVec.setAsRelative();
    testQ.setAsRelative();
    resultVec = convert(testVec,UnitSystem(UnitSystem::Fahrenheit));
    resultQ = convert(testQ,UnitSystem(UnitSystem::Fahrenheit));
    ASSERT_EQ(2u,resultVec.size());
    ASSERT_TRUE(resultQ);
    EXPECT_EQ(resultQ.get().units(),resultVec.units());
    // not sure why these aren't quite getting the precision we would like
    EXPECT_NEAR(resultQ.get().value(),resultVec.getQuantity(0).value(),1.0E-12);
    EXPECT_NEAR(resultQ.get().value(),resultVec.getQuantity(1).value(),1.0E-12);
    EXPECT_EQ(resultQ->system(),resultVec.system());
    EXPECT_TRUE(resultVec.isRelative());
    EXPECT_TRUE(resultQ->isRelative());
}
开发者ID:urbanengr,项目名称:OpenStudio,代码行数:50,代码来源:QuantityConverter_GTest.cpp

示例2: convert

OSQuantityVector convert(const OSQuantityVector& original, const Unit& targetUnits) {
  OSQuantityVector result;
  Quantity testQuantity(0.0,original.units());
  OptionalQuantity offset = convert(testQuantity,targetUnits);
  if (!offset) {
    return result;
  }
  testQuantity.setValue(1.0);
  OptionalQuantity factorPlusOffset = convert(testQuantity,targetUnits);
  OS_ASSERT(factorPlusOffset);
  OS_ASSERT(offset->units() == factorPlusOffset->units());
  result = OSQuantityVector(offset->units(),original.values());
  result = result * (factorPlusOffset->value() - offset->value()) + offset.get();
  return result;
}
开发者ID:CUEBoxer,项目名称:OpenStudio,代码行数:15,代码来源:QuantityConverter.cpp


注:本文中的OptionalQuantity::units方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。