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

Unified Diff: tests/MathTest.cpp

Issue 24159009: Add SkDivMod with a special case for ARM. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: appease gcc on 10.6 Created 7 years, 3 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 | « src/core/SkScaledImageCache.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/MathTest.cpp
diff --git a/tests/MathTest.cpp b/tests/MathTest.cpp
index cb4d0b8bd2e8f281ad905eff5961004ab9f391a9..bc8e6a32de886ff16a13d1589bf207b86603da1a 100644
--- a/tests/MathTest.cpp
+++ b/tests/MathTest.cpp
@@ -691,3 +691,74 @@ static void TestEndian(skiatest::Reporter* reporter) {
}
DEFINE_TESTCLASS("Endian", EndianTestClass, TestEndian)
+
+template <typename T>
+static void test_divmod(skiatest::Reporter* r) {
+ const struct {
+ T numer;
+ T denom;
+ } kEdgeCases[] = {
+ {(T)17, (T)17},
+ {(T)17, (T)4},
+ {(T)0, (T)17},
+ // For unsigned T these negatives are just some large numbers. Doesn't hurt to test them.
+ {(T)-17, (T)-17},
+ {(T)-17, (T)4},
+ {(T)17, (T)-4},
+ {(T)-17, (T)-4},
+ };
+
+ for (size_t i = 0; i < SK_ARRAY_COUNT(kEdgeCases); i++) {
+ const T numer = kEdgeCases[i].numer;
+ const T denom = kEdgeCases[i].denom;
+ T div, mod;
+ SkTDivMod(numer, denom, &div, &mod);
+ REPORTER_ASSERT(r, numer/denom == div);
+ REPORTER_ASSERT(r, numer%denom == mod);
+ }
+
+ SkRandom rand;
+ for (size_t i = 0; i < 10000; i++) {
+ const T numer = (T)rand.nextS();
+ T denom = 0;
+ while (0 == denom) {
+ denom = (T)rand.nextS();
+ }
+ T div, mod;
+ SkTDivMod(numer, denom, &div, &mod);
+ REPORTER_ASSERT(r, numer/denom == div);
+ REPORTER_ASSERT(r, numer%denom == mod);
+ }
+}
+
+DEF_TEST(divmod_u8, r) {
+ test_divmod<uint8_t>(r);
+}
+
+DEF_TEST(divmod_u16, r) {
+ test_divmod<uint16_t>(r);
+}
+
+DEF_TEST(divmod_u32, r) {
+ test_divmod<uint32_t>(r);
+}
+
+DEF_TEST(divmod_u64, r) {
+ test_divmod<uint64_t>(r);
+}
+
+DEF_TEST(divmod_s8, r) {
+ test_divmod<int8_t>(r);
+}
+
+DEF_TEST(divmod_s16, r) {
+ test_divmod<int16_t>(r);
+}
+
+DEF_TEST(divmod_s32, r) {
+ test_divmod<int32_t>(r);
+}
+
+DEF_TEST(divmod_s64, r) {
+ test_divmod<int64_t>(r);
+}
« no previous file with comments | « src/core/SkScaledImageCache.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698