コード例 #1
0
ファイル: UnitFactory_GTest.cpp プロジェクト: NREL/OpenStudio
TEST_F(UnitsFixture,UnitFactory_KitchenSink) {
  // unregistered compound units
  SIUnit eui = openstudio::createUnit("J/m^2",UnitSystem::SI)->cast<SIUnit>();
  testStreamOutput("J/m^2",eui);
  EXPECT_EQ("kg/s^2",eui.standardString(false));
  EXPECT_EQ(0,eui.scale().exponent);

  BTUUnit ipEui = openstudio::createUnit("Btu/ft^2",UnitSystem::BTU)->cast<BTUUnit>();
  testStreamOutput("Btu/ft^2",ipEui);
  EXPECT_EQ("",ipEui.prettyString());
  EXPECT_EQ(0,eui.scale().exponent);

  // scaled atomic units
  SIUnit f1 = openstudio::createUnit("\\muN",UnitSystem::SI)->cast<SIUnit>();
  testStreamOutput("\\muN",f1);
  EXPECT_EQ(-6,f1.scale().exponent);

  // parenthetical scaled units
  f1 = openstudio::createUnit("c(kg*m/s^2)",UnitSystem::SI)->cast<SIUnit>();
  testStreamOutput("cN",f1);
  EXPECT_EQ(-2,f1.scale().exponent);

  // first baseUnit scaled
  eui = openstudio::createUnit("MJ/m^2",UnitSystem::SI)->cast<SIUnit>();
  testStreamOutput("MJ/m^2",eui);
  EXPECT_EQ("kg/s^2",eui.standardString(false));
  EXPECT_EQ(6,eui.scale().exponent);

  ipEui = openstudio::createUnit("kBtu/ft^2",UnitSystem::BTU)->cast<BTUUnit>();
  testStreamOutput("kBtu/ft^2",ipEui);
  EXPECT_EQ("Btu/ft^2",ipEui.standardString(false));
  EXPECT_EQ("",ipEui.prettyString());
  EXPECT_EQ(3,ipEui.scale().exponent);

  // multiple baseUnits scaled
  SIUnit u = openstudio::createUnit("MJ/ms*kK",UnitSystem::SI)->cast<SIUnit>();
  testStreamOutput("MW/K",u);
  EXPECT_EQ(6,u.scale().exponent);
  EXPECT_EQ(1,u.baseUnitExponent("kg"));
  EXPECT_EQ(2,u.baseUnitExponent("m"));
  EXPECT_EQ(-3,u.baseUnitExponent("s"));
  EXPECT_EQ(-1,u.baseUnitExponent("K"));

  // odd bug observed. test added so can fix it.
  std::string unitString = openstudio::extractUnitString("J/J");
  u = openstudio::createUnit(unitString,UnitSystem::SI)->cast<SIUnit>();
  EXPECT_EQ("",u.standardString(false));
  EXPECT_EQ("",u.prettyString());
}
コード例 #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());

}