本文整理汇总了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());
}
示例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;
}