diff options
author | RJ Ryan <rryan@mixxx.org> | 2015-12-10 10:50:47 -0800 |
---|---|---|
committer | RJ Ryan <rryan@mixxx.org> | 2015-12-10 10:50:47 -0800 |
commit | a45e66ac9b501f4e2190d9f9f07bf7cc23328464 (patch) | |
tree | c522e65e95ed84b1562d39ec483b490a31d3bd49 /src | |
parent | d02cc729aa3bf5295e0b5cecc11939043dd860e6 (diff) |
Add tests for isinf, isnan and denormal detection.
Diffstat (limited to 'src')
-rw-r--r-- | src/test/mathutiltest.cpp | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/src/test/mathutiltest.cpp b/src/test/mathutiltest.cpp index 847472671e..27854b434b 100644 --- a/src/test/mathutiltest.cpp +++ b/src/test/mathutiltest.cpp @@ -1,8 +1,10 @@ -#include <gtest/gtest.h> -#include "util/math.h" +#include <limits> +#include <gtest/gtest.h> #include <QtDebug> +#include "util/math.h" + namespace { class MathUtilTest : public testing::Test { @@ -28,7 +30,7 @@ const int MathUtilTest::MIN = -10; const int MathUtilTest::MAX = 10; const int MathUtilTest::VALUE_MIN = 2 * MathUtilTest::MIN; -const int MathUtilTest::VALUE_MAX = 2 * MathUtilTest::MAX; +const int MathUtilTest::VALUE_MAX = 2 * MathUtilTest::MAX; TEST_F(MathUtilTest, MathClampUnsafe) { for (int i = VALUE_MIN; i <= VALUE_MAX; ++i) { @@ -45,4 +47,33 @@ TEST_F(MathUtilTest, MathClampUnsafe) { } } +TEST_F(MathUtilTest, IsNaN) { + // Test floats can be recognized as nan. + EXPECT_FALSE(isnan(0.0f)); + EXPECT_TRUE(isnan(std::numeric_limits<float>::quiet_NaN())); + + // Test doubles can be recognized as nan. + EXPECT_FALSE(isnan(0.0)); + EXPECT_TRUE(isnan(std::numeric_limits<double>::quiet_NaN())); +} + +TEST_F(MathUtilTest, IsInf) { + // Test floats can be recognized as infinity. + EXPECT_FALSE(isinf(0.0f)); + EXPECT_TRUE(isinf(std::numeric_limits<float>::infinity())); + + // Test doubles can be recognized as infinity. + EXPECT_FALSE(isinf(0.0f)); + EXPECT_TRUE(isinf(std::numeric_limits<double>::infinity())); +} + +TEST_F(MathUtilTest, Denormal) { + float fDenormal = std::numeric_limits<float>::min() / 2.0f; + EXPECT_TRUE(std::fpclassify(fDenormal) == FP_SUBNORMAL); + + double dDenormal = std::numeric_limits<double>::min() / 2.0; + EXPECT_TRUE(std::fpclassify(dDenormal) == FP_SUBNORMAL); +} + + } // namespace |