7#include "gtest/gtest.h"
13class RangeTest :
public testing::Test {};
15typedef testing::Types<gfx::Range> RangeTypes;
16TYPED_TEST_SUITE(RangeTest, RangeTypes);
19void TestContainsAndIntersects(
const T& r1,
const T& r2,
const T& r3) {
22 EXPECT_EQ(
T(10, 12), r1.Intersect(r1));
24 EXPECT_FALSE(r1.Intersects(r2));
25 EXPECT_FALSE(r1.Contains(r2));
27 EXPECT_FALSE(r2.Intersects(r1));
28 EXPECT_FALSE(r2.Contains(r1));
34 EXPECT_FALSE(r1.Contains(r3));
35 EXPECT_EQ(
T(10, 12), r1.Intersect(r3));
36 EXPECT_EQ(
T(10, 12), r3.Intersect(r1));
40 EXPECT_FALSE(r3.Contains(r2));
41 EXPECT_FALSE(r2.Contains(r3));
42 EXPECT_EQ(
T(5, 8), r2.Intersect(r3));
43 EXPECT_EQ(
T(5, 8), r3.Intersect(r2));
50 EXPECT_EQ(0
U, r.start());
51 EXPECT_EQ(0
U, r.end());
52 EXPECT_EQ(0
U, r.length());
53 EXPECT_FALSE(r.is_reversed());
56 EXPECT_EQ(0
U, r.GetMin());
57 EXPECT_EQ(0
U, r.GetMax());
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());
68 EXPECT_EQ(10U, r.GetMin());
69 EXPECT_EQ(15U, r.GetMax());
74 EXPECT_EQ(10U, r.start());
75 EXPECT_EQ(5U, r.end());
76 EXPECT_EQ(5U, r.length());
78 EXPECT_FALSE(r.is_empty());
80 EXPECT_EQ(5U, r.GetMin());
81 EXPECT_EQ(10U, r.GetMax());
86 EXPECT_EQ(12U, r.start());
87 EXPECT_EQ(12U, r.end());
88 EXPECT_EQ(0
U, r.length());
89 EXPECT_FALSE(r.is_reversed());
92 EXPECT_EQ(12U, r.GetMin());
93 EXPECT_EQ(12U, r.GetMax());
97 TypeParam r(TypeParam::InvalidRange());
98 EXPECT_EQ(0
U, r.length());
99 EXPECT_EQ(r.start(), r.end());
100 EXPECT_EQ(r.GetMax(), r.GetMin());
101 EXPECT_FALSE(r.is_reversed());
103 EXPECT_FALSE(r.IsValid());
104 EXPECT_EQ(r, TypeParam::InvalidRange());
105 EXPECT_TRUE(r.EqualsIgnoringDirection(TypeParam::InvalidRange()));
135 EXPECT_EQ(10U, r.start());
136 EXPECT_EQ(10U, r.length());
139 EXPECT_EQ(42U, r.start());
140 EXPECT_EQ(20U, r.end());
141 EXPECT_EQ(22U, r.length());
147 EXPECT_EQ(10U, r.start());
148 EXPECT_EQ(3U, r.length());
151 EXPECT_EQ(10U, r.start());
152 EXPECT_EQ(20U, r.end());
153 EXPECT_EQ(10U, r.length());
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());
169 EXPECT_EQ(10U, r.start());
170 EXPECT_EQ(5U, r.end());
171 EXPECT_EQ(5U, r.length());
174 EXPECT_EQ(5U, r.GetMin());
175 EXPECT_EQ(10U, r.GetMax());
181 EXPECT_EQ(25U, r.start());
182 EXPECT_EQ(20U, r.end());
183 EXPECT_EQ(5U, r.length());
188 EXPECT_EQ(25U, r.start());
189 EXPECT_EQ(21U, r.end());
190 EXPECT_EQ(4U, r.length());
192 EXPECT_EQ(21U, r.GetMin());
193 EXPECT_EQ(25U, r.GetMax());
198 SCOPED_TRACE(
"contain and intersect");
199 TypeParam r1(10, 12);
202 TestContainsAndIntersects(r1, r2, r3);
205 SCOPED_TRACE(
"contain and intersect: reversed");
206 TypeParam r1(12, 10);
209 TestContainsAndIntersects(r1, r2, r3);
212 TypeParam r1(10, 12);
214 TypeParam
invalid = r1.Intersect(r2);
215 EXPECT_FALSE(
invalid.IsValid());
217 EXPECT_FALSE(
invalid.Contains(r1));
219 EXPECT_FALSE(
invalid.Intersects(r1));
220 EXPECT_FALSE(r1.Contains(
invalid));
221 EXPECT_FALSE(r1.Intersects(
invalid));
224TEST(RangeTest, RangeOperations) {
226 constexpr gfx::Range ranges[] = {{0, 0}, {0, 1}, {0, 2}, {1, 0}, {1, 1},
227 {1, 2}, {2, 0}, {2, 1}, {2, 2}};
230 for (
const auto& range : ranges) {
231 SCOPED_TRACE(range.ToString());
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));
246 EXPECT_FALSE(invalid_range.
Contains(invalid_range));
247 EXPECT_FALSE(invalid_range.
Intersects(invalid_range));
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)) {
256 EXPECT_EQ(range2.Contains(range1),
257 range1.EqualsIgnoringDirection(range2));
259 EXPECT_EQ(range2.Intersects(range1), range1.Intersects(range2));
261 EXPECT_EQ(range1.Intersect(range2) != invalid_range,
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())));
274 range1.Intersects(range2),
275 range1.Intersects(
gfx::Range(range2.GetMax(), range2.GetMin())));
280TEST(RangeTest, ContainsAndIntersects) {
371 EXPECT_EQ(
"{4,7}", range.
ToString());
374 std::ostringstream expected;
375 expected <<
"{" << range.
start() <<
"," << range.
end() <<
"}";
376 EXPECT_EQ(expected.str(), range.
ToString());
static bool invalid(const SkISize &size)
constexpr bool Intersects(const Range &range) const
std::string ToString() const
constexpr bool IsBoundedBy(const Range &range) const
constexpr uint32_t end() const
constexpr uint32_t start() const
constexpr bool Contains(const Range &range) const
static constexpr Range InvalidRange()
static std::string ToString(CompilerBackend::Type type)
TEST(RangeTest, RangeOperations)
TYPED_TEST(RangeTest, EmptyInit)
#define EXPECT_TRUE(handle)