diff options
author | reed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2010-02-09 19:18:38 +0000 |
---|---|---|
committer | reed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2010-02-09 19:18:38 +0000 |
commit | f0ad0864af632736819b9f3f34dbba488c73e3af (patch) | |
tree | 986a8e94aa8a825ff3286a26f27581d7bf2cf636 /tests/MathTest.cpp | |
parent | eebf5cb6c0f5ed2630de2e7712d61b4ec1d49015 (diff) |
add unittest for copysign
git-svn-id: http://skia.googlecode.com/svn/trunk@496 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tests/MathTest.cpp')
-rw-r--r-- | tests/MathTest.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/MathTest.cpp b/tests/MathTest.cpp index 09e3748860..dec93dea1d 100644 --- a/tests/MathTest.cpp +++ b/tests/MathTest.cpp @@ -170,6 +170,46 @@ static void test_muldiv255(skiatest::Reporter* reporter) { #endif } +static void test_copysign(skiatest::Reporter* reporter) { + static const int32_t gTriples[] = { + // x, y, expected result + 0, 0, 0, + 0, 1, 0, + 0, -1, 0, + 1, 0, 1, + 1, 1, 1, + 1, -1, -1, + -1, 0, 1, + -1, 1, 1, + -1, -1, -1, + }; + for (size_t i = 0; i < SK_ARRAY_COUNT(gTriples); i += 3) { + REPORTER_ASSERT(reporter, + SkCopySign32(gTriples[i], gTriples[i+1]) == gTriples[i+2]); +#ifdef SK_CAN_USE_FLOAT + float x = (float)gTriples[i]; + float y = (float)gTriples[i+1]; + float expected = (float)gTriples[i+2]; + REPORTER_ASSERT(reporter, sk_float_copysign(x, y) == expected); +#endif + } + + SkRandom rand; + for (int j = 0; j < 1000; j++) { + int ix = rand.nextS(); + REPORTER_ASSERT(reporter, SkCopySign32(ix, ix) == ix); + REPORTER_ASSERT(reporter, SkCopySign32(ix, -ix) == -ix); + REPORTER_ASSERT(reporter, SkCopySign32(-ix, ix) == ix); + REPORTER_ASSERT(reporter, SkCopySign32(-ix, -ix) == -ix); + + SkScalar sx = rand.nextSScalar1(); + REPORTER_ASSERT(reporter, SkScalarCopySign(sx, sx) == sx); + REPORTER_ASSERT(reporter, SkScalarCopySign(sx, -sx) == -sx); + REPORTER_ASSERT(reporter, SkScalarCopySign(-sx, sx) == sx); + REPORTER_ASSERT(reporter, SkScalarCopySign(-sx, -sx) == -sx); + } +} + static void TestMath(skiatest::Reporter* reporter) { int i; int32_t x; @@ -196,6 +236,7 @@ static void TestMath(skiatest::Reporter* reporter) { #endif test_muldiv255(reporter); + test_copysign(reporter); { SkScalar x = SK_ScalarNaN; |