File tree Expand file tree Collapse file tree 2 files changed +20
-3
lines changed
Expand file tree Collapse file tree 2 files changed +20
-3
lines changed Original file line number Diff line number Diff line change @@ -464,7 +464,7 @@ bool MathLib::isBin(const std::string& s)
464464bool 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;
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments