From 3ff4d07c401d856fdf592603c211a43470deba50 Mon Sep 17 00:00:00 2001 From: David Adam Date: Tue, 15 Dec 2009 09:59:13 +0100 Subject: [PATCH] d3dx9/tests: Check a relative error instead of an absolute error. --- dlls/d3dx9_36/tests/math.c | 107 +++++++++++++++++++------------------ 1 file changed, 54 insertions(+), 53 deletions(-) diff --git a/dlls/d3dx9_36/tests/math.c b/dlls/d3dx9_36/tests/math.c index 60d71939f3..4eb7bcb610 100644 --- a/dlls/d3dx9_36/tests/math.c +++ b/dlls/d3dx9_36/tests/math.c @@ -26,9 +26,9 @@ #define admitted_error 0.0001f -#define relative_error(exp, out) ((exp == out) ? 0.0f : (fabs(out - exp) / fabs(exp))) +#define relative_error(exp, out) ((exp == 0.0f) ? fabs(exp - out) : (fabs(1 - out/ exp) )) -#define expect_color(expectedcolor,gotcolor) ok((fabs(expectedcolor.r-gotcolor.r) admitted_error) + if (relative_error(U(*m1).m[i][j], U(*m2).m[i][j]) > admitted_error) return FALSE; } } @@ -63,26 +63,26 @@ do { \ } while(0) #define compare_rotation(exp, got) \ - ok(fabs(exp.w - got.w) < admitted_error && \ - fabs(exp.x - got.x) < admitted_error && \ - fabs(exp.y - got.y) < admitted_error && \ - fabs(exp.z - got.z) < admitted_error, \ + ok(relative_error(exp.w, got.w) < admitted_error && \ + relative_error(exp.x, got.x) < admitted_error && \ + relative_error(exp.y, got.y) < admitted_error && \ + relative_error(exp.z, got.z) < admitted_error, \ "Expected rotation = (%f, %f, %f, %f), \ got rotation = (%f, %f, %f, %f)\n", \ exp.w, exp.x, exp.y, exp.z, got.w, got.x, got.y, got.z) #define compare_scale(exp, got) \ - ok(fabs(exp.x - got.x) < admitted_error && \ - fabs(exp.y - got.y) < admitted_error && \ - fabs(exp.z - got.z) < admitted_error, \ + ok(relative_error(exp.x, got.x) < admitted_error && \ + relative_error(exp.y, got.y) < admitted_error && \ + relative_error(exp.z, got.z) < admitted_error, \ "Expected scale = (%f, %f, %f), \ got scale = (%f, %f, %f)\n", \ exp.x, exp.y, exp.z, got.x, got.y, got.z) #define compare_translation(exp, got) \ - ok(fabs(exp.x - got.x) < admitted_error && \ - fabs(exp.y - got.y) < admitted_error && \ - fabs(exp.z - got.z) < admitted_error, \ + ok(relative_error(exp.x, got.x) < admitted_error && \ + relative_error(exp.y, got.y) < admitted_error && \ + relative_error(exp.z, got.z) < admitted_error, \ "Expected translation = (%f, %f, %f), \ got translation = (%f, %f, %f)\n", \ exp.x, exp.y, exp.z, got.x, got.y, got.z) @@ -110,13 +110,14 @@ do { \ exp[i].a, exp[i].b, exp[i].c, exp[i].d, \ i); \ } -#define expect_plane(expectedplane,gotplane) ok((fabs(expectedplane.a-gotplane.a)1.0f */ expectedvec.x = 1.0f; expectedvec.y = 2.0f; expectedvec.z = 4.0f; expected = 0.0f; @@ -947,7 +948,7 @@ static void D3DXQuaternionTest(void) expected = 3.141593f; D3DXQuaternionToAxisAngle(&nul,&axis,&angle); expect_vec3(expectedvec,axis); - ok(fabs( angle - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, angle); + ok(relative_error(angle, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, angle); } static void D3DXVector2Test(void) @@ -995,26 +996,26 @@ static void D3DXVector2Test(void) /*_______________D3DXVec2CCW__________________________*/ expected = 55.0f; got = D3DXVec2CCW(&u,&v); - ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); + ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); /* Tests the case NULL */ expected=0.0f; got = D3DXVec2CCW(NULL,&v); - ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); + ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); expected=0.0f; got = D3DXVec2CCW(NULL,NULL); - ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); + ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); /*_______________D3DXVec2Dot__________________________*/ expected = 15.0f; got = D3DXVec2Dot(&u,&v); - ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); + ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); /* Tests the case NULL */ expected=0.0f; got = D3DXVec2Dot(NULL,&v); - ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); + ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); expected=0.0f; got = D3DXVec2Dot(NULL,NULL); - ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); + ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); /*_______________D3DXVec2Hermite__________________________*/ expectedvec.x = 2604.625f; expectedvec.y = -4533.0f; @@ -1024,20 +1025,20 @@ static void D3DXVector2Test(void) /*_______________D3DXVec2Length__________________________*/ expected = 5.0f; got = D3DXVec2Length(&u); - ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); + ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); /* Tests the case NULL */ expected=0.0f; got = D3DXVec2Length(NULL); - ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); + ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); /*_______________D3DXVec2LengthSq________________________*/ expected = 25.0f; got = D3DXVec2LengthSq(&u); - ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); + ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); /* Tests the case NULL */ expected=0.0f; got = D3DXVec2LengthSq(NULL); - ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); + ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); /*_______________D3DXVec2Lerp__________________________*/ expectedvec.x = 68.0f; expectedvec.y = -28.5f; @@ -1186,14 +1187,14 @@ static void D3DXVector3Test(void) /*_______________D3DXVec3Dot__________________________*/ expected = -8.0f; got = D3DXVec3Dot(&u,&v); - ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); + ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); /* Tests the case NULL */ expected=0.0f; got = D3DXVec3Dot(NULL,&v); - ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); + ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); expected=0.0f; got = D3DXVec3Dot(NULL,NULL); - ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); + ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); /*_______________D3DXVec3Hermite__________________________*/ expectedvec.x = -6045.75f; expectedvec.y = -6650.0f; expectedvec.z = 1358.875f; @@ -1203,20 +1204,20 @@ static void D3DXVector3Test(void) /*_______________D3DXVec3Length__________________________*/ expected = 11.0f; got = D3DXVec3Length(&u); - ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); + ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); /* Tests the case NULL */ expected=0.0f; got = D3DXVec3Length(NULL); - ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); + ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); /*_______________D3DXVec3LengthSq________________________*/ expected = 121.0f; got = D3DXVec3LengthSq(&u); - ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); + ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); /* Tests the case NULL */ expected=0.0f; got = D3DXVec3LengthSq(NULL); - ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); + ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); /*_______________D3DXVec3Lerp__________________________*/ expectedvec.x = 54.5f; expectedvec.y = 64.5f, expectedvec.z = 41.0f ; @@ -1355,14 +1356,14 @@ static void D3DXVector4Test(void) /*_______________D3DXVec4Dot__________________________*/ expected = 55.0f; got = D3DXVec4Dot(&u,&v); - ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); + ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); /* Tests the case NULL */ expected=0.0f; got = D3DXVec4Dot(NULL,&v); - ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); + ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); expected=0.0f; got = D3DXVec4Dot(NULL,NULL); - ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); + ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); /*_______________D3DXVec4Hermite_________________________*/ expectedvec.x = 1224.625f; expectedvec.y = 3461.625f; expectedvec.z = -4758.875f; expectedvec.w = -5781.5f; @@ -1372,20 +1373,20 @@ static void D3DXVector4Test(void) /*_______________D3DXVec4Length__________________________*/ expected = 11.0f; got = D3DXVec4Length(&u); - ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); + ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); /* Tests the case NULL */ expected=0.0f; got = D3DXVec4Length(NULL); - ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); + ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); /*_______________D3DXVec4LengthSq________________________*/ expected = 121.0f; got = D3DXVec4LengthSq(&u); - ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); + ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); /* Tests the case NULL */ expected=0.0f; got = D3DXVec4LengthSq(NULL); - ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); + ok(relative_error(got, expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); /*_______________D3DXVec4Lerp__________________________*/ expectedvec.x = 27.0f; expectedvec.y = -11.0f; expectedvec.z = 62.5; expectedvec.w = 29.5;