MathLib: Added test for isDec() and removed not required state.

This commit is contained in:
orbitcowboy 2014-11-14 04:29:35 +01:00
parent fafcf40ee6
commit b9a9f51fe0
2 changed files with 20 additions and 3 deletions

View File

@ -464,7 +464,7 @@ bool MathLib::isBin(const std::string& s)
bool MathLib::isDec(const std::string & s) bool MathLib::isDec(const std::string & s)
{ {
enum Status { enum Status {
START, PLUSMINUS, DIGIT, SUFFIX START, PLUSMINUS, DIGIT
} state = START; } state = START;
for (std::string::const_iterator it = s.begin(); it != s.end(); ++it) { for (std::string::const_iterator it = s.begin(); it != s.end(); ++it) {
switch (state) { switch (state) {
@ -488,8 +488,6 @@ bool MathLib::isDec(const std::string & s)
else else
return isValidSuffix(it,s.end()); return isValidSuffix(it,s.end());
break; break;
case SUFFIX:
break;
} }
} }
return state == DIGIT; return state == DIGIT;

View File

@ -31,6 +31,7 @@ private:
void run() { void run() {
TEST_CASE(isint); TEST_CASE(isint);
TEST_CASE(isbin); TEST_CASE(isbin);
TEST_CASE(isdec);
TEST_CASE(isoct); TEST_CASE(isoct);
TEST_CASE(ishex); TEST_CASE(ishex);
TEST_CASE(isnegative); TEST_CASE(isnegative);
@ -613,6 +614,24 @@ private:
ASSERT_EQUALS("-inf.0", MathLib::divide("-3.0", "0.0f")); // -inf (#5142) ASSERT_EQUALS("-inf.0", MathLib::divide("-3.0", "0.0f")); // -inf (#5142)
ASSERT_EQUALS("inf.0", MathLib::divide("-3.0", "-0.0f")); // inf (#5142) ASSERT_EQUALS("inf.0", MathLib::divide("-3.0", "-0.0f")); // inf (#5142)
} }
void isdec(void)
{
// positive testing
ASSERT_EQUALS(true, MathLib::isDec("1"));
ASSERT_EQUALS(true, MathLib::isDec("+1"));
ASSERT_EQUALS(true, MathLib::isDec("-1"));
ASSERT_EQUALS(true, MathLib::isDec("-100"));
ASSERT_EQUALS(true, MathLib::isDec("-1L"));
ASSERT_EQUALS(true, MathLib::isDec("1UL"));
// negative testing
ASSERT_EQUALS(false, MathLib::isDec("-1."));
ASSERT_EQUALS(false, MathLib::isDec("+1."));
ASSERT_EQUALS(false, MathLib::isDec("-x"));
ASSERT_EQUALS(false, MathLib::isDec("+x"));
ASSERT_EQUALS(false, MathLib::isDec("x"));
}
void isNullValue() const { void isNullValue() const {
// inter zero value // inter zero value