コード例 #1
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));
 */

}
コード例 #2
0
TEST_F(UnitsFixture,QuantityRegex_DecomposeCompoundUnits) {
  std::string uStr("1/s");
  std::pair< std::vector<std::string>,std::vector<std::string> > result;
  result = decomposeCompoundUnitString(uStr);
  ASSERT_EQ(static_cast<size_t>(0),result.first.size()); 
  ASSERT_EQ(static_cast<size_t>(1),result.second.size());
  EXPECT_EQ("s",result.second[0]);

  uStr = "kg*m/s^2"; result = decomposeCompoundUnitString(uStr);
  ASSERT_EQ(static_cast<size_t>(2),result.first.size()); 
  ASSERT_EQ(static_cast<size_t>(1),result.second.size());
  EXPECT_EQ("kg",result.first[0]); EXPECT_EQ("m",result.first[1]);
  EXPECT_EQ("s^2",result.second[0]);

  uStr = "s^{-1}/ft^{-1}"; result = decomposeCompoundUnitString(uStr);
  ASSERT_EQ(static_cast<size_t>(1),result.first.size()); 
  ASSERT_EQ(static_cast<size_t>(1),result.second.size());
  EXPECT_EQ("s^{-1}",result.first[0]);
  EXPECT_EQ("ft^{-1}",result.second[0]);

  uStr = "kg"; result = decomposeCompoundUnitString(uStr);
  ASSERT_EQ(static_cast<size_t>(1),result.first.size()); 
  ASSERT_EQ(static_cast<size_t>(0),result.second.size());
  EXPECT_EQ("kg",result.first[0]);

  uStr = "1/s^2*K"; result = decomposeCompoundUnitString(uStr);
  ASSERT_EQ(static_cast<size_t>(0),result.first.size()); 
  ASSERT_EQ(static_cast<size_t>(2),result.second.size());
  EXPECT_EQ("s^2",result.second[0]); EXPECT_EQ("K",result.second[1]);

  EXPECT_THROW(decomposeCompoundUnitString(" kg*m"),openstudio::Exception);
  EXPECT_THROW(decomposeCompoundUnitString("2 1/s"),openstudio::Exception);
}