| 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 + d, 6, 9)); | |
| 45 REPORTER_ASSERT(r, eq(a - d, 2, -1)); | |
| 46 REPORTER_ASSERT(r, eq(a * d, 8, 20)); | |
| 47 REPORTER_ASSERT(r, eq(a / d, 2, 0.8)); | |
| 48 | |
| 49 REPORTER_ASSERT(r, nearly_eq(0.001, a.rsqrt(), 0.5, 0.5)); | |
| 50 REPORTER_ASSERT(r, eq(a.sqrt(), 2, 2)); | |
| 51 | |
| 52 REPORTER_ASSERT(r, nearly_eq(0.001, d.approxInvert(), 0.5, 0.2)); | |
| 53 REPORTER_ASSERT(r, eq(d.invert(), 0.5, 0.2)); | |
| 54 | |
| 55 REPORTER_ASSERT(r, eq(Sk2x<T>::Min(a, d), 2, 4)); | |
| 56 REPORTER_ASSERT(r, eq(Sk2x<T>::Max(a, d), 4, 5)); | |
| 57 | |
| 58 REPORTER_ASSERT(r, eq(-d, -2, -5)); | |
| 59 | |
| 60 // A bit of both. | |
| 61 a += d; | |
| 62 a *= d; | |
| 63 a -= d; | |
| 64 REPORTER_ASSERT(r, eq(a, 10, 40)); | |
| 65 } | |
| 66 | |
| 67 DEF_TEST(Sk2f, r) { test< float>(r); } | |
| 68 DEF_TEST(Sk2d, r) { test<double>(r); } | |
| OLD | NEW |