Flutter Engine
The Flutter Engine
Functions
range_unittest.cc File Reference
#include <sstream>
#include "gtest/gtest.h"
#include "range.h"

Go to the source code of this file.

Functions

 TYPED_TEST (RangeTest, EmptyInit)
 
 TYPED_TEST (RangeTest, StartEndInit)
 
 TYPED_TEST (RangeTest, StartEndReversedInit)
 
 TYPED_TEST (RangeTest, PositionInit)
 
 TYPED_TEST (RangeTest, InvalidRange)
 
 TYPED_TEST (RangeTest, Equality)
 
 TYPED_TEST (RangeTest, EqualsIgnoringDirection)
 
 TYPED_TEST (RangeTest, SetStart)
 
 TYPED_TEST (RangeTest, SetEnd)
 
 TYPED_TEST (RangeTest, SetStartAndEnd)
 
 TYPED_TEST (RangeTest, ReversedRange)
 
 TYPED_TEST (RangeTest, SetReversedRange)
 
 TYPED_TEST (RangeTest, ContainAndIntersect)
 
 TEST (RangeTest, RangeOperations)
 
 TEST (RangeTest, ContainsAndIntersects)
 
 TEST (RangeTest, Intersect)
 
 TEST (RangeTest, IsBoundedBy)
 
 TEST (RangeTest, ToString)
 

Function Documentation

◆ TEST() [1/5]

TEST ( RangeTest  ,
ContainsAndIntersects   
)

Definition at line 280 of file range_unittest.cc.

280 {
281 constexpr gfx::Range r1(0, 0);
282 constexpr gfx::Range r2(0, 1);
283 constexpr gfx::Range r3(1, 2);
284 constexpr gfx::Range r4(1, 0);
285 constexpr gfx::Range r5(2, 1);
286 constexpr gfx::Range r6(0, 2);
287 constexpr gfx::Range r7(2, 0);
288 constexpr gfx::Range r8(1, 1);
289
290 // Ensures Contains(...) handle the open range.
291 EXPECT_TRUE(r2.Contains(r1));
292 EXPECT_TRUE(r4.Contains(r1));
293 EXPECT_TRUE(r3.Contains(r5));
294 EXPECT_TRUE(r5.Contains(r3));
295
296 // Ensures larger ranges contains smaller ranges.
297 EXPECT_TRUE(r6.Contains(r1));
298 EXPECT_TRUE(r6.Contains(r2));
299 EXPECT_TRUE(r6.Contains(r3));
300 EXPECT_TRUE(r6.Contains(r4));
301 EXPECT_TRUE(r6.Contains(r5));
302
303 EXPECT_TRUE(r7.Contains(r1));
304 EXPECT_TRUE(r7.Contains(r2));
305 EXPECT_TRUE(r7.Contains(r3));
306 EXPECT_TRUE(r7.Contains(r4));
307 EXPECT_TRUE(r7.Contains(r5));
308
309 // Ensures Intersects(...) handle the open range.
310 EXPECT_TRUE(r2.Intersects(r1));
311 EXPECT_TRUE(r4.Intersects(r1));
312
313 // Ensures larger ranges intersects smaller ranges.
314 EXPECT_TRUE(r6.Intersects(r1));
315 EXPECT_TRUE(r6.Intersects(r2));
316 EXPECT_TRUE(r6.Intersects(r3));
317 EXPECT_TRUE(r6.Intersects(r4));
318 EXPECT_TRUE(r6.Intersects(r5));
319
320 EXPECT_TRUE(r7.Intersects(r1));
321 EXPECT_TRUE(r7.Intersects(r2));
322 EXPECT_TRUE(r7.Intersects(r3));
323 EXPECT_TRUE(r7.Intersects(r4));
324 EXPECT_TRUE(r7.Intersects(r5));
325
326 // Ensures adjacent ranges don't overlap.
327 EXPECT_FALSE(r2.Intersects(r3));
328 EXPECT_FALSE(r5.Intersects(r4));
329
330 // Ensures empty ranges are handled correctly.
331 EXPECT_FALSE(r1.Contains(r8));
332 EXPECT_FALSE(r2.Contains(r8));
333 EXPECT_TRUE(r3.Contains(r8));
334 EXPECT_TRUE(r8.Contains(r8));
335
336 EXPECT_FALSE(r1.Intersects(r8));
337 EXPECT_FALSE(r2.Intersects(r8));
338 EXPECT_TRUE(r3.Intersects(r8));
339 EXPECT_TRUE(r8.Intersects(r8));
340}
#define EXPECT_TRUE(handle)
Definition: unit_test.h:678

◆ TEST() [2/5]

TEST ( RangeTest  ,
Intersect   
)

Definition at line 342 of file range_unittest.cc.

