コード例 #1
0
ファイル: UnitFactory_GTest.cpp プロジェクト: NREL/OpenStudio
TEST_F(UnitsFixture,UnitFactory_TestForAndReturnUnitObjects) {

  LOG(Debug,"UnitFactory_TestForAndReturnUnitObjects");

  ASSERT_TRUE(openstudio::getSystem("s") == UnitSystem::SI);
  ASSERT_TRUE(openstudio::createUnit("s",UnitSystem::IP)->system() == UnitSystem::IP);
  ASSERT_TRUE(openstudio::getSystem("kg*m/s^2") == UnitSystem::SI);
  ASSERT_TRUE(openstudio::getSystem("ft") == UnitSystem::IP);

  OptionalUnit f1 = openstudio::createUnit("kg*m/s^2");
  ASSERT_TRUE(f1);
  ASSERT_NO_THROW(f1->cast<SIUnit>());
  EXPECT_TRUE(f1->system() == UnitSystem::SI);
  {
    SCOPED_TRACE("Creation of N from standard string.");
    testStreamOutput("N",*f1);
  }
  f1 = openstudio::createUnit("ft^2");
  EXPECT_TRUE(f1->system() == UnitSystem::IP);
  ASSERT_ANY_THROW(f1->cast<SIUnit>());
  OptionalUnit T1 = openstudio::createUnit("R");
  ASSERT_NO_THROW(T1->cast<IPUnit>());
  Unit mixedUnit = (*f1)*(*T1);
  {
    SCOPED_TRACE("Output of mixed unit multiplication.");
    testStreamOutput("ft^2*R",mixedUnit);
  }

  ASSERT_TRUE(openstudio::getSystem("Btu/h") == UnitSystem::BTU);
  OptionalUnit e1 = openstudio::createUnit("Btu/h");
  ASSERT_TRUE(e1);
  ASSERT_NO_THROW(e1->cast<BTUUnit>());
  BTUUnit btuU = e1->cast<BTUUnit>();
  EXPECT_EQ(1,btuU.baseUnitExponent("Btu"));
  EXPECT_EQ(-1,btuU.baseUnitExponent("h"));

  ASSERT_TRUE(openstudio::getSystem("CFM") == UnitSystem::CFM);
  CFMUnit cfmU = openstudio::createUnit("CFM")->cast<CFMUnit>();
  EXPECT_EQ(3,cfmU.baseUnitExponent("ft"));
  EXPECT_EQ(-1,cfmU.baseUnitExponent("min"));
  EXPECT_EQ("cfm",cfmU.prettyString());

  ASSERT_EQ(UnitSystem::Celsius,openstudio::getSystem("C").value());
  CelsiusUnit TC = openstudio::createUnit("C")->cast<CelsiusUnit>();
  ASSERT_ANY_THROW(openstudio::createUnit("W/K")->cast<CelsiusUnit>());

  ASSERT_FALSE(openstudio::isInSystem("F*ft",UnitSystem::Fahrenheit));
  FahrenheitUnit TF = openstudio::createUnit("F")->cast<FahrenheitUnit>();
}
コード例 #2
0
ファイル: BTUUnit_GTest.cpp プロジェクト: jtanaa/OpenStudio
TEST_F(UnitsFixture,BTUUnit_CreateFunctions)
{
  BTUUnit u;

  u = createBTULength();
  EXPECT_EQ(1,u.baseUnitExponent("ft"));
  EXPECT_EQ(0,u.scale().exponent);
  EXPECT_EQ("ft",u.standardString(false));
  EXPECT_EQ("",u.prettyString());

  u = createBTUTime();
  EXPECT_EQ(1,u.baseUnitExponent("h"));
  EXPECT_EQ(0,u.scale().exponent);
  EXPECT_EQ("h",u.standardString(false));
  EXPECT_EQ("",u.prettyString());

  u = createBTUTemperature();
  EXPECT_EQ(1,u.baseUnitExponent("R"));
  EXPECT_EQ(0,u.scale().exponent);
  EXPECT_EQ("R",u.standardString(false));
  EXPECT_EQ("",u.prettyString());

  u = createBTUPeople();
  EXPECT_EQ(1,u.baseUnitExponent("people"));
  EXPECT_EQ(0,u.scale().exponent);
  EXPECT_EQ("people",u.standardString(false));
  EXPECT_EQ("",u.prettyString());
  u.pow(-1);
  EXPECT_EQ("1/person",u.standardString(false));

  u = createBTUEnergy();
  EXPECT_EQ(0,u.scale().exponent);
  EXPECT_EQ("Btu",u.standardString(false));
  EXPECT_EQ("",u.prettyString());

  u = createBTUPower();
  EXPECT_EQ(0,u.scale().exponent);
  EXPECT_EQ("Btu/h",u.standardString(false));
  EXPECT_EQ("",u.prettyString());

}