OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2015 Google Inc. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. |
| 6 */ |
| 7 |
| 8 #include "Test.h" |
| 9 #include "Sk2x.h" |
| 10 |
| 11 template <typename T> |
| 12 static bool nearly_eq(double eps, const Sk2x<T>& v, double x, double y) { |
| 13 T vals[2]; |
| 14 v.store(vals); |
| 15 return fabs(vals[0] - (T)x) <= eps && fabs(vals[1] - (T)y) <= eps; |
| 16 } |
| 17 |
| 18 template <typename T> |
| 19 static bool eq(const Sk2x<T>& v, double x, double y) { return nearly_eq(0, v, x,
y); } |
| 20 |
| 21 template <typename T> |
| 22 static void test(skiatest::Reporter* r) { |
| 23 // Constructors, assignment, etc. |
| 24 Sk2x<T> a(4), |
| 25 b = a, |
| 26 c(a); |
| 27 REPORTER_ASSERT(r, eq(a, 4, 4)); |
| 28 REPORTER_ASSERT(r, eq(b, 4, 4)); |
| 29 REPORTER_ASSERT(r, eq(c, 4, 4)); |
| 30 |
| 31 Sk2x<T> d(2, 5); |
| 32 Sk2x<T> e; |
| 33 e = d; |
| 34 T vals[] = { 2, 5 }; |
| 35 Sk2x<T> f = Sk2x<T>::Load(vals); |
| 36 REPORTER_ASSERT(r, eq(d, 2, 5)); |
| 37 REPORTER_ASSERT(r, eq(e, 2, 5)); |
| 38 REPORTER_ASSERT(r, eq(f, 2, 5)); |
| 39 |
| 40 a.store(vals); |
| 41 REPORTER_ASSERT(r, vals[0] == 4 && vals[1] == 4); |
| 42 |
| 43 // Math |
| 44 REPORTER_ASSERT(r, eq(a.add(d), 6, 9)); |
| 45 REPORTER_ASSERT(r, eq(a.subtract(d), 2, -1)); |
| 46 REPORTER_ASSERT(r, eq(a.multiply(d), 8, 20)); |
| 47 |
| 48 REPORTER_ASSERT(r, nearly_eq(0.001, a.rsqrt(), 0.5, 0.5)); |
| 49 REPORTER_ASSERT(r, eq(a.sqrt(), 2, 2)); |
| 50 |
| 51 REPORTER_ASSERT(r, eq(Sk2x<T>::Min(a, d), 2, 4)); |
| 52 REPORTER_ASSERT(r, eq(Sk2x<T>::Max(a, d), 4, 5)); |
| 53 } |
| 54 |
| 55 DEF_TEST(Sk2f, r) { test< float>(r); } |
| 56 DEF_TEST(Sk2d, r) { test<double>(r); } |
OLD | NEW |