342 {
343 EXPECT_EQ(gfx::Range(0, 1).Intersect({0, 1}), gfx::Range(0, 1));
344 EXPECT_EQ(gfx::Range(0, 1).Intersect({0, 0}), gfx::Range(0, 0));
345 EXPECT_EQ(gfx::Range(0, 0).Intersect({1, 0}), gfx::Range(0, 0));
346 EXPECT_EQ(gfx::Range(0, 4).Intersect({2, 3}), gfx::Range(2, 3));
347 EXPECT_EQ(gfx::Range(0, 4).Intersect({2, 7}), gfx::Range(2, 4));
348 EXPECT_EQ(gfx::Range(0, 4).Intersect({3, 4}), gfx::Range(3, 4));
349
350 EXPECT_EQ(gfx::Range(0, 1).Intersect({1, 1}), gfx::Range::InvalidRange());
351 EXPECT_EQ(gfx::Range(1, 1).Intersect({1, 0}), gfx::Range::InvalidRange());
352 EXPECT_EQ(gfx::Range(0, 1).Intersect({1, 2}), gfx::Range::InvalidRange());
353 EXPECT_EQ(gfx::Range(0, 1).Intersect({2, 1}), gfx::Range::InvalidRange());
354 EXPECT_EQ(gfx::Range(2, 1).Intersect({1, 0}), gfx::Range::InvalidRange());
355}
static constexpr Range InvalidRange()
Definition: range.h:50

◆ TEST() [3/5]

TEST ( RangeTest  ,
IsBoundedBy   
)

Definition at line 357 of file range_unittest.cc.

357 {
358 constexpr gfx::Range r1(0, 0);
359 constexpr gfx::Range r2(0, 1);
360 EXPECT_TRUE(r1.IsBoundedBy(r1));
361 EXPECT_FALSE(r2.IsBoundedBy(r1));
362
363 constexpr gfx::Range r3(0, 2);
364 constexpr gfx::Range r4(2, 2);
365 EXPECT_TRUE(r4.IsBoundedBy(r3));
366 EXPECT_FALSE(r3.IsBoundedBy(r4));
367}

◆ TEST() [4/5]

TEST ( RangeTest  ,
RangeOperations   
)

Definition at line 224 of file range_unittest.cc.

224 {
225 constexpr gfx::Range invalid_range = gfx::Range::InvalidRange();
226 constexpr gfx::Range ranges[] = {{0, 0}, {0, 1}, {0, 2}, {1, 0}, {1, 1},
227 {1, 2}, {2, 0}, {2, 1}, {2, 2}};
228
229 // Ensures valid behavior over same range.
230 for (const auto& range : ranges) {
231 SCOPED_TRACE(range.ToString());
232 // A range should contain itself.
233 EXPECT_TRUE(range.Contains(range));
234 // A ranges should intersect with itself.
235 EXPECT_TRUE(range.Intersects(range));
236 }
237
238 // Ensures valid behavior with an invalid range.
239 for (const auto& range : ranges) {
240 SCOPED_TRACE(range.ToString());
241 EXPECT_FALSE(invalid_range.Contains(range));
242 EXPECT_FALSE(invalid_range.Intersects(range));
243 EXPECT_FALSE(range.Contains(invalid_range));
244 EXPECT_FALSE(range.Intersects(invalid_range));
245 }
246 EXPECT_FALSE(invalid_range.Contains(invalid_range));
247 EXPECT_FALSE(invalid_range.Intersects(invalid_range));
248
249 // Ensures consistent operations between Contains(...) and Intersects(...).
250 for (const auto& range1 : ranges) {
251 for (const auto& range2 : ranges) {
252 SCOPED_TRACE(testing::Message()
253 << "range1=" << range1 << " range2=" << range2);
254 if (range1.Contains(range2)) {
255 EXPECT_TRUE(range1.Intersects(range2));
256 EXPECT_EQ(range2.Contains(range1),
257 range1.EqualsIgnoringDirection(range2));
258 }
259 EXPECT_EQ(range2.Intersects(range1), range1.Intersects(range2));
260
261 EXPECT_EQ(range1.Intersect(range2) != invalid_range,
262 range1.Intersects(range2));
263 }
264 }
265
266 // Ranges should behave the same way no matter the direction.
267 for (const auto& range1 : ranges) {
268 for (const auto& range2 : ranges) {
269 SCOPED_TRACE(testing::Message()
270 << "range1=" << range1 << " range2=" << range2);
271 EXPECT_EQ(range1.Contains(range2),
272 range1.Contains(gfx::Range(range2.GetMax(), range2.GetMin())));
273 EXPECT_EQ(
274 range1.Intersects(range2),
275 range1.Intersects(gfx::Range(range2.GetMax(), range2.GetMin())));
276 }
277 }
278}
constexpr bool Intersects(const Range &range) const
Definition: range.h:81
constexpr bool Contains(const Range &range) const
Definition: range.h:84

