TEST_F(UnitsFixture,SIUnit_ArithmeticOperators) { LOG(Debug,"SIUnit_ArithmeticOperators"); SIUnit u1; SIUnit u2(SIExpnt(1,1,-2,0),0,"N"); SIUnit u3(SIExpnt(1)); // kg SIUnit u4(SIExpnt(0,1,0,0),-2); // cm // multiplication u1 *= u3; // kg testStreamOutput("kg",u1); Unit u5 = u2*u3; // N*kg EXPECT_TRUE(u5.system() == UnitSystem::SI); testStreamOutput("N*kg",u5); Unit u6 = u2*u4; // cJ EXPECT_TRUE(u6.system() == UnitSystem::SI); testStreamOutput("cJ",u6); // division u6 /= u4; EXPECT_TRUE(u6 == u2); // power Unit u7 = pow(u4,6); // (cm)^6 EXPECT_TRUE(u7.system() == UnitSystem::SI); testStreamOutput("cm^6",u7); EXPECT_EQ("p",u7.scale().abbr); u7.pow(1,3); // (cm)^2 testStreamOutput("m(m^2)",u7); // no 10^-4 scale--moves to 10^-3 }
TEST_F(UnitsFixture,SIUnit_Constructors) { LOG(Debug,"SIUnit_Constructors"); // default SIUnit u1; ASSERT_NO_THROW(u1.setBaseUnitExponent("m",1)); ASSERT_THROW(u1.setBaseUnitExponent("ft",2),Exception); testStreamOutput("m",u1); // default with pretty string SIUnit u2(SIExpnt(1,1,-2,0),0,"N"); testStreamOutput("N",u2); // scale exponent and pretty string SIUnit u3(SIExpnt(1,1,-2,0),3,"N"); testStreamOutput("kN",u3); EXPECT_TRUE(u3.baseUnitExponent("kg") == 1); EXPECT_TRUE(u3.baseUnitExponent("K") == 0); EXPECT_TRUE(u3.baseUnitExponent("ft") == 0); u2.setScale("\\mu"); testStreamOutput("\\muN",u2); // scale abbreviation SIUnit u4("c",SIExpnt(0,0,0,1)); testStreamOutput("cK",u4); EXPECT_EQ(1,u4.baseUnitExponent("K")); }
TEST_F(UnitsFixture,SIUnit_LogicalOperators) { LOG(Debug,"SIUnit_LogicalOperators"); SIUnit u1; SIUnit u2(SIExpnt(1,1,-2)); SIUnit u3(SIExpnt(1,1,-2,0),3); EXPECT_TRUE(u2 == u3); EXPECT_FALSE(u1 == u3); }