From 5454005d816432925d30af5ed1ffd94585166e74 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Tue, 6 Sep 2011 06:43:03 +0000 Subject: [PATCH] debug: various improvements to the test programs. --- src/debug/quad.cpp | 2 +- test/matrix.cpp | 94 +++++++++++++++++++++++----------------------- test/trig.cpp | 28 +++++++------- 3 files changed, 62 insertions(+), 62 deletions(-) diff --git a/src/debug/quad.cpp b/src/debug/quad.cpp index 91fc8e18..358b9675 100644 --- a/src/debug/quad.cpp +++ b/src/debug/quad.cpp @@ -197,7 +197,7 @@ void DebugQuad::TickDraw(float deltams) } /* Prepare our quad coordinates */ - ivec2 const layout(5, 4); + ivec2 const layout(7, 5); data->step = vec2(2.0f, -2.0f) / (4 * layout + ivec2(1)); data->orig = vec2(-1.0f, 1.0f) + data->step; data->aa = data->orig; diff --git a/test/matrix.cpp b/test/matrix.cpp index b580d435..0b49c77a 100644 --- a/test/matrix.cpp +++ b/test/matrix.cpp @@ -139,26 +139,26 @@ public: vec3 b(a1); vec2 a2(b); - CPPUNIT_ASSERT(b.x == a1.x); - CPPUNIT_ASSERT(b.y == a1.y); - CPPUNIT_ASSERT(b.z == 0.0f); + CPPUNIT_ASSERT_EQUAL(b.x, a1.x); + CPPUNIT_ASSERT_EQUAL(b.y, a1.y); + CPPUNIT_ASSERT_EQUAL(b.z, 0.0f); CPPUNIT_ASSERT(a2 == a1); vec4 c(a1); vec2 a3(c); - CPPUNIT_ASSERT(c.x == a1.x); - CPPUNIT_ASSERT(c.y == a1.y); - CPPUNIT_ASSERT(c.z == 0.0f); - CPPUNIT_ASSERT(c.w == 0.0f); + CPPUNIT_ASSERT_EQUAL(c.x, a1.x); + CPPUNIT_ASSERT_EQUAL(c.y, a1.y); + CPPUNIT_ASSERT_EQUAL(c.z, 0.0f); + CPPUNIT_ASSERT_EQUAL(c.w, 0.0f); CPPUNIT_ASSERT(a3 == a1); } void test_mat_det() { float d1 = triangular.det(); - CPPUNIT_ASSERT(d1 == 24.0f); + CPPUNIT_ASSERT_EQUAL(d1, 24.0f); float d2 = invertible.det(); - CPPUNIT_ASSERT(d2 == -1.0f); + CPPUNIT_ASSERT_EQUAL(d2, -1.0f); } void test_mat_mul() @@ -167,25 +167,25 @@ public: mat4 m1 = identity; mat4 m2 = m0 * m1; - CPPUNIT_ASSERT(m2[0][0] == 1.0f); - CPPUNIT_ASSERT(m2[1][0] == 0.0f); - CPPUNIT_ASSERT(m2[2][0] == 0.0f); - CPPUNIT_ASSERT(m2[3][0] == 0.0f); - - CPPUNIT_ASSERT(m2[0][1] == 0.0f); - CPPUNIT_ASSERT(m2[1][1] == 1.0f); - CPPUNIT_ASSERT(m2[2][1] == 0.0f); - CPPUNIT_ASSERT(m2[3][1] == 0.0f); - - CPPUNIT_ASSERT(m2[0][2] == 0.0f); - CPPUNIT_ASSERT(m2[1][2] == 0.0f); - CPPUNIT_ASSERT(m2[2][2] == 1.0f); - CPPUNIT_ASSERT(m2[3][2] == 0.0f); - - CPPUNIT_ASSERT(m2[0][3] == 0.0f); - CPPUNIT_ASSERT(m2[1][3] == 0.0f); - CPPUNIT_ASSERT(m2[2][3] == 0.0f); - CPPUNIT_ASSERT(m2[3][3] == 1.0f); + CPPUNIT_ASSERT_EQUAL(m2[0][0], 1.0f); + CPPUNIT_ASSERT_EQUAL(m2[1][0], 0.0f); + CPPUNIT_ASSERT_EQUAL(m2[2][0], 0.0f); + CPPUNIT_ASSERT_EQUAL(m2[3][0], 0.0f); + + CPPUNIT_ASSERT_EQUAL(m2[0][1], 0.0f); + CPPUNIT_ASSERT_EQUAL(m2[1][1], 1.0f); + CPPUNIT_ASSERT_EQUAL(m2[2][1], 0.0f); + CPPUNIT_ASSERT_EQUAL(m2[3][1], 0.0f); + + CPPUNIT_ASSERT_EQUAL(m2[0][2], 0.0f); + CPPUNIT_ASSERT_EQUAL(m2[1][2], 0.0f); + CPPUNIT_ASSERT_EQUAL(m2[2][2], 1.0f); + CPPUNIT_ASSERT_EQUAL(m2[3][2], 0.0f); + + CPPUNIT_ASSERT_EQUAL(m2[0][3], 0.0f); + CPPUNIT_ASSERT_EQUAL(m2[1][3], 0.0f); + CPPUNIT_ASSERT_EQUAL(m2[2][3], 0.0f); + CPPUNIT_ASSERT_EQUAL(m2[3][3], 1.0f); } void test_mat_inv() @@ -195,25 +195,25 @@ public: mat4 m2 = m0 * m1; - CPPUNIT_ASSERT(m2[0][0] == 1.0f); - CPPUNIT_ASSERT(m2[1][0] == 0.0f); - CPPUNIT_ASSERT(m2[2][0] == 0.0f); - CPPUNIT_ASSERT(m2[3][0] == 0.0f); - - CPPUNIT_ASSERT(m2[0][1] == 0.0f); - CPPUNIT_ASSERT(m2[1][1] == 1.0f); - CPPUNIT_ASSERT(m2[2][1] == 0.0f); - CPPUNIT_ASSERT(m2[3][1] == 0.0f); - - CPPUNIT_ASSERT(m2[0][2] == 0.0f); - CPPUNIT_ASSERT(m2[1][2] == 0.0f); - CPPUNIT_ASSERT(m2[2][2] == 1.0f); - CPPUNIT_ASSERT(m2[3][2] == 0.0f); - - CPPUNIT_ASSERT(m2[0][3] == 0.0f); - CPPUNIT_ASSERT(m2[1][3] == 0.0f); - CPPUNIT_ASSERT(m2[2][3] == 0.0f); - CPPUNIT_ASSERT(m2[3][3] == 1.0f); + CPPUNIT_ASSERT_EQUAL(m2[0][0], 1.0f); + CPPUNIT_ASSERT_EQUAL(m2[1][0], 0.0f); + CPPUNIT_ASSERT_EQUAL(m2[2][0], 0.0f); + CPPUNIT_ASSERT_EQUAL(m2[3][0], 0.0f); + + CPPUNIT_ASSERT_EQUAL(m2[0][1], 0.0f); + CPPUNIT_ASSERT_EQUAL(m2[1][1], 1.0f); + CPPUNIT_ASSERT_EQUAL(m2[2][1], 0.0f); + CPPUNIT_ASSERT_EQUAL(m2[3][1], 0.0f); + + CPPUNIT_ASSERT_EQUAL(m2[0][2], 0.0f); + CPPUNIT_ASSERT_EQUAL(m2[1][2], 0.0f); + CPPUNIT_ASSERT_EQUAL(m2[2][2], 1.0f); + CPPUNIT_ASSERT_EQUAL(m2[3][2], 0.0f); + + CPPUNIT_ASSERT_EQUAL(m2[0][3], 0.0f); + CPPUNIT_ASSERT_EQUAL(m2[1][3], 0.0f); + CPPUNIT_ASSERT_EQUAL(m2[2][3], 0.0f); + CPPUNIT_ASSERT_EQUAL(m2[3][3], 1.0f); } private: diff --git a/test/trig.cpp b/test/trig.cpp index 4b8254e5..31f01154 100644 --- a/test/trig.cpp +++ b/test/trig.cpp @@ -44,7 +44,7 @@ public: double f = (double)i * (1.0 / 1000.0); double a = __builtin_sin(f); double b = lol_sin(f); - CPPUNIT_ASSERT(fabs(a - b) <= fabs(f) * 1e-11); + CPPUNIT_ASSERT_DOUBLES_EQUAL(a, b, fabs(f) * 1e-11); } for (int i = -10000; i < 10000; i++) @@ -52,7 +52,7 @@ public: double f = (double)i * (1.0 / 100000.0); double a = __builtin_sin(f); double b = lol_sin(f); - CPPUNIT_ASSERT(fabs(a - b) <= fabs(f) * 1e-11); + CPPUNIT_ASSERT_DOUBLES_EQUAL(a, b, fabs(f) * 1e-11); } for (int i = -10000; i < 10000; i++) @@ -60,7 +60,7 @@ public: double f = (double)i * (1.0 / 1000.0); double a = __builtin_cos(f); double b = lol_cos(f); - CPPUNIT_ASSERT(fabs(a - b) <= fabs(f) * 1e-11); + CPPUNIT_ASSERT_DOUBLES_EQUAL(a, b, fabs(f) * 1e-11); } for (int i = -10000; i < 10000; i++) @@ -68,7 +68,7 @@ public: double f = (double)i * (1.0 / 100000.0); double a = __builtin_cos(f); double b = lol_cos(f); - CPPUNIT_ASSERT(fabs(a - b) <= fabs(f) * 1e-11); + CPPUNIT_ASSERT_DOUBLES_EQUAL(a, b, fabs(f) * 1e-11); } for (int i = -10000; i < 10000; i++) @@ -78,8 +78,8 @@ public: double a2 = __builtin_cos(f); double b1, b2; lol_sincos(f, &b1, &b2); - CPPUNIT_ASSERT(fabs(a1 - b1) <= fabs(f) * 1e-11); - CPPUNIT_ASSERT(fabs(a2 - b2) <= fabs(f) * 1e-11); + CPPUNIT_ASSERT_DOUBLES_EQUAL(a1, b1, fabs(f) * 1e-11); + CPPUNIT_ASSERT_DOUBLES_EQUAL(a2, b2, fabs(f) * 1e-11); } for (int i = -10000; i < 10000; i++) @@ -89,8 +89,8 @@ public: double a2 = __builtin_cos(f); double b1, b2; lol_sincos(f, &b1, &b2); - CPPUNIT_ASSERT(fabs(a1 - b1) <= fabs(f) * 1e-11); - CPPUNIT_ASSERT(fabs(a2 - b2) <= fabs(f) * 1e-11); + CPPUNIT_ASSERT_DOUBLES_EQUAL(a1, b1, fabs(f) * 1e-11); + CPPUNIT_ASSERT_DOUBLES_EQUAL(a2, b2, fabs(f) * 1e-11); } for (int i = -100000; i < 100000; i++) @@ -99,11 +99,11 @@ public: double a = __builtin_tan(f); double b = lol_tan(f); if (fabs(a) > 1e4) - CPPUNIT_ASSERT(fabs(a - b) <= fabs(a) * fabs(a) * 1e-11); + CPPUNIT_ASSERT_DOUBLES_EQUAL(a, b, fabs(a) * fabs(a) * 1e-11); else if (fabs(a) > 1.0) - CPPUNIT_ASSERT(fabs(a - b) <= fabs(a) * 1e-11); + CPPUNIT_ASSERT_DOUBLES_EQUAL(a, b, fabs(a) * 1e-11); else - CPPUNIT_ASSERT(fabs(a - b) <= fabs(f) * 1e-11); + CPPUNIT_ASSERT_DOUBLES_EQUAL(a, b, fabs(f) * 1e-11); } for (int i = -10000; i < 10000; i++) @@ -112,11 +112,11 @@ public: double a = __builtin_tan(f); double b = lol_tan(f); if (fabs(a) > 1e4) - CPPUNIT_ASSERT(fabs(a - b) <= fabs(a) * fabs(a) * 1e-11); + CPPUNIT_ASSERT_DOUBLES_EQUAL(a, b, fabs(a) * fabs(a) * 1e-11); else if (fabs(a) > 1.0) - CPPUNIT_ASSERT(fabs(a - b) <= fabs(a) * 1e-11); + CPPUNIT_ASSERT_DOUBLES_EQUAL(a, b, fabs(a) * 1e-11); else - CPPUNIT_ASSERT(fabs(a - b) <= fabs(f) * 1e-11); + CPPUNIT_ASSERT_DOUBLES_EQUAL(a, b, fabs(f) * 1e-11); } } };