aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/MathTest.cpp
diff options
context:
space:
mode:
authorGravatar Mike Reed <reed@google.com>2017-10-10 14:49:35 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-10-10 19:58:13 +0000
commite07622386b10c158cb0cc653ace264e24c5702af (patch)
tree07210d6ddd3ad14e7a66197261ad911d7f3cea80 /tests/MathTest.cpp
parent57a0edf7ba03082e649f0c2ddc43930dfa849e7f (diff)
clone saturating cast code for doubles
Bug: skia: Change-Id: I4f35413995cf73c6f130476d6b36e530120aa7ed Reviewed-on: https://skia-review.googlesource.com/57901 Reviewed-by: Mike Klein <mtklein@google.com> Commit-Queue: Mike Reed <reed@google.com>
Diffstat (limited to 'tests/MathTest.cpp')
-rw-r--r--tests/MathTest.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/MathTest.cpp b/tests/MathTest.cpp
index fcbd63ddca..0d0bdce67d 100644
--- a/tests/MathTest.cpp
+++ b/tests/MathTest.cpp
@@ -693,3 +693,27 @@ DEF_TEST(FloatSaturate, reporter) {
REPORTER_ASSERT(reporter, r.fExpectedInt == i);
}
}
+
+DEF_TEST(DoubleSaturate, reporter) {
+ const struct {
+ double fDouble;
+ int fExpectedInt;
+ } recs[] = {
+ { 0, 0 },
+ { 100.5, 100 },
+ { SK_MaxS32, SK_MaxS32 },
+ { SK_MinS32, SK_MinS32 },
+ { SK_MaxS32 - 1, SK_MaxS32 - 1 },
+ { SK_MinS32 + 1, SK_MinS32 + 1 },
+ { SK_MaxS32 * 100.0, SK_MaxS32 },
+ { SK_MinS32 * 100.0, SK_MinS32 },
+ { SK_ScalarInfinity, SK_MaxS32 },
+ { SK_ScalarNegativeInfinity, SK_MinS32 },
+ { SK_ScalarNaN, SK_MaxS32 },
+ };
+
+ for (auto r : recs) {
+ int i = sk_double_saturate2int(r.fDouble);
+ REPORTER_ASSERT(reporter, r.fExpectedInt == i);
+ }
+}