Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(272)

Unified Diff: tests/MathTest.cpp

Issue 13934010: fix asserts in SkMulDiv255Round, and add test (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/core/SkMath.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/MathTest.cpp
===================================================================
--- tests/MathTest.cpp (revision 8804)
+++ tests/MathTest.cpp (working copy)
@@ -48,6 +48,32 @@
///////////////////////////////////////////////////////////////////////////////
+// test that SkMul16ShiftRound and SkMulDiv255Round return the same result
+static void test_muldivround(skiatest::Reporter* reporter) {
+#if 0
+ // this "complete" test is too slow, so we test a random sampling of it
+
+ for (int a = 0; a <= 32767; ++a) {
+ for (int b = 0; b <= 32767; ++b) {
+ unsigned prod0 = SkMul16ShiftRound(a, b, 8);
+ unsigned prod1 = SkMulDiv255Round(a, b);
+ SkASSERT(prod0 == prod1);
+ }
+ }
+#endif
+
+ SkRandom rand;
+ for (int i = 0; i < 10000; ++i) {
+ unsigned a = rand.nextU() & 0x7FFF;
+ unsigned b = rand.nextU() & 0x7FFF;
+
+ unsigned prod0 = SkMul16ShiftRound(a, b, 8);
+ unsigned prod1 = SkMulDiv255Round(a, b);
+
+ REPORTER_ASSERT(reporter, prod0 == prod1);
+ }
+}
+
static float float_blend(int src, int dst, float unit) {
return dst + (src - dst) * unit;
}
@@ -595,6 +621,8 @@
// disable for now
if (false) test_blend31(); // avoid bit rot, suppress warning
+
+ test_muldivround(reporter);
}
#include "TestClassDef.h"
« no previous file with comments | « include/core/SkMath.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698