diff options
author | Mike Reed <reed@google.com> | 2010-02-09 14:55:53 -0500 |
---|---|---|
committer | Mike Reed <reed@google.com> | 2010-02-09 14:55:53 -0500 |
commit | 1c980e0d7772f05f570ae0227d91635f017c2227 (patch) | |
tree | c47945284d58b01dd5aeb744bb11a2c90489fec1 /tests | |
parent | 0d8b9985975678c153f5d04c076c8d9c0315f277 (diff) | |
download | external_skia-1c980e0d7772f05f570ae0227d91635f017c2227.zip external_skia-1c980e0d7772f05f570ae0227d91635f017c2227.tar.gz external_skia-1c980e0d7772f05f570ae0227d91635f017c2227.tar.bz2 |
refresh from skia/trunk
Diffstat (limited to 'tests')
-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 09e3748..dec93de 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; |