◆ TEST() [5/5]

TEST ( RangeTest  ,
ToString   
)

Definition at line 369 of file range_unittest.cc.

369 {
370 gfx::Range range(4, 7);
371 EXPECT_EQ("{4,7}", range.ToString());
372
373 range = gfx::Range::InvalidRange();
374 std::ostringstream expected;
375 expected << "{" << range.start() << "," << range.end() << "}";
376 EXPECT_EQ(expected.str(), range.ToString());
377}

◆ TYPED_TEST() [1/13]

TYPED_TEST ( RangeTest  ,
ContainAndIntersect   
)

Definition at line 196 of file range_unittest.cc.

196 {
197 {
198 SCOPED_TRACE("contain and intersect");
199 TypeParam r1(10, 12);
200 TypeParam r2(1, 8);
201 TypeParam r3(5, 12);
202 TestContainsAndIntersects(r1, r2, r3);
203 }
204 {
205 SCOPED_TRACE("contain and intersect: reversed");
206 TypeParam r1(12, 10);
207 TypeParam r2(8, 1);
208 TypeParam r3(12, 5);
209 TestContainsAndIntersects(r1, r2, r3);
210 }
211 // Invalid rect tests
212 TypeParam r1(10, 12);
213 TypeParam r2(8, 1);
214 TypeParam invalid = r1.Intersect(r2);
215 EXPECT_FALSE(invalid.IsValid());
216 EXPECT_FALSE(invalid.Contains(invalid));
217 EXPECT_FALSE(invalid.Contains(r1));
218 EXPECT_FALSE(invalid.Intersects(invalid));
219 EXPECT_FALSE(invalid.Intersects(r1));
220 EXPECT_FALSE(r1.Contains(invalid));
221 EXPECT_FALSE(r1.Intersects(invalid));
222}
static bool invalid(const SkISize &size)

◆ TYPED_TEST() [2/13]

TYPED_TEST ( RangeTest  ,
EmptyInit   
)

Definition at line 48 of file range_unittest.cc.

48 {
49 TypeParam r;
50 EXPECT_EQ(0U, r.start());
51 EXPECT_EQ(0U, r.end());
52 EXPECT_EQ(0U, r.length());
53 EXPECT_FALSE(r.is_reversed());
54 EXPECT_TRUE(r.is_empty());
55 EXPECT_TRUE(r.IsValid());
56 EXPECT_EQ(0U, r.GetMin());
57 EXPECT_EQ(0U, r.GetMax());
58}

◆ TYPED_TEST() [3/13]

TYPED_TEST ( RangeTest  ,
Equality   
)

Definition at line 108 of file range_unittest.cc.

108 {
109 TypeParam r1(10, 4);
110 TypeParam r2(10, 4);
111 TypeParam r3(10, 2);
112 EXPECT_EQ(r1, r2);
113 EXPECT_NE(r1, r3);
114 EXPECT_NE(r2, r3);
115
116 TypeParam r4(11, 4);
117 EXPECT_NE(r1, r4);
118 EXPECT_NE(r2, r4);
119 EXPECT_NE(r3, r4);
120
121 TypeParam r5(12, 5);
122 EXPECT_NE(r1, r5);
123 EXPECT_NE(r2, r5);
124 EXPECT_NE(r3, r5);
125}

◆ TYPED_TEST() [4/13]

TYPED_TEST ( RangeTest  ,
EqualsIgnoringDirection   
)

Definition at line 127 of file range_unittest.cc.

127 {
128 TypeParam r1(10, 5);
129 TypeParam r2(5, 10);
130 EXPECT_TRUE(r1.EqualsIgnoringDirection(r2));
131}

◆ TYPED_TEST() [5/13]

TYPED_TEST ( RangeTest  ,
InvalidRange   
)

Definition at line 96 of file range_unittest.cc.

96 {
97 TypeParam r(TypeParam::InvalidRange());
98 EXPECT_EQ(0U, r.length());
99 EXPECT_EQ(r.start(), r.end());
100 EXPECT_EQ(r.GetMax(), r.GetMin());
101 EXPECT_FALSE(r.is_reversed());
102 EXPECT_TRUE(r.is_empty());
103 EXPECT_FALSE(r.IsValid());
104 EXPECT_EQ(r, TypeParam::InvalidRange());
105 EXPECT_TRUE(r.EqualsIgnoringDirection(TypeParam::InvalidRange()));
106}

◆ TYPED_TEST() [6/13]

TYPED_TEST ( RangeTest  ,
PositionInit   
)

Definition at line 84 of file range_unittest.cc.

