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


C++ Quantity::standardUnitsString方法代码示例

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


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

示例1: convert

TEST_F(IdfFixture, IdfObject_GetQuantity)
{
    std::string text = "Building,                !- Building \n\
                      Building,                !- Name \n\
                      30.,                     !- North Axis {deg} \n\
                      City,                    !- Terrain \n\
                      0.04,                    !- Loads Convergence Tolerance Value \n\
                      0.4,                     !- Temperature Convergence Tolerance Value {deltaC} \n\
                      FullExterior,            !- Solar Distribution \n\
                      25;                      !- Maximum Number of Warmup Days";

  // make an idf object
  OptionalIdfObject oObj = IdfObject::load(text);
  ASSERT_TRUE(oObj);

  // Test get.
  OSOptionalQuantity ooq = oObj->getQuantity (4);
  ASSERT_TRUE(ooq.isSet());
  Quantity q = ooq.get();
  EXPECT_TRUE(q.value() == 0.4);
  EXPECT_TRUE(q.system() == UnitSystem::SI);
  EXPECT_TRUE(q.standardUnitsString() == "K");

  // Test set.
  OptionalQuantity oq = convert(q,UnitSystem(UnitSystem::IP));
  ASSERT_TRUE(oq);
  EXPECT_TRUE(oq->system() == UnitSystem::IP);
  EXPECT_DOUBLE_EQ(0.72,oq->value());
  oq->setValue(1.5);

  EXPECT_TRUE(oObj->setQuantity(4, *oq));
  ooq = oObj->getQuantity(4);
  ASSERT_TRUE(ooq.isSet());
  q = ooq.get();
  EXPECT_DOUBLE_EQ(0.83333333333333333,q.value());
  EXPECT_TRUE(q.system() == UnitSystem::SI);
  EXPECT_TRUE(q.standardUnitsString() == "K");
}
开发者ID:ChengXinDL,项目名称:OpenStudio,代码行数:38,代码来源:IdfObject_GTest.cpp

示例2: len

TEST_F(UnitsFixture,Quantity_ArithmeticOperators)
{
  LOG(Debug,"Quantity_ArithmeticOperators");

  Quantity q1;
  Quantity q2(1.0);

  Unit u3;
  u3.setBaseUnitExponent("ft",1);
  Quantity q3(34.2,u3);

  // addition
  Quantity q4 = q1 + q2;
  q4 += q4;
  testNumbersEqual(2.0,q4.value());
  testStreamOutput("2",q4);
  ASSERT_THROW(q3 + q1,Exception);

  // subtraction;
  ASSERT_THROW(q3 - q1,Exception);
  Quantity len(3.5,u3);
  len -= q3;
  testNumbersEqual(-30.7,len.value());
  testStreamOutput("-30.7 ft",len,1);

  // multiplication
  q3 *= q4;
  testNumbersEqual(68.4,q3.value());
  testStreamOutput("68.4 ft",q3,1);

  Unit u5;
  u5.setBaseUnitExponent("s",-2);
  u5.setBaseUnitExponent("ft",1);
  Quantity q5(0.5,u5);
  Quantity q6 = q5 * q3;
  testNumbersEqual(34.2,q6.value());
  testStreamOutput("34.2 ft^2/s^2",q6,1);

  // division
  len = Quantity(1.1,u3);
  Quantity a = q6/len;
  testNumbersEqual(31.0909090909,a.value());
  EXPECT_EQ("ft/s^2",a.standardUnitsString());

  // pow
  a.pow(6);
  EXPECT_EQ("ft^6/s^12",a.standardUnitsString());
  Quantity b = openstudio::pow(a,1,3);
  EXPECT_EQ("ft^2/s^4",b.standardUnitsString());
  testNumbersEqual(966.644628099,b.value());
  a = b;

  // multiplication and division with double
  a *= 1.21;
  testNumbersEqual(1169.64,a.value());
  b = a/2;
  testNumbersEqual(584.82,b.value());
  EXPECT_EQ("ft^2/s^4",b.standardUnitsString());
  EXPECT_EQ("",b.prettyUnitsString());

  Quantity c = 32.0/b;
  EXPECT_EQ("s^4/ft^2",c.standardUnitsString());
  testNumbersEqual(0.054717690913,c.value());

  // Operations on Quantities with units of temperature
  LOG(Debug,"Quantity_FahrenheitUnit_Arithmetic");

  FahrenheitUnit fu1(1, 0, "");
  Quantity T1(60.0,fu1);
  FahrenheitUnit fu2(1);
  Quantity T2(74.0,fu2);
  Quantity TT1 = pow(T1,2);
  Quantity TT2 = pow(T2,2);

  EXPECT_TRUE(TT1.isAbsolute());
  EXPECT_TRUE(TT2.isAbsolute());

  Quantity q;

  // -, unary
  q = -T1;
  testStreamOutput("-60 F",q);
  q.setAsRelative();
  q = -q;
  testStreamOutput("60 F",q);
  EXPECT_FALSE(q.isAbsolute());

  // +, good units, bad units, absolute + relative = absolute
  q = T1 + T2;
  EXPECT_TRUE(q.isAbsolute());
  testStreamOutput("134 F",q,0);
  EXPECT_THROW(T1 + TT1,Exception);
  q.setAsRelative();
  q += T1;
  EXPECT_TRUE(q.isAbsolute());

  // -, binary, good units, bad units, absolute -> relative when exp == 1, ow same as +
  q = T2 - T1;
  testStreamOutput("14 F",q,0);
  EXPECT_FALSE(q.isAbsolute());
//.........这里部分代码省略.........
开发者ID:pepsi7959,项目名称:OpenStudio,代码行数:101,代码来源:Quantity_GTest.cpp


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