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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 ASSERT_NE(twoi, twof.reinterpret<Sk4i>()); | 59 ASSERT_NE(twoi, twof.reinterpret<Sk4i>()); |
60 ASSERT_EQ(twof, twoi.cast<Sk4f>()); | 60 ASSERT_EQ(twof, twoi.cast<Sk4f>()); |
61 ASSERT_NE(twof, twoi.reinterpret<Sk4f>()); | 61 ASSERT_NE(twof, twoi.reinterpret<Sk4f>()); |
62 } | 62 } |
63 | 63 |
64 DEF_TEST(Sk4x_Bits, r) { | 64 DEF_TEST(Sk4x_Bits, r) { |
65 ASSERT_EQ(Sk4i(0,0,0,0).bitNot(), Sk4i(-1,-1,-1,-1)); | 65 ASSERT_EQ(Sk4i(0,0,0,0).bitNot(), Sk4i(-1,-1,-1,-1)); |
66 | 66 |
67 Sk4i a(2,3,4,5), | 67 Sk4i a(2,3,4,5), |
68 b(1,3,5,7); | 68 b(1,3,5,7); |
69 ASSERT_EQ(Sk4i(0,3,4,5), a.bitAnd(b)); | 69 ASSERT_EQ(Sk4i(0,3,4,5), a & b); |
70 ASSERT_EQ(Sk4i(3,3,5,7), a.bitOr(b)); | 70 ASSERT_EQ(Sk4i(3,3,5,7), a | b); |
71 } | 71 } |
72 | 72 |
73 DEF_TEST(Sk4x_Arith, r) { | 73 DEF_TEST(Sk4x_Arith, r) { |
74 ASSERT_EQ(Sk4f(4,6,8,10), Sk4f(1,2,3,4).add(Sk4f(3,4,5,6))); | 74 ASSERT_EQ(Sk4f(4,6,8,10), Sk4f(1,2,3,4) + Sk4f(3,4,5,6)); |
75 ASSERT_EQ(Sk4f(-2,-2,-2,-2), Sk4f(1,2,3,4).subtract(Sk4f(3,4,5,6))); | 75 ASSERT_EQ(Sk4f(-2,-2,-2,-2), Sk4f(1,2,3,4) - Sk4f(3,4,5,6)); |
76 ASSERT_EQ(Sk4f(3,8,15,24), Sk4f(1,2,3,4).multiply(Sk4f(3,4,5,6))); | 76 ASSERT_EQ(Sk4f(3,8,15,24), Sk4f(1,2,3,4) * Sk4f(3,4,5,6)); |
77 | 77 |
78 float third = 1.0f/3.0f; | 78 float third = 1.0f/3.0f; |
79 ASSERT_EQ(Sk4f(1*third, 0.5f, 0.6f, 2*third), Sk4f(1,2,3,4).divide(Sk4f(3,4,
5,6))); | 79 ASSERT_EQ(Sk4f(1*third, 0.5f, 0.6f, 2*third), Sk4f(1,2,3,4) / Sk4f(3,4,5,6))
; |
80 ASSERT_EQ(Sk4i(4,6,8,10), Sk4i(1,2,3,4).add(Sk4i(3,4,5,6))); | 80 ASSERT_EQ(Sk4i(4,6,8,10), Sk4i(1,2,3,4) + Sk4i(3,4,5,6)); |
81 ASSERT_EQ(Sk4i(-2,-2,-2,-2), Sk4i(1,2,3,4).subtract(Sk4i(3,4,5,6))); | 81 ASSERT_EQ(Sk4i(-2,-2,-2,-2), Sk4i(1,2,3,4) - Sk4i(3,4,5,6)); |
82 ASSERT_EQ(Sk4i(3,8,15,24), Sk4i(1,2,3,4).multiply(Sk4i(3,4,5,6))); | 82 ASSERT_EQ(Sk4i(3,8,15,24), Sk4i(1,2,3,4) * Sk4i(3,4,5,6)); |
83 } | 83 } |
84 | 84 |
85 DEF_TEST(Sk4x_ImplicitPromotion, r) { | 85 DEF_TEST(Sk4x_ExplicitPromotion, r) { |
86 ASSERT_EQ(Sk4f(2,4,6,8), Sk4f(1,2,3,4).multiply(Sk4f(2.0f))); | 86 ASSERT_EQ(Sk4f(2,4,6,8), Sk4f(1,2,3,4) * Sk4f(2.0f)); |
87 } | 87 } |
88 | 88 |
89 DEF_TEST(Sk4x_Sqrt, r) { | 89 DEF_TEST(Sk4x_Sqrt, r) { |
90 Sk4f squares(4, 16, 25, 121), | 90 Sk4f squares(4, 16, 25, 121), |
91 roots(2, 4, 5, 11); | 91 roots(2, 4, 5, 11); |
92 // .sqrt() should be pretty precise. | 92 // .sqrt() should be pretty precise. |
93 Sk4f error = roots.subtract(squares.sqrt()); | 93 Sk4f error = roots.subtract(squares.sqrt()); |
94 REPORTER_ASSERT(r, error.greaterThanEqual(Sk4f(0.0f)).allTrue()); | 94 REPORTER_ASSERT(r, error.greaterThanEqual(Sk4f(0.0f)).allTrue()); |
95 REPORTER_ASSERT(r, error.lessThan(Sk4f(0.000001f)).allTrue()); | 95 REPORTER_ASSERT(r, error.lessThan(Sk4f(0.000001f)).allTrue()); |
96 | 96 |
97 // .rsqrt() isn't so precise (for SSE), but should be pretty close. | 97 // .rsqrt() isn't so precise (for SSE), but should be pretty close. |
98 error = roots.subtract(squares.multiply(squares.rsqrt())); | 98 error = roots.subtract(squares.multiply(squares.rsqrt())); |
99 REPORTER_ASSERT(r, error.greaterThanEqual(Sk4f(0.0f)).allTrue()); | 99 REPORTER_ASSERT(r, error.greaterThanEqual(Sk4f(0.0f)).allTrue()); |
100 REPORTER_ASSERT(r, error.lessThan(Sk4f(0.01f)).allTrue()); | 100 REPORTER_ASSERT(r, error.lessThan(Sk4f(0.01f)).allTrue()); |
101 } | 101 } |
102 | 102 |
103 DEF_TEST(Sk4x_Comparison, r) { | 103 DEF_TEST(Sk4x_Comparison, r) { |
104 ASSERT_EQ(Sk4f(1,2,3,4), Sk4f(1,2,3,4)); | 104 ASSERT_EQ(Sk4f(1,2,3,4), Sk4f(1,2,3,4)); |
105 ASSERT_NE(Sk4f(4,3,2,1), Sk4f(1,2,3,4)); | 105 ASSERT_NE(Sk4f(4,3,2,1), Sk4f(1,2,3,4)); |
106 | 106 |
107 ASSERT_EQ(Sk4i(-1,-1,0,-1), Sk4f(1,2,5,4).equal(Sk4f(1,2,3,4))); | 107 ASSERT_EQ(Sk4i(-1,-1,0,-1), Sk4f(1,2,5,4) == Sk4f(1,2,3,4)); |
108 | 108 |
109 ASSERT_EQ(Sk4i(-1,-1,-1,-1), Sk4f(1,2,3,4).lessThan(Sk4f(2,3,4,5))); | 109 ASSERT_EQ(Sk4i(-1,-1,-1,-1), Sk4f(1,2,3,4) < Sk4f(2,3,4,5)); |
110 ASSERT_EQ(Sk4i(-1,-1,-1,-1), Sk4f(1,2,3,4).lessThanEqual(Sk4f(2,3,4,5))); | 110 ASSERT_EQ(Sk4i(-1,-1,-1,-1), Sk4f(1,2,3,4) <= Sk4f(2,3,4,5)); |
111 ASSERT_EQ(Sk4i(0,0,0,0), Sk4f(1,2,3,4).greaterThan(Sk4f(2,3,4,5))); | 111 ASSERT_EQ(Sk4i(0,0,0,0), Sk4f(1,2,3,4) > Sk4f(2,3,4,5)); |
112 ASSERT_EQ(Sk4i(0,0,0,0), Sk4f(1,2,3,4).greaterThanEqual(Sk4f(2,3,4,5))); | 112 ASSERT_EQ(Sk4i(0,0,0,0), Sk4f(1,2,3,4) >= Sk4f(2,3,4,5)); |
113 | 113 |
114 ASSERT_EQ(Sk4i(1,2,3,4), Sk4i(1,2,3,4)); | 114 ASSERT_EQ(Sk4i(1,2,3,4), Sk4i(1,2,3,4)); |
115 ASSERT_NE(Sk4i(4,3,2,1), Sk4i(1,2,3,4)); | 115 ASSERT_NE(Sk4i(4,3,2,1), Sk4i(1,2,3,4)); |
116 | 116 |
117 ASSERT_EQ(Sk4i(-1,-1,0,-1), Sk4i(1,2,5,4).equal(Sk4i(1,2,3,4))); | 117 ASSERT_EQ(Sk4i(-1,-1,0,-1), Sk4i(1,2,5,4) == Sk4i(1,2,3,4)); |
118 | 118 |
119 ASSERT_EQ(Sk4i(-1,-1,-1,-1), Sk4i(1,2,3,4).lessThan(Sk4i(2,3,4,5))); | 119 ASSERT_EQ(Sk4i(-1,-1,-1,-1), Sk4i(1,2,3,4) < Sk4i(2,3,4,5)); |
120 ASSERT_EQ(Sk4i(-1,-1,-1,-1), Sk4i(1,2,3,4).lessThanEqual(Sk4i(2,3,4,5))); | 120 ASSERT_EQ(Sk4i(-1,-1,-1,-1), Sk4i(1,2,3,4) <= Sk4i(2,3,4,5)); |
121 ASSERT_EQ(Sk4i(0,0,0,0), Sk4i(1,2,3,4).greaterThan(Sk4i(2,3,4,5))); | 121 ASSERT_EQ(Sk4i(0,0,0,0), Sk4i(1,2,3,4) > Sk4i(2,3,4,5)); |
122 ASSERT_EQ(Sk4i(0,0,0,0), Sk4i(1,2,3,4).greaterThanEqual(Sk4i(2,3,4,5))); | 122 ASSERT_EQ(Sk4i(0,0,0,0), Sk4i(1,2,3,4) >= Sk4i(2,3,4,5)); |
123 } | 123 } |
124 | 124 |
125 DEF_TEST(Sk4x_MinMax, r) { | 125 DEF_TEST(Sk4x_MinMax, r) { |
126 ASSERT_EQ(Sk4f(1,2,2,1), Sk4f::Min(Sk4f(1,2,3,4), Sk4f(4,3,2,1))); | 126 ASSERT_EQ(Sk4f(1,2,2,1), Sk4f::Min(Sk4f(1,2,3,4), Sk4f(4,3,2,1))); |
127 ASSERT_EQ(Sk4f(4,3,3,4), Sk4f::Max(Sk4f(1,2,3,4), Sk4f(4,3,2,1))); | 127 ASSERT_EQ(Sk4f(4,3,3,4), Sk4f::Max(Sk4f(1,2,3,4), Sk4f(4,3,2,1))); |
128 ASSERT_EQ(Sk4i(1,2,2,1), Sk4i::Min(Sk4i(1,2,3,4), Sk4i(4,3,2,1))); | 128 ASSERT_EQ(Sk4i(1,2,2,1), Sk4i::Min(Sk4i(1,2,3,4), Sk4i(4,3,2,1))); |
129 ASSERT_EQ(Sk4i(4,3,3,4), Sk4i::Max(Sk4i(1,2,3,4), Sk4i(4,3,2,1))); | 129 ASSERT_EQ(Sk4i(4,3,3,4), Sk4i::Max(Sk4i(1,2,3,4), Sk4i(4,3,2,1))); |
130 } | 130 } |
131 | 131 |
132 DEF_TEST(Sk4x_Swizzle, r) { | 132 DEF_TEST(Sk4x_Swizzle, r) { |
133 ASSERT_EQ(Sk4f(3,4,1,2), Sk4f(1,2,3,4).zwxy()); | 133 ASSERT_EQ(Sk4f(3,4,1,2), Sk4f(1,2,3,4).zwxy()); |
134 ASSERT_EQ(Sk4f(1,2,5,6), Sk4f::XYAB(Sk4f(1,2,3,4), Sk4f(5,6,7,8))); | 134 ASSERT_EQ(Sk4f(1,2,5,6), Sk4f::XYAB(Sk4f(1,2,3,4), Sk4f(5,6,7,8))); |
135 ASSERT_EQ(Sk4f(3,4,7,8), Sk4f::ZWCD(Sk4f(1,2,3,4), Sk4f(5,6,7,8))); | 135 ASSERT_EQ(Sk4f(3,4,7,8), Sk4f::ZWCD(Sk4f(1,2,3,4), Sk4f(5,6,7,8))); |
136 ASSERT_EQ(Sk4i(3,4,1,2), Sk4i(1,2,3,4).zwxy()); | 136 ASSERT_EQ(Sk4i(3,4,1,2), Sk4i(1,2,3,4).zwxy()); |
137 ASSERT_EQ(Sk4i(1,2,5,6), Sk4i::XYAB(Sk4i(1,2,3,4), Sk4i(5,6,7,8))); | 137 ASSERT_EQ(Sk4i(1,2,5,6), Sk4i::XYAB(Sk4i(1,2,3,4), Sk4i(5,6,7,8))); |
138 ASSERT_EQ(Sk4i(3,4,7,8), Sk4i::ZWCD(Sk4i(1,2,3,4), Sk4i(5,6,7,8))); | 138 ASSERT_EQ(Sk4i(3,4,7,8), Sk4i::ZWCD(Sk4i(1,2,3,4), Sk4i(5,6,7,8))); |
139 } | 139 } |
OLD | NEW |