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)); */ }
TEST_F(UnitsFixture,QuantityRegex_Units) { // should be AtomicUnits std::string atomicUnit("kg"); EXPECT_TRUE(isAtomicUnit(atomicUnit)); atomicUnit = "MJ"; EXPECT_TRUE(isAtomicUnit(atomicUnit)); atomicUnit = "kBtu^3"; EXPECT_TRUE(isAtomicUnit(atomicUnit)); atomicUnit = "s^{-1}"; EXPECT_TRUE(isAtomicUnit(atomicUnit)); atomicUnit = "ms^5"; EXPECT_TRUE(isAtomicUnit(atomicUnit)); atomicUnit = "aioranb^32"; EXPECT_TRUE(isAtomicUnit(atomicUnit)); atomicUnit = "\\muN"; EXPECT_TRUE(isAtomicUnit(atomicUnit)); atomicUnit = "lb_f^2"; EXPECT_TRUE(isAtomicUnit(atomicUnit)); // should not be AtomicUnits std::string notAtomicUnit("m/s"); EXPECT_FALSE(isAtomicUnit(notAtomicUnit)); notAtomicUnit = " m "; EXPECT_FALSE(isAtomicUnit(notAtomicUnit)); notAtomicUnit = "kBtu/h"; EXPECT_FALSE(isAtomicUnit(notAtomicUnit)); notAtomicUnit = "kg*m"; EXPECT_FALSE(isAtomicUnit(notAtomicUnit)); notAtomicUnit = "3 s"; EXPECT_FALSE(isAtomicUnit(notAtomicUnit)); notAtomicUnit = "kN*m"; EXPECT_FALSE(isAtomicUnit(notAtomicUnit)); notAtomicUnit = "hippopotamus^3"; EXPECT_FALSE(isAtomicUnit(notAtomicUnit)); notAtomicUnit = "ft^2,"; EXPECT_FALSE(isAtomicUnit(notAtomicUnit)); // should contain AtomicUnits std::string includesUnit("kg*m"); EXPECT_TRUE(containsAtomicUnit(includesUnit)); includesUnit = "short words"; EXPECT_TRUE(containsAtomicUnit(includesUnit)); includesUnit = "kg^2/ms"; EXPECT_TRUE(containsAtomicUnit(includesUnit)); includesUnit = "hello s^{-2}"; EXPECT_TRUE(containsAtomicUnit(includesUnit)); // should not contain AtomicUnits std::string doesNotContainUnit("kg^^3"); EXPECT_FALSE(containsAtomicUnit(doesNotContainUnit)); doesNotContainUnit = "3"; EXPECT_FALSE(containsAtomicUnit(doesNotContainUnit)); doesNotContainUnit = "m^-3"; EXPECT_FALSE(containsAtomicUnit(doesNotContainUnit)); doesNotContainUnit = "*2/"; EXPECT_FALSE(containsAtomicUnit(doesNotContainUnit)); // compoundUnits std::string compoundUnit("kg/s"); EXPECT_TRUE(isCompoundUnit(compoundUnit)); compoundUnit = "ft^2"; EXPECT_TRUE(isCompoundUnit(compoundUnit)); compoundUnit = "1/s"; EXPECT_TRUE(isCompoundUnit(compoundUnit)); compoundUnit = "1/s^2"; EXPECT_TRUE(isCompoundUnit(compoundUnit)); compoundUnit = "kg*m^2/s^2"; EXPECT_TRUE(isCompoundUnit(compoundUnit)); compoundUnit = "MJ^{-3}"; EXPECT_TRUE(isCompoundUnit(compoundUnit)); compoundUnit = "s^{-1}/m^{-1}"; EXPECT_TRUE(isCompoundUnit(compoundUnit)); // not compoundUnits std::string notCompoundUnit("k(kg/s)"); EXPECT_FALSE(isCompoundUnit(notCompoundUnit)); notCompoundUnit = " m/s^2"; EXPECT_FALSE(isCompoundUnit(notCompoundUnit)); notCompoundUnit = "31"; EXPECT_FALSE(isCompoundUnit(notCompoundUnit)); notCompoundUnit = "0.12 kg"; EXPECT_FALSE(isCompoundUnit(notCompoundUnit)); notCompoundUnit = "hiccocampus"; EXPECT_FALSE(isCompoundUnit(notCompoundUnit)); notCompoundUnit = "ft^^2"; EXPECT_FALSE(isCompoundUnit(notCompoundUnit)); notCompoundUnit = "ft^{2}"; EXPECT_FALSE(isCompoundUnit(notCompoundUnit)); notCompoundUnit = "ft/s,"; EXPECT_FALSE(isCompoundUnit(notCompoundUnit)); // contains compountUnit std::string includesCompoundUnit("3 kg"); EXPECT_TRUE(containsCompoundUnit(includesCompoundUnit)); includesCompoundUnit = "3.0E-3 k(kg*m/s^2)"; EXPECT_TRUE(containsCompoundUnit(includesCompoundUnit)); includesCompoundUnit = "MJ"; EXPECT_TRUE(containsCompoundUnit(includesCompoundUnit)); includesCompoundUnit = "short words count, unfortunately"; EXPECT_TRUE(containsCompoundUnit(includesCompoundUnit)); includesCompoundUnit = "1 1/s"; EXPECT_TRUE(containsCompoundUnit(includesCompoundUnit)); includesCompoundUnit = "ft/s,"; EXPECT_TRUE(containsCompoundUnit(includesCompoundUnit)); includesCompoundUnit = "J^2/s;"; EXPECT_TRUE(containsCompoundUnit(includesCompoundUnit)); // does not contain compoundUnit std::string noCompoundUnitsHere("hippocampus"); EXPECT_FALSE(containsCompoundUnit(noCompoundUnitsHere)); noCompoundUnitsHere = "32,36819"; EXPECT_FALSE(containsCompoundUnit(noCompoundUnitsHere)); noCompoundUnitsHere = "389ft1986"; EXPECT_FALSE(containsCompoundUnit(noCompoundUnitsHere)); noCompoundUnitsHere = "ft^^2"; EXPECT_FALSE(containsCompoundUnit(noCompoundUnitsHere)); noCompoundUnitsHere = "ft^{2}"; EXPECT_FALSE(containsCompoundUnit(noCompoundUnitsHere)); // scaledUnit std::string scaledUnit("k(m)"); EXPECT_TRUE(isScaledUnit(scaledUnit)); scaledUnit = "M(kg^3)"; EXPECT_TRUE(isScaledUnit(scaledUnit)); scaledUnit = "\\mu(ft^3/s^2)"; EXPECT_TRUE(isScaledUnit(scaledUnit)); scaledUnit = "aaaaa(kg^3)"; EXPECT_TRUE(isScaledUnit(scaledUnit)); scaledUnit = "M(1/s^2*K)"; EXPECT_TRUE(isScaledUnit(scaledUnit)); // not a scaledUnit std::string notScaledUnit("m"); EXPECT_FALSE(isScaledUnit(notScaledUnit)); notScaledUnit = "1/s"; EXPECT_FALSE(isScaledUnit(notScaledUnit)); notScaledUnit = "k(m/s"; EXPECT_FALSE(isScaledUnit(notScaledUnit)); notScaledUnit = "\\mu\\mu(kg*m)"; EXPECT_FALSE(isScaledUnit(notScaledUnit)); notScaledUnit = "km^2)"; EXPECT_FALSE(isScaledUnit(notScaledUnit)); // contains a scaledUnit std::string includesScaledUnit("3 M(kg^3/s^2*K)"); EXPECT_TRUE(containsScaledUnit(includesScaledUnit)); includesScaledUnit = ".1D-38 k(m)"; EXPECT_TRUE(containsScaledUnit(includesScaledUnit)); includesScaledUnit = "surrounding text 32 n(m^2/s) more text"; EXPECT_TRUE(containsScaledUnit(includesScaledUnit)); includesScaledUnit = "32 \\mu(W/s^2), is a funny quantity"; EXPECT_TRUE(containsScaledUnit(includesScaledUnit)); // does not contain a scaledUnit std::string noScaledUnitsHere("3 m"); EXPECT_FALSE(containsScaledUnit(noScaledUnitsHere)); noScaledUnitsHere = "kg*m^2/s^2"; EXPECT_FALSE(containsScaledUnit(noScaledUnitsHere)); noScaledUnitsHere = "1200"; EXPECT_FALSE(containsScaledUnit(noScaledUnitsHere)); noScaledUnitsHere = "1.0E-2 MJ"; EXPECT_FALSE(containsScaledUnit(noScaledUnitsHere)); noScaledUnitsHere = "some text"; EXPECT_FALSE(containsScaledUnit(noScaledUnitsHere)); // unit std::string aUnit("kg*m/s^2"); EXPECT_TRUE(isUnit(aUnit)); aUnit = "km/s"; EXPECT_TRUE(isUnit(aUnit)); aUnit = "M(ft^3/s)"; EXPECT_TRUE(isUnit(aUnit)); aUnit = "nJ"; EXPECT_TRUE(isUnit(aUnit)); aUnit = "\\muN"; EXPECT_TRUE(isUnit(aUnit)); aUnit = "s^{-3}/lb_m^{-2}*h"; EXPECT_TRUE(isUnit(aUnit)); aUnit = "ft*m^2*K/K*lb_f"; EXPECT_TRUE(isUnit(aUnit)); // not a unit std::string notAUnit("(ft/s)"); EXPECT_FALSE(isUnit(notAUnit)); notAUnit = " kN"; EXPECT_FALSE(isUnit(notAUnit)); notAUnit = "m/s^2)"; EXPECT_FALSE(isUnit(notAUnit)); notAUnit = "kW^^2"; EXPECT_FALSE(isUnit(notAUnit)); notAUnit = "cm^-2"; EXPECT_FALSE(isUnit(notAUnit)); notAUnit = "2 m/s"; EXPECT_FALSE(isUnit(notAUnit)); notAUnit = "kg*2"; EXPECT_FALSE(isUnit(notAUnit)); // contains a unit std::string includesAUnit("2 m"); EXPECT_TRUE(containsUnit(includesAUnit)); includesAUnit = "3.2E-2 k(kg^2/s)"; EXPECT_TRUE(containsUnit(includesAUnit)); includesAUnit = " km/s "; EXPECT_TRUE(containsUnit(includesAUnit)); includesAUnit = "short, hairy elephant"; EXPECT_TRUE(containsUnit(includesAUnit)); includesAUnit = " 0.1 m \n 21.3 \\muN"; EXPECT_TRUE(containsUnit(includesAUnit)); includesAUnit = "km/s; "; EXPECT_TRUE(containsUnit(includesAUnit)); includesAUnit = "(ft/s) "; EXPECT_TRUE(containsUnit(includesAUnit)); includesAUnit = "Height [ft]"; EXPECT_TRUE(containsUnit(includesAUnit)); // does not contain a unit std::string noUnitHere("2 m/s)"); EXPECT_FALSE(containsUnit(noUnitHere)); noUnitHere = "kN**ps/J"; EXPECT_FALSE(containsUnit(noUnitHere)); noUnitHere = "32 hippopotamuses"; EXPECT_FALSE(containsUnit(noUnitHere)); noUnitHere = "2.0 mph//J"; EXPECT_FALSE(containsUnit(noUnitHere)); noUnitHere = "2.0 m*2.0"; EXPECT_FALSE(containsUnit(noUnitHere)); }