Beispiel #1
0
  bool IPUnit_Impl::operator==(const Unit& rUnit) const {
    // compare using lb_m
    IPUnit wLUnit = clone().cast<IPUnit>();
    wLUnit.lbfToLbm();

    Unit wRUnit = rUnit.clone();
    if (OptionalIPUnit temp = wRUnit.optionalCast<IPUnit>()) {
      temp->lbfToLbm();

      // loop through and check each exponent
      BOOST_FOREACH(const std::string& baseUnit,wLUnit.baseUnits()) {
        if (wLUnit.baseUnitExponent(baseUnit) != wRUnit.baseUnitExponent(baseUnit)) {
          return false;
        }
      }

      return true;
    }
TEST_F(UnitsFixture,IPUnit_createFunctions)
{
    IPUnit u;

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

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

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

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

    u = createIPPeople();
    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 = createIPCurrency();
    EXPECT_EQ(1, u.baseUnitExponent("$"));
    EXPECT_EQ(0, u.scale().exponent);
    EXPECT_EQ("$", u.standardString());
    EXPECT_EQ("", u.prettyString());
    u.pow(-1);
    EXPECT_EQ("1/$", u.standardString());

    u = createIPForce();
    EXPECT_EQ(0,u.scale().exponent);
    EXPECT_EQ("lb_f",u.standardString());
    EXPECT_EQ("",u.prettyString());

    u = createIPEnergy();
    EXPECT_EQ(0,u.scale().exponent);
    EXPECT_EQ("ft*lb_f",u.standardString());
    EXPECT_EQ("",u.prettyString());

    u = createIPPower();
    EXPECT_EQ(0,u.scale().exponent);
    EXPECT_EQ("ft*lb_f/s",u.standardString());
    EXPECT_EQ("",u.prettyString());


}