Example #1
0
TEST_F(UnitsFixture,SIUnit_createFunctions)
{
    SIUnit u;

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

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

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

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

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

    u = createSIForce();
    EXPECT_EQ(0,u.scale().exponent);
    EXPECT_EQ("kg*m/s^2",u.standardString());
    EXPECT_EQ("N",u.prettyString());

    u = createSIEnergy();
    EXPECT_EQ(0,u.scale().exponent);
    EXPECT_EQ("kg*m^2/s^2",u.standardString());
    EXPECT_EQ("J",u.prettyString());

    u = createSIPower();
    EXPECT_EQ(0,u.scale().exponent);
    EXPECT_EQ("kg*m^2/s^3",u.standardString());
    EXPECT_EQ("W",u.prettyString());

}
Example #2
0
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());
}