OLD | NEW |
1 #include "Test.h" | 1 #include "Test.h" |
2 #include "Sk4x.h" | 2 #include "Sk4x.h" |
3 | 3 |
4 #define ASSERT_EQ(a, b) REPORTER_ASSERT(r, a.equal(b).allTrue()) | 4 #define ASSERT_EQ(a, b) REPORTER_ASSERT(r, a.equal(b).allTrue()) |
5 #define ASSERT_NE(a, b) REPORTER_ASSERT(r, a.notEqual(b).allTrue()) | 5 #define ASSERT_NE(a, b) REPORTER_ASSERT(r, a.notEqual(b).allTrue()) |
6 | 6 |
7 DEF_TEST(Sk4x_Construction, r) { | 7 DEF_TEST(Sk4x_Construction, r) { |
8 Sk4f uninitialized; | 8 Sk4f uninitialized; |
9 Sk4f zero(0,0,0,0); | 9 Sk4f zero(0,0,0,0); |
10 Sk4f foo(1,2,3,4), | 10 Sk4f foo(1,2,3,4), |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 | 80 |
81 ASSERT_EQ(Sk4i(4,6,8,10), Sk4i(1,2,3,4).add(Sk4i(3,4,5,6))); | 81 ASSERT_EQ(Sk4i(4,6,8,10), Sk4i(1,2,3,4).add(Sk4i(3,4,5,6))); |
82 ASSERT_EQ(Sk4i(-2,-2,-2,-2), Sk4i(1,2,3,4).subtract(Sk4i(3,4,5,6))); | 82 ASSERT_EQ(Sk4i(-2,-2,-2,-2), Sk4i(1,2,3,4).subtract(Sk4i(3,4,5,6))); |
83 ASSERT_EQ(Sk4i(3,8,15,24), Sk4i(1,2,3,4).multiply(Sk4i(3,4,5,6))); | 83 ASSERT_EQ(Sk4i(3,8,15,24), Sk4i(1,2,3,4).multiply(Sk4i(3,4,5,6))); |
84 } | 84 } |
85 | 85 |
86 DEF_TEST(Sk4x_ImplicitPromotion, r) { | 86 DEF_TEST(Sk4x_ImplicitPromotion, r) { |
87 ASSERT_EQ(Sk4f(2,4,6,8), Sk4f(1,2,3,4).multiply(2.0f)); | 87 ASSERT_EQ(Sk4f(2,4,6,8), Sk4f(1,2,3,4).multiply(2.0f)); |
88 } | 88 } |
89 | 89 |
| 90 DEF_TEST(Sk4x_Sqrt, r) { |
| 91 Sk4f squares(4, 16, 25, 121), |
| 92 roots(2, 4, 5, 11); |
| 93 // .sqrt() should be pretty precise. |
| 94 ASSERT_EQ(roots, squares.sqrt()); |
| 95 |
| 96 // .rsqrt() isn't so precise, but should be pretty close. |
| 97 Sk4f error = roots.subtract(squares.multiply(squares.rsqrt())); |
| 98 REPORTER_ASSERT(r, error.greaterThan(0.0f).allTrue()); |
| 99 REPORTER_ASSERT(r, error.lessThan(0.01f).allTrue()); |
| 100 } |
| 101 |
90 DEF_TEST(Sk4x_Comparison, r) { | 102 DEF_TEST(Sk4x_Comparison, r) { |
91 ASSERT_EQ(Sk4f(1,2,3,4), Sk4f(1,2,3,4)); | 103 ASSERT_EQ(Sk4f(1,2,3,4), Sk4f(1,2,3,4)); |
92 ASSERT_NE(Sk4f(4,3,2,1), Sk4f(1,2,3,4)); | 104 ASSERT_NE(Sk4f(4,3,2,1), Sk4f(1,2,3,4)); |
93 | 105 |
94 ASSERT_EQ(Sk4i(-1,-1,0,-1), Sk4f(1,2,5,4).equal(Sk4f(1,2,3,4))); | 106 ASSERT_EQ(Sk4i(-1,-1,0,-1), Sk4f(1,2,5,4).equal(Sk4f(1,2,3,4))); |
95 | 107 |
96 ASSERT_EQ(Sk4i(-1,-1,-1,-1), Sk4f(1,2,3,4).lessThan(Sk4f(2,3,4,5))); | 108 ASSERT_EQ(Sk4i(-1,-1,-1,-1), Sk4f(1,2,3,4).lessThan(Sk4f(2,3,4,5))); |
97 ASSERT_EQ(Sk4i(-1,-1,-1,-1), Sk4f(1,2,3,4).lessThanEqual(Sk4f(2,3,4,5))); | 109 ASSERT_EQ(Sk4i(-1,-1,-1,-1), Sk4f(1,2,3,4).lessThanEqual(Sk4f(2,3,4,5))); |
98 ASSERT_EQ(Sk4i(0,0,0,0), Sk4f(1,2,3,4).greaterThan(Sk4f(2,3,4,5))); | 110 ASSERT_EQ(Sk4i(0,0,0,0), Sk4f(1,2,3,4).greaterThan(Sk4f(2,3,4,5))); |
99 ASSERT_EQ(Sk4i(0,0,0,0), Sk4f(1,2,3,4).greaterThanEqual(Sk4f(2,3,4,5))); | 111 ASSERT_EQ(Sk4i(0,0,0,0), Sk4f(1,2,3,4).greaterThanEqual(Sk4f(2,3,4,5))); |
(...skipping 17 matching lines...) Expand all Loading... |
117 } | 129 } |
118 | 130 |
119 DEF_TEST(Sk4x_Swizzle, r) { | 131 DEF_TEST(Sk4x_Swizzle, r) { |
120 ASSERT_EQ(Sk4f(3,4,1,2), Sk4f(1,2,3,4).zwxy()); | 132 ASSERT_EQ(Sk4f(3,4,1,2), Sk4f(1,2,3,4).zwxy()); |
121 ASSERT_EQ(Sk4f(1,2,5,6), Sk4f::XYAB(Sk4f(1,2,3,4), Sk4f(5,6,7,8))); | 133 ASSERT_EQ(Sk4f(1,2,5,6), Sk4f::XYAB(Sk4f(1,2,3,4), Sk4f(5,6,7,8))); |
122 ASSERT_EQ(Sk4f(3,4,7,8), Sk4f::ZWCD(Sk4f(1,2,3,4), Sk4f(5,6,7,8))); | 134 ASSERT_EQ(Sk4f(3,4,7,8), Sk4f::ZWCD(Sk4f(1,2,3,4), Sk4f(5,6,7,8))); |
123 ASSERT_EQ(Sk4i(3,4,1,2), Sk4i(1,2,3,4).zwxy()); | 135 ASSERT_EQ(Sk4i(3,4,1,2), Sk4i(1,2,3,4).zwxy()); |
124 ASSERT_EQ(Sk4i(1,2,5,6), Sk4i::XYAB(Sk4i(1,2,3,4), Sk4i(5,6,7,8))); | 136 ASSERT_EQ(Sk4i(1,2,5,6), Sk4i::XYAB(Sk4i(1,2,3,4), Sk4i(5,6,7,8))); |
125 ASSERT_EQ(Sk4i(3,4,7,8), Sk4i::ZWCD(Sk4i(1,2,3,4), Sk4i(5,6,7,8))); | 137 ASSERT_EQ(Sk4i(3,4,7,8), Sk4i::ZWCD(Sk4i(1,2,3,4), Sk4i(5,6,7,8))); |
126 } | 138 } |
OLD | NEW |