aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/MathTest.cpp
diff options
context:
space:
mode:
authorGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-09-26 19:22:54 +0000
committerGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-09-26 19:22:54 +0000
commit2c86fbb0b14a1f674bf56ea5ad6a086cc004a76e (patch)
tree39c7755bf8736c85ae8c3d35d8e4c273140932b1 /tests/MathTest.cpp
parent52753b93518d2ad3322c2807799eacb869e9f9d9 (diff)
Add SkDivMod with a special case for ARM.
BUG=skia:1663 R=djsollen@google.com, tomhudson@google.com, reed@google.com Author: mtklein@google.com Review URL: https://chromiumcodereview.appspot.com/24159009 git-svn-id: http://skia.googlecode.com/svn/trunk@11482 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tests/MathTest.cpp')
-rw-r--r--tests/MathTest.cpp71
1 files changed, 71 insertions, 0 deletions
diff --git a/tests/MathTest.cpp b/tests/MathTest.cpp
index cb4d0b8bd2..bc8e6a32de 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);
+}