Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit a112dfa

Browse files
committed
better comments in the unit test
1 parent 79bfa41 commit a112dfa

File tree

1 file changed

+58
-40
lines changed

1 file changed

+58
-40
lines changed

impeller/geometry/rect_unittests.cc

Lines changed: 58 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -73,24 +73,28 @@ TEST(RectTest, NormalizePoint) {
7373
EXPECT_EQ(Rect::MakeLTRB(l, t, r, b).NormalizePoint(Point(px, py)),
7474
expected)
7575
<< "Point(" << pt_desc << ") in " << rect_desc << " Rect";
76+
7677
// Scalar point inside Integer rect
7778
EXPECT_EQ(IRect::MakeLTRB(l, t, r, b).NormalizePoint(Point(px, py)),
7879
expected)
7980
<< "Point(" << pt_desc << ") in " << rect_desc << " IRect";
81+
8082
// Integer point inside Scalar rect
8183
EXPECT_EQ(Rect::MakeLTRB(l, t, r, b).NormalizePoint(IPoint(px, py)),
8284
expected)
8385
<< "IPoint(" << pt_desc << ") in " << rect_desc << " Rect";
86+
8487
// Integer point inside Integer rect
8588
EXPECT_EQ(IRect::MakeLTRB(l, t, r, b).NormalizePoint(IPoint(px, py)),
8689
expected)
8790
<< "IPoint(" << pt_desc << ") in " << rect_desc << " IRect";
8891

92+
// Now test nan handling by substituting a nan for the X and/or Y of
93+
// the point.
8994
auto nan = std::numeric_limits<Scalar>::quiet_NaN();
9095
auto nan_x = Point(nan, py);
9196
auto nan_y = Point(px, nan);
9297
auto nan_p = Point(nan, nan);
93-
// Nan Scalar point inside Scalar and integer rects
9498
EXPECT_EQ(Rect::MakeLTRB(l, t, r, b).NormalizePoint(nan_x), Point())
9599
<< "Point(NaN x) in " << rect_desc << " Rect";
96100
EXPECT_EQ(Rect::MakeLTRB(l, t, r, b).NormalizePoint(nan_y), Point())
@@ -105,29 +109,39 @@ TEST(RectTest, NormalizePoint) {
105109
<< "Point(NaN x&y) in " << rect_desc << " Rect";
106110
};
107111

108-
// Tests a rectangle using test_one both normally and all variants of
109-
// being empty by reversing the lr and tb points.
112+
// Tests the rectangle as specified, which is assumed to be non-empty
113+
// and then tests it in various states of emptiness in both dimensions
114+
// by reversing left/right and top/bottom or using the same value for
115+
// both.
110116
auto test = [&test_one](int64_t l, int64_t t, int64_t r, int64_t b, //
111117
int64_t px, int64_t py, //
112118
const std::string& pt_desc, Point expected) {
113-
test_one(l, t, r, b, "non-empty", px, py, pt_desc, expected);
114-
test_one(l, t, l, b, "LR empty", px, py, pt_desc, Point());
115-
test_one(r, t, l, b, "LR reversed", px, py, pt_desc, Point());
116-
test_one(l, t, r, t, "TB empty", px, py, pt_desc, Point());
117-
test_one(l, b, r, t, "TB reversed", px, py, pt_desc, Point());
118-
test_one(l, t, l, t, "all empty", px, py, pt_desc, Point());
119-
test_one(r, b, l, t, "all reversed", px, py, pt_desc, Point());
119+
// clang-format off
120+
// rect point expected
121+
// rect description point desc result
122+
test_one(l, t, r, b, "non-empty", px, py, pt_desc, expected);
123+
test_one(l, t, l, b, "LR empty", px, py, pt_desc, Point());
124+
test_one(r, t, l, b, "LR reversed", px, py, pt_desc, Point());
125+
test_one(l, t, r, t, "TB empty", px, py, pt_desc, Point());
126+
test_one(l, b, r, t, "TB reversed", px, py, pt_desc, Point());
127+
test_one(l, t, l, t, "all empty", px, py, pt_desc, Point());
128+
test_one(r, b, l, t, "all reversed", px, py, pt_desc, Point());
129+
// clang-format on
120130
};
121131

122-
test(100, 100, 200, 200, 100, 100, "UL", Point(0, 0));
123-
test(100, 100, 200, 200, 200, 100, "UR", Point(1, 0));
124-
test(100, 100, 200, 200, 200, 200, "LR", Point(1, 1));
125-
test(100, 100, 200, 200, 100, 200, "LL", Point(0, 1));
126-
test(100, 100, 200, 200, 150, 150, "Center", Point(0.5, 0.5));
127-
test(100, 100, 200, 200, 0, 0, "outside UL", Point(-1, -1));
128-
test(100, 100, 200, 200, 300, 0, "outside UR", Point(2, -1));
129-
test(100, 100, 200, 200, 300, 300, "outside LR", Point(2, 2));
130-
test(100, 100, 200, 200, 0, 300, "outside LL", Point(-1, 2));
132+
// clang-format off
133+
// rect point point expected
134+
// [ l t r b ] [ px py ] description result
135+
test(100, 100, 200, 200, 100, 100, "UL", Point(0, 0));
136+
test(100, 100, 200, 200, 200, 100, "UR", Point(1, 0));
137+
test(100, 100, 200, 200, 200, 200, "LR", Point(1, 1));
138+
test(100, 100, 200, 200, 100, 200, "LL", Point(0, 1));
139+
test(100, 100, 200, 200, 150, 150, "Center", Point(0.5, 0.5));
140+
test(100, 100, 200, 200, 0, 0, "outside UL", Point(-1, -1));
141+
test(100, 100, 200, 200, 300, 0, "outside UR", Point(2, -1));
142+
test(100, 100, 200, 200, 300, 300, "outside LR", Point(2, 2));
143+
test(100, 100, 200, 200, 0, 300, "outside LL", Point(-1, 2));
144+
// clang-format on
131145

132146
// We can't test the true min and max due to overflow of the xywh
133147
// internal representation, but we can test with half their values.
@@ -156,56 +170,64 @@ TEST(RectTest, NormalizePointToNonFiniteRects) {
156170
EXPECT_EQ(Rect::MakeLTRB(l, t, r, b).NormalizePoint(Point(px, py)),
157171
expected)
158172
<< "Point(" << pt_desc << ") in Rect";
173+
159174
// Scalar point inside Scalar rect with NaN left
160175
EXPECT_EQ(Rect::MakeLTRB(nan, t, r, b).NormalizePoint(Point(px, py)),
161176
Point())
162177
<< "Point(" << pt_desc << ") in Rect NaN Left";
178+
163179
// Scalar point inside Scalar rect with NaN top
164180
EXPECT_EQ(Rect::MakeLTRB(l, nan, r, b).NormalizePoint(Point(px, py)),
165181
Point())
166182
<< "Point(" << pt_desc << ") in Rect NaN Top";
183+
167184
// Scalar point inside Scalar rect with NaN right
168185
EXPECT_EQ(Rect::MakeLTRB(l, t, nan, b).NormalizePoint(Point(px, py)),
169186
Point())
170187
<< "Point(" << pt_desc << ") in Rect NaN Left";
188+
171189
// Scalar point inside Scalar rect with NaN bottom
172190
EXPECT_EQ(Rect::MakeLTRB(l, t, r, nan).NormalizePoint(Point(px, py)),
173191
Point())
174192
<< "Point(" << pt_desc << ") in Rect NaN Top";
193+
175194
// Scalar point inside Scalar rect with infinite left
176195
EXPECT_EQ(Rect::MakeLTRB(-inf, t, r, b).NormalizePoint(Point(px, py)),
177196
Point())
178197
<< "Point(" << pt_desc << ") in Rect -Inf Left";
198+
179199
// Scalar point inside Scalar rect with infinite top
180200
EXPECT_EQ(Rect::MakeLTRB(l, -inf, r, b).NormalizePoint(Point(px, py)),
181201
Point())
182202
<< "Point(" << pt_desc << ") in Rect -Inf Top";
203+
183204
// Scalar point inside Scalar rect with infinite right
184205
EXPECT_EQ(Rect::MakeLTRB(l, t, inf, b).NormalizePoint(Point(px, py)),
185206
Point(0, expected.y))
186207
<< "Point(" << pt_desc << ") in Rect Inf Right";
208+
187209
// Scalar point inside Scalar rect with infinite bottom
188210
EXPECT_EQ(Rect::MakeLTRB(l, t, r, inf).NormalizePoint(Point(px, py)),
189211
Point(expected.x, 0))
190212
<< "Point(" << pt_desc << ") in Rect Inf Bottom";
191213

192-
// Testing with NaN points
214+
// Now test NaN handling by substituting a NaN for the X and/or Y of
215+
// the point.
193216
auto nan_x = Point(nan, py);
194217
auto nan_y = Point(px, nan);
195218
auto nan_p = Point(nan, nan);
196-
// Nan Scalar point inside Scalar rect
197219
EXPECT_EQ(Rect::MakeLTRB(l, t, r, b).NormalizePoint(nan_x), Point())
198220
<< "Point(NaN x) in Rect";
199221
EXPECT_EQ(Rect::MakeLTRB(l, t, r, b).NormalizePoint(nan_y), Point())
200222
<< "Point(NaN y) in Rect";
201223
EXPECT_EQ(Rect::MakeLTRB(l, t, r, b).NormalizePoint(nan_p), Point())
202224
<< "Point(NaN x&y) in Rect";
203225

204-
// Testing with infinite points
226+
// Now test +/- infinity handling by substituting an infinity for the
227+
// X and/or Y of the point.
205228
auto inf_x = Point(inf, py);
206229
auto inf_y = Point(px, inf);
207230
auto inf_p = Point(inf, inf);
208-
// Infinite Scalar point inside Scalar rect
209231
EXPECT_EQ(Rect::MakeLTRB(l, t, r, b).NormalizePoint(inf_x), Point())
210232
<< "Point(Infinite x) in Rect";
211233
EXPECT_EQ(Rect::MakeLTRB(l, t, r, b).NormalizePoint(inf_y), Point())
@@ -220,23 +242,19 @@ TEST(RectTest, NormalizePointToNonFiniteRects) {
220242
<< "Point(-Infinite x&y) in Rect";
221243
};
222244

223-
test(100, 100, 200, 200, 100, 100, "UL", Point(0, 0));
224-
test(100, 100, 200, 200, 200, 100, "UR", Point(1, 0));
225-
test(100, 100, 200, 200, 200, 200, "LR", Point(1, 1));
226-
test(100, 100, 200, 200, 100, 200, "LL", Point(0, 1));
227-
test(100, 100, 200, 200, 150, 150, "Center", Point(0.5, 0.5));
228-
test(100, 100, 200, 200, 0, 0, "outside UL", Point(-1, -1));
229-
test(100, 100, 200, 200, 300, 0, "outside UR", Point(2, -1));
230-
test(100, 100, 200, 200, 300, 300, "outside LR", Point(2, 2));
231-
test(100, 100, 200, 200, 0, 300, "outside LL", Point(-1, 2));
232-
233-
// We can't test the true min and max due to overflow of the xywh
234-
// internal representation, but we can test with half their values.
235-
// When TRect is converted to ltrb notation, we can relax this
236-
// restriction.
237-
int64_t min_int = std::numeric_limits<int64_t>::min() / 2;
238-
int64_t max_int = std::numeric_limits<int64_t>::max() / 2;
239-
test(min_int, 100, max_int, 200, 0, 150, "max int center", Point(0.5, 0.5));
245+
// clang-format off
246+
// rect point point expected
247+
// [ l t r b ] [ px py ] description result
248+
test(100, 100, 200, 200, 100, 100, "UL", Point(0, 0));
249+
test(100, 100, 200, 200, 200, 100, "UR", Point(1, 0));
250+
test(100, 100, 200, 200, 200, 200, "LR", Point(1, 1));
251+
test(100, 100, 200, 200, 100, 200, "LL", Point(0, 1));
252+
test(100, 100, 200, 200, 150, 150, "Center", Point(0.5, 0.5));
253+
test(100, 100, 200, 200, 0, 0, "outside UL", Point(-1, -1));
254+
test(100, 100, 200, 200, 300, 0, "outside UR", Point(2, -1));
255+
test(100, 100, 200, 200, 300, 300, "outside LR", Point(2, 2));
256+
test(100, 100, 200, 200, 0, 300, "outside LL", Point(-1, 2));
257+
// clang-format on
240258
}
241259

242260
} // namespace testing

0 commit comments

Comments
 (0)