From b9a9f51fe08b53ab8b338f30d93ce4ada90a28dd Mon Sep 17 00:00:00 2001 From: orbitcowboy Date: Fri, 14 Nov 2014 04:29:35 +0100 Subject: [PATCH] MathLib: Added test for isDec() and removed not required state. --- lib/mathlib.cpp | 4 +--- test/testmathlib.cpp | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/lib/mathlib.cpp b/lib/mathlib.cpp index 3f1c84dd3..651c54d2f 100644 --- a/lib/mathlib.cpp +++ b/lib/mathlib.cpp @@ -464,7 +464,7 @@ bool MathLib::isBin(const std::string& s) bool MathLib::isDec(const std::string & s) { enum Status { - START, PLUSMINUS, DIGIT, SUFFIX + START, PLUSMINUS, DIGIT } state = START; for (std::string::const_iterator it = s.begin(); it != s.end(); ++it) { switch (state) { @@ -488,8 +488,6 @@ bool MathLib::isDec(const std::string & s) else return isValidSuffix(it,s.end()); break; - case SUFFIX: - break; } } return state == DIGIT; diff --git a/test/testmathlib.cpp b/test/testmathlib.cpp index 6a6eb4773..eb4915162 100644 --- a/test/testmathlib.cpp +++ b/test/testmathlib.cpp @@ -31,6 +31,7 @@ private: void run() { TEST_CASE(isint); TEST_CASE(isbin); + TEST_CASE(isdec); TEST_CASE(isoct); TEST_CASE(ishex); 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) } + + 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 { // inter zero value