Esempio n. 1
0
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>();
}
Esempio n. 2
0
TEST_F(UnitsFixture,CFMUnit_CreateFunctions)
{
  CFMUnit u;

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

  u = createCFMTime();
  EXPECT_EQ(1,u.baseUnitExponent("min"));
  EXPECT_EQ(0,u.scale().exponent);
  EXPECT_EQ("min",u.standardString());
  EXPECT_EQ("",u.prettyString());

  u = createCFMPower();
  EXPECT_EQ(1,u.baseUnitExponent("ton"));
  EXPECT_EQ(0,u.scale().exponent);
  EXPECT_EQ("ton",u.standardString());
  EXPECT_EQ("",u.prettyString());

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

  u = createCFMPeople();
  EXPECT_EQ(1,u.baseUnitExponent("people"));
  EXPECT_EQ(0,u.scale().exponent);
  EXPECT_EQ("people",u.standardString());
  EXPECT_EQ("",u.prettyString());

  u = createCFMVolumetricFlowrate();
  EXPECT_EQ(3,u.baseUnitExponent("ft"));
  EXPECT_EQ(-1,u.baseUnitExponent("min"));
  EXPECT_EQ(0,u.scale().exponent);
  EXPECT_EQ("ft^3/min",u.standardString());
  EXPECT_EQ("cfm",u.prettyString());

}