aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/SkFixed15Test.cpp
diff options
context:
space:
mode:
authorGravatar Mike Klein <mtklein@chromium.org>2016-10-31 09:20:54 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2016-10-31 13:41:39 +0000
commitd280d425bd541ebbb3a5e9045913eabb3f85f04b (patch)
treebe55c6adcc9e2a1362e01ee503750ff2c26dfd14 /tests/SkFixed15Test.cpp
parent70295ea220e25ede0f967ad0168c51a8e3fd444d (diff)
SkFixed15
BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=3981 Change-Id: I811b22004e8e2d5b7135f574caea296ffdff7011 Reviewed-on: https://skia-review.googlesource.com/3981 Reviewed-by: Mike Reed <reed@google.com> Commit-Queue: Mike Klein <mtklein@chromium.org>
Diffstat (limited to 'tests/SkFixed15Test.cpp')
-rw-r--r--tests/SkFixed15Test.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/SkFixed15Test.cpp b/tests/SkFixed15Test.cpp
new file mode 100644
index 0000000000..e2108d5604
--- /dev/null
+++ b/tests/SkFixed15Test.cpp
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2016 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "Test.h"
+#include "SkFixed15.h"
+
+DEF_TEST(SkFixed15, r) {
+ // For all v, v*0 == 0, v*1 == v.
+ for (uint16_t bits = 0; bits <= 32768; bits++) {
+ auto v = SkFixed15::Load(bits);
+ REPORTER_ASSERT(r, v * 0.0f == 0.0f);
+ REPORTER_ASSERT(r, v * 1.0f == v);
+ }
+
+ // Division and multiplication by powers of 2 is exact.
+ SkFixed15 v = 1.0f;
+ REPORTER_ASSERT(r, (v>>1) == 0.50f);
+ REPORTER_ASSERT(r, (v>>2) == 0.25f);
+ REPORTER_ASSERT(r, (v>>2<<1) == 0.50f);
+
+ // FromU8() should be just as good as going through float.
+ for (int x = 0; x < 256; x++) {
+ REPORTER_ASSERT(r, SkFixed15::FromU8(x) == SkFixed15(x * (1/255.0f)));
+ }
+}