84 {
85 TypeParam r(12);
86 EXPECT_EQ(12U, r.start());
87 EXPECT_EQ(12U, r.end());
88 EXPECT_EQ(0U, r.length());
89 EXPECT_FALSE(r.is_reversed());
90 EXPECT_TRUE(r.is_empty());
91 EXPECT_TRUE(r.IsValid());
92 EXPECT_EQ(12U, r.GetMin());
93 EXPECT_EQ(12U, r.GetMax());
94}

◆ TYPED_TEST() [7/13]

TYPED_TEST ( RangeTest  ,
ReversedRange   
)

Definition at line 167 of file range_unittest.cc.

167 {
168 TypeParam r(10, 5);
169 EXPECT_EQ(10U, r.start());
170 EXPECT_EQ(5U, r.end());
171 EXPECT_EQ(5U, r.length());
172 EXPECT_TRUE(r.is_reversed());
173 EXPECT_TRUE(r.IsValid());
174 EXPECT_EQ(5U, r.GetMin());
175 EXPECT_EQ(10U, r.GetMax());
176}

◆ TYPED_TEST() [8/13]

TYPED_TEST ( RangeTest  ,
SetEnd   
)

Definition at line 145 of file range_unittest.cc.

145 {
146 TypeParam r(10, 13);
147 EXPECT_EQ(10U, r.start());
148 EXPECT_EQ(3U, r.length());
149
150 r.set_end(20);
151 EXPECT_EQ(10U, r.start());
152 EXPECT_EQ(20U, r.end());
153 EXPECT_EQ(10U, r.length());
154}

◆ TYPED_TEST() [9/13]

TYPED_TEST ( RangeTest  ,
SetReversedRange   
)

Definition at line 178 of file range_unittest.cc.

178 {
179 TypeParam r(10, 20);
180 r.set_start(25);
181 EXPECT_EQ(25U, r.start());
182 EXPECT_EQ(20U, r.end());
183 EXPECT_EQ(5U, r.length());
184 EXPECT_TRUE(r.is_reversed());
185 EXPECT_TRUE(r.IsValid());
186
187 r.set_end(21);
188 EXPECT_EQ(25U, r.start());
189 EXPECT_EQ(21U, r.end());
190 EXPECT_EQ(4U, r.length());
191 EXPECT_TRUE(r.IsValid());
192 EXPECT_EQ(21U, r.GetMin());
193 EXPECT_EQ(25U, r.GetMax());
194}

◆ TYPED_TEST() [10/13]

TYPED_TEST ( RangeTest  ,
SetStart   
)

Definition at line 133 of file range_unittest.cc.

133 {
134 TypeParam r(10, 20);
135 EXPECT_EQ(10U, r.start());
136 EXPECT_EQ(10U, r.length());
137
138 r.set_start(42);
139 EXPECT_EQ(42U, r.start());
140 EXPECT_EQ(20U, r.end());
141 EXPECT_EQ(22U, r.length());
142 EXPECT_TRUE(r.is_reversed());
143}

◆ TYPED_TEST() [11/13]

TYPED_TEST ( RangeTest  ,
SetStartAndEnd   
)

Definition at line 156 of file range_unittest.cc.

156 {
157 TypeParam r;
158 r.set_end(5);
159 r.set_start(1);
160 EXPECT_EQ(1U, r.start());
161 EXPECT_EQ(5U, r.end());
162 EXPECT_EQ(4U, r.length());
163 EXPECT_EQ(1U, r.GetMin());
164 EXPECT_EQ(5U, r.GetMax());
165}

◆ TYPED_TEST() [12/13]

TYPED_TEST ( RangeTest  ,
StartEndInit   
)

Definition at line 60 of file range_unittest.cc.

60 {
61 TypeParam r(10, 15);
62 EXPECT_EQ(10U, r.start());
63 EXPECT_EQ(15U, r.end());
64 EXPECT_EQ(5U, r.length());
65 EXPECT_FALSE(r.is_reversed());
66 EXPECT_FALSE(r.is_empty());
67 EXPECT_TRUE(r.IsValid());
68 EXPECT_EQ(10U, r.GetMin());
69 EXPECT_EQ(15U, r.GetMax());
70}

◆ TYPED_TEST() [13/13]

TYPED_TEST ( RangeTest  ,
StartEndReversedInit   
)

Definition at line 72 of file range_unittest.cc.

72 {
73 TypeParam r(10, 5);
74 EXPECT_EQ(10U, r.start());
75 EXPECT_EQ(5U, r.end());
76 EXPECT_EQ(5U, r.length());
77 EXPECT_TRUE(r.is_reversed());
78 EXPECT_FALSE(r.is_empty());
79 EXPECT_TRUE(r.IsValid());
80 EXPECT_EQ(5U, r.GetMin());
81 EXPECT_EQ(10U, r.GetMax());
82}