TEST_F(UnitsFixture,QuantityRegex_DirectScaledUnit) {

  // direct scaled unit
  std::string aMatch("people/1000 ft^2");
  EXPECT_TRUE(isDirectScaledUnit(aMatch));
  aMatch = "1/10kg"; EXPECT_TRUE(isDirectScaledUnit(aMatch));
  aMatch = "people/100*m^2"; EXPECT_TRUE(isDirectScaledUnit(aMatch));

  // not a direct scaled unit
  std::string notAMatch("m^2");
  EXPECT_FALSE(isDirectScaledUnit(notAMatch));
  notAMatch = "kg/10**m"; EXPECT_FALSE(isDirectScaledUnit(notAMatch));

  // contains a direct scaled unit
  std::string includesMatch("32 people/100 m^2");
  EXPECT_TRUE(containsDirectScaledUnit(includesMatch));
  boost::smatch m;
  boost::regex_search(includesMatch,m,regexEmbeddedDirectScaledUnit());
  std::string unitStr = std::string(m[1].first,m[1].second);
  EXPECT_EQ("people/100 m^2",unitStr);
  std::pair<std::string,std::pair<unsigned,std::string> > result;
  result = decomposeDirectScaledUnit(unitStr);
  EXPECT_EQ("people/",result.first);
  EXPECT_EQ(static_cast<unsigned>(2),result.second.first);
  EXPECT_EQ("m^2",result.second.second);
  
  includesMatch = "Occupancy (people/1000*ft^2)";
  EXPECT_TRUE(containsDirectScaledUnit(includesMatch));
  boost::regex_search(includesMatch,m,regexEmbeddedDirectScaledUnit());
  unitStr = std::string(m[5].first,m[5].second);
  EXPECT_EQ("people/1000*ft^2",unitStr);
  result = decomposeDirectScaledUnit(unitStr);
  EXPECT_EQ("people/",result.first);
  EXPECT_EQ(static_cast<unsigned>(3),result.second.first);
  EXPECT_EQ("ft^2",result.second.second);

  includesMatch = "1/10kg";
  EXPECT_TRUE(containsDirectScaledUnit(includesMatch));
  boost::regex_search(includesMatch,m,regexEmbeddedDirectScaledUnit());
  unitStr = std::string(m[1].first,m[1].second);
  EXPECT_EQ("1/10kg",unitStr);
  result = decomposeDirectScaledUnit(unitStr);
  EXPECT_EQ("1/",result.first);
  EXPECT_EQ(static_cast<unsigned>(1),result.second.first);
  EXPECT_EQ("kg",result.second.second);

}
示例#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));
 */

}