testsuite: don't compare doubles with !=

This commit is contained in:
Daniel Marjamäki 2017-10-10 22:40:49 +02:00
parent e59ebed3b0
commit f9d8dd9f4d
3 changed files with 29 additions and 29 deletions

View File

@ -345,31 +345,31 @@ private:
}
void toDoubleNumber() const {
ASSERT_EQUALS_DOUBLE(10.0 , MathLib::toDoubleNumber("10"));
ASSERT_EQUALS_DOUBLE(1000.0, MathLib::toDoubleNumber("10E+2"));
ASSERT_EQUALS_DOUBLE(100.0 , MathLib::toDoubleNumber("1.0E+2"));
ASSERT_EQUALS_DOUBLE(-100.0, MathLib::toDoubleNumber("-1.0E+2"));
ASSERT_EQUALS_DOUBLE(-1e+10, MathLib::toDoubleNumber("-1.0E+10"));
ASSERT_EQUALS_DOUBLE(100.0 , MathLib::toDoubleNumber("+1.0E+2"));
ASSERT_EQUALS_DOUBLE(1e+10 , MathLib::toDoubleNumber("+1.0E+10"));
ASSERT_EQUALS_DOUBLE(100.0 , MathLib::toDoubleNumber("1.0E+2"));
ASSERT_EQUALS_DOUBLE(1e+10 , MathLib::toDoubleNumber("1.0E+10"));
ASSERT_EQUALS_DOUBLE(0.0 , MathLib::toDoubleNumber("0E+0"));
ASSERT_EQUALS_DOUBLE(0.0 , MathLib::toDoubleNumber("0E-0"));
ASSERT_EQUALS_DOUBLE(0.0 , MathLib::toDoubleNumber("0E+00"));
ASSERT_EQUALS_DOUBLE(0.0 , MathLib::toDoubleNumber("0E-00"));
ASSERT_EQUALS_DOUBLE(0.0 , MathLib::toDoubleNumber("-0E+00"));
ASSERT_EQUALS_DOUBLE(0.0 , MathLib::toDoubleNumber("+0E-00"));
ASSERT_EQUALS_DOUBLE(0.0 , MathLib::toDoubleNumber("0"));
ASSERT_EQUALS_DOUBLE(0.0 , MathLib::toDoubleNumber("0."));
ASSERT_EQUALS_DOUBLE(0.0 , MathLib::toDoubleNumber("0.0"));
ASSERT_EQUALS_DOUBLE(0.0 , MathLib::toDoubleNumber("-0"));
ASSERT_EQUALS_DOUBLE(0.0 , MathLib::toDoubleNumber("+0"));
ASSERT_EQUALS_DOUBLE(0.0 , MathLib::toDoubleNumber("-0."));
ASSERT_EQUALS_DOUBLE(0.0 , MathLib::toDoubleNumber("+0."));
ASSERT_EQUALS_DOUBLE(0.0 , MathLib::toDoubleNumber("-0.0"));
ASSERT_EQUALS_DOUBLE(0.0 , MathLib::toDoubleNumber("+0.0"));
ASSERT_EQUALS_DOUBLE('0' , MathLib::toDoubleNumber("'0'"));
ASSERT_EQUALS_DOUBLE(10.0 , MathLib::toDoubleNumber("10"), 0.001);
ASSERT_EQUALS_DOUBLE(1000.0, MathLib::toDoubleNumber("10E+2"), 0.001);
ASSERT_EQUALS_DOUBLE(100.0 , MathLib::toDoubleNumber("1.0E+2"), 0.001);
ASSERT_EQUALS_DOUBLE(-100.0, MathLib::toDoubleNumber("-1.0E+2"), 0.001);
ASSERT_EQUALS_DOUBLE(-1e+10, MathLib::toDoubleNumber("-1.0E+10"), 1);
ASSERT_EQUALS_DOUBLE(100.0 , MathLib::toDoubleNumber("+1.0E+2"), 0.001);
ASSERT_EQUALS_DOUBLE(1e+10 , MathLib::toDoubleNumber("+1.0E+10"), 1);
ASSERT_EQUALS_DOUBLE(100.0 , MathLib::toDoubleNumber("1.0E+2"), 0.001);
ASSERT_EQUALS_DOUBLE(1e+10 , MathLib::toDoubleNumber("1.0E+10"), 1);
ASSERT_EQUALS_DOUBLE(0.0 , MathLib::toDoubleNumber("0E+0"), 0.000001);
ASSERT_EQUALS_DOUBLE(0.0 , MathLib::toDoubleNumber("0E-0"), 0.000001);
ASSERT_EQUALS_DOUBLE(0.0 , MathLib::toDoubleNumber("0E+00"), 0.000001);
ASSERT_EQUALS_DOUBLE(0.0 , MathLib::toDoubleNumber("0E-00"), 0.000001);
ASSERT_EQUALS_DOUBLE(0.0 , MathLib::toDoubleNumber("-0E+00"), 0.000001);
ASSERT_EQUALS_DOUBLE(0.0 , MathLib::toDoubleNumber("+0E-00"), 0.000001);
ASSERT_EQUALS_DOUBLE(0.0 , MathLib::toDoubleNumber("0"), 0.000001);
ASSERT_EQUALS_DOUBLE(0.0 , MathLib::toDoubleNumber("0."), 0.000001);
ASSERT_EQUALS_DOUBLE(0.0 , MathLib::toDoubleNumber("0.0"), 0.000001);
ASSERT_EQUALS_DOUBLE(0.0 , MathLib::toDoubleNumber("-0"), 0.000001);
ASSERT_EQUALS_DOUBLE(0.0 , MathLib::toDoubleNumber("+0"), 0.000001);
ASSERT_EQUALS_DOUBLE(0.0 , MathLib::toDoubleNumber("-0."), 0.000001);
ASSERT_EQUALS_DOUBLE(0.0 , MathLib::toDoubleNumber("+0."), 0.000001);
ASSERT_EQUALS_DOUBLE(0.0 , MathLib::toDoubleNumber("-0.0"), 0.000001);
ASSERT_EQUALS_DOUBLE(0.0 , MathLib::toDoubleNumber("+0.0"), 0.000001);
ASSERT_EQUALS_DOUBLE('0' , MathLib::toDoubleNumber("'0'"), 0.000001);
// verify: string --> double --> string conversion
ASSERT_EQUALS("1.0" , MathLib::toString(MathLib::toDoubleNumber("1.0f")));

View File

@ -192,9 +192,9 @@ void TestFixture::assertEquals(const char *filename, unsigned int linenr, long l
}
}
void TestFixture::assertEqualsDouble(const char *filename, unsigned int linenr, double expected, double actual, const std::string &msg) const
void TestFixture::assertEqualsDouble(const char *filename, unsigned int linenr, double expected, double actual, double tolerance, const std::string &msg) const
{
if (expected != actual) {
if (expected < (actual - tolerance) || expected > (actual + tolerance)) {
std::ostringstream ostr1;
ostr1 << expected;
std::ostringstream ostr2;

View File

@ -55,7 +55,7 @@ protected:
void assertEquals(const char *filename, unsigned int linenr, const char expected[], const char actual[], const std::string &msg = emptyString) const;
void assertEquals(const char *filename, unsigned int linenr, const std::string& expected, const char actual[], const std::string &msg = emptyString) const;
void assertEquals(const char *filename, unsigned int linenr, long long expected, long long actual, const std::string &msg = emptyString) const;
void assertEqualsDouble(const char *filename, unsigned int linenr, double expected, double actual, const std::string &msg = emptyString) const;
void assertEqualsDouble(const char *filename, unsigned int linenr, double expected, double actual, double tolerance, const std::string &msg = emptyString) const;
void todoAssertEquals(const char *filename, unsigned int linenr, const std::string &wanted,
const std::string &current, const std::string &actual) const;
@ -87,7 +87,7 @@ extern std::ostringstream output;
#define ASSERT( CONDITION ) assert_(__FILE__, __LINE__, CONDITION)
#define ASSERT_EQUALS( EXPECTED , ACTUAL ) assertEquals(__FILE__, __LINE__, EXPECTED, ACTUAL)
#define ASSERT_EQUALS_WITHOUT_LINENUMBERS( EXPECTED , ACTUAL ) assertEqualsWithoutLineNumbers(__FILE__, __LINE__, EXPECTED, ACTUAL)
#define ASSERT_EQUALS_DOUBLE( EXPECTED , ACTUAL ) assertEqualsDouble(__FILE__, __LINE__, EXPECTED, ACTUAL)
#define ASSERT_EQUALS_DOUBLE( EXPECTED , ACTUAL, TOLERANCE ) assertEqualsDouble(__FILE__, __LINE__, EXPECTED, ACTUAL, TOLERANCE)
#define ASSERT_EQUALS_MSG( EXPECTED , ACTUAL, MSG ) assertEquals(__FILE__, __LINE__, EXPECTED, ACTUAL, MSG)
#define ASSERT_THROW( CMD, EXCEPTION ) try { CMD ; assertThrowFail(__FILE__, __LINE__); } catch (const EXCEPTION&) { } catch (...) { assertThrowFail(__FILE__, __LINE__); }
#define ASSERT_NO_THROW( CMD ) try { CMD ; } catch (...) { assertNoThrowFail(__FILE__, __LINE__); }