TEST_F(UnitsFixture,QuantityRegex_DecomposeAtomicUnits) {
  std::string uStr("m");
  std::pair<std::string,int> result;
  result = decomposeAtomicUnitString(uStr);
  EXPECT_EQ("m",result.first); EXPECT_EQ(1,result.second);

  uStr = "kg^3"; result = decomposeAtomicUnitString(uStr);
  EXPECT_EQ("kg",result.first); EXPECT_EQ(3,result.second);

  uStr = "short^{-3291}"; result = decomposeAtomicUnitString(uStr);
  EXPECT_EQ("short",result.first); EXPECT_EQ(-3291,result.second);

  EXPECT_THROW(decomposeAtomicUnitString("kg^{2}"),openstudio::Exception);
  EXPECT_THROW(decomposeAtomicUnitString("kg/s"),openstudio::Exception);
}
示例#2
0
TEST_F(UnitsFixture,QuantityRegex_PumpFields) {

  std::string aUnit;
  // Design Shaft Power per Unit Flow Rate per Unit Head is posing problems
  // After trial and error, I can format the IDD so it works: No parenthesis, one divisor
  // Currently this is the only one that passes
  aUnit = "W*s/m^3*Pa"; EXPECT_TRUE(isUnit(aUnit));
  aUnit = "W*min/gal*ftH_{2}O"; EXPECT_TRUE(isUnit(aUnit));


  std::pair<std::string,int> atomicDecomp;

  aUnit = "ftH_{2}O";
  // this shouldn't be an atomic unit!
  // EXPECT_FALSE(isAtomicUnit(aUnit));

  // But we can at least make sure that the decomposition at least returns the right exponent (1...)
  atomicDecomp = decomposeAtomicUnitString(aUnit);
  EXPECT_EQ("ftH_{2}O", atomicDecomp.first);
  EXPECT_EQ(1, atomicDecomp.second);

  aUnit = "1/ftH_{2}O";
  EXPECT_FALSE(containsScientificNotationValue(aUnit));
  // There is no multiplier (km, ms, etc)
  // This returns TRUE, like above... but we'll make sure it ends up fine...
  // EXPECT_FALSE(containsAtomicUnit(aUnit));

  // 1 over something is a Compound Unit)
  EXPECT_TRUE(containsCompoundUnit(aUnit));

  EXPECT_FALSE(containsScaledUnit(aUnit));
  EXPECT_FALSE(containsDirectScaledUnit(aUnit));
  EXPECT_TRUE(isUnit(aUnit));

  ASSERT_TRUE(isCompoundUnit(aUnit));

  std::pair< std::vector<std::string>,std::vector<std::string> > result;

  result = decomposeCompoundUnitString(aUnit);
  // Nothing on numerator
  ASSERT_EQ(static_cast<size_t>(0),result.first.size());
  // Should have one unit on the denominator
  ASSERT_EQ(static_cast<size_t>(1),result.second.size());
  EXPECT_EQ("ftH_{2}O",result.second[0]);


  // All of these variations do fail
/*
 *  aUnit = "(W*s)/(m^3*Pa)"; EXPECT_TRUE(isUnit(aUnit));
 *  aUnit = "(W*s)/(m^3*Pa)"; EXPECT_TRUE(isUnit(aUnit));
 *
 *  aUnit = "(W*min)/(gal*ftH_{2}O)"; EXPECT_TRUE(isUnit(aUnit));
 *  aUnit = "W*min/(gal*ftH_{2}O)"; EXPECT_TRUE(isUnit(aUnit));
 *
 *  aUnit = "W/((m^3/s)*Pa)"; EXPECT_TRUE(isUnit(aUnit));
 *  aUnit = "W/((gal/min)*ftH_{2}O)"; EXPECT_TRUE(isUnit(aUnit));
 */

}