Skip to content

Commit b9a9f51

Browse files
committed
MathLib: Added test for isDec() and removed not required state.
1 parent fafcf40 commit b9a9f51

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

lib/mathlib.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ bool MathLib::isBin(const std::string& s)
464464
bool MathLib::isDec(const std::string & s)
465465
{
466466
enum Status {
467-
START, PLUSMINUS, DIGIT, SUFFIX
467+
START, PLUSMINUS, DIGIT
468468
} state = START;
469469
for (std::string::const_iterator it = s.begin(); it != s.end(); ++it) {
470470
switch (state) {
@@ -488,8 +488,6 @@ bool MathLib::isDec(const std::string & s)
488488
else
489489
return isValidSuffix(it,s.end());
490490
break;
491-
case SUFFIX:
492-
break;
493491
}
494492
}
495493
return state == DIGIT;

test/testmathlib.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class TestMathLib : public TestFixture {
3131
void run() {
3232
TEST_CASE(isint);
3333
TEST_CASE(isbin);
34+
TEST_CASE(isdec);
3435
TEST_CASE(isoct);
3536
TEST_CASE(ishex);
3637
TEST_CASE(isnegative);
@@ -613,6 +614,24 @@ class TestMathLib : public TestFixture {
613614
ASSERT_EQUALS("-inf.0", MathLib::divide("-3.0", "0.0f")); // -inf (#5142)
614615
ASSERT_EQUALS("inf.0", MathLib::divide("-3.0", "-0.0f")); // inf (#5142)
615616
}
617+
618+
void isdec(void)
619+
{
620+
// positive testing
621+
ASSERT_EQUALS(true, MathLib::isDec("1"));
622+
ASSERT_EQUALS(true, MathLib::isDec("+1"));
623+
ASSERT_EQUALS(true, MathLib::isDec("-1"));
624+
ASSERT_EQUALS(true, MathLib::isDec("-100"));
625+
ASSERT_EQUALS(true, MathLib::isDec("-1L"));
626+
ASSERT_EQUALS(true, MathLib::isDec("1UL"));
627+
628+
// negative testing
629+
ASSERT_EQUALS(false, MathLib::isDec("-1."));
630+
ASSERT_EQUALS(false, MathLib::isDec("+1."));
631+
ASSERT_EQUALS(false, MathLib::isDec("-x"));
632+
ASSERT_EQUALS(false, MathLib::isDec("+x"));
633+
ASSERT_EQUALS(false, MathLib::isDec("x"));
634+
}
616635

617636
void isNullValue() const {
618637
// inter zero value

0 commit comments

Comments
 (0)