MathLib: Added test for isDec() and removed not required state.
This commit is contained in:
parent
fafcf40ee6
commit
b9a9f51fe0
|
@ -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;
|
||||||
|
|
|
@ -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);
|
||||||
|
@ -614,6 +615,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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
||||||
ASSERT_EQUALS(true, MathLib::isNullValue("0"));
|
ASSERT_EQUALS(true, MathLib::isNullValue("0"));
|
||||||
|
|
Loading…
Reference in New Issue