RawSpeed
fast raw decoding library
Loading...
Searching...
No Matches
NORangesSetTest.cpp
Go to the documentation of this file.
1/*
2 RawSpeed - RAW file decoder.
3
4 Copyright (C) 2017 Roman Lebedev
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; withexpected even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with this library; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19*/
20
21#include "adt/NORangesSet.h"
22#include "adt/Range.h"
23#include "adt/RangeTest.h"
24#include <tuple>
25#include <gtest/gtest.h>
26
27// IWYU pragma: no_forward_declare rawspeed::Range
28
30using rawspeed::Range;
31
32namespace rawspeed_test {
33
34namespace {
35
36TEST_P(TwoRangesTest, NORangesSetDataSelfTest) {
37 {
39
40 auto res = s.insert(r0);
41 ASSERT_TRUE(res);
42
43 // can not insert same element twice
44 res = s.insert(r0);
45 ASSERT_FALSE(res);
46 }
47 {
49
50 auto res = s.insert(r1);
51 ASSERT_TRUE(res);
52
53 // can not insert same element twice
54 res = s.insert(r1);
55 ASSERT_FALSE(res);
56 }
57}
58
59TEST_P(TwoRangesTest, NORangesSetDataTest) {
60 {
62 auto res = s.insert(r0);
63 ASSERT_TRUE(res);
64
65 res = s.insert(r1);
66 // if the ranges overlap, we should fail to insert the second range
67 if (AllOverlapped.find(GetParam()) != AllOverlapped.end()) {
68 ASSERT_FALSE(res);
69 } else {
70 ASSERT_TRUE(res);
71 }
72 }
73 {
75 auto res = s.insert(r1);
76 ASSERT_TRUE(res);
77
78 res = s.insert(r0);
79 // if the ranges overlap, we should fail to insert the second range
80 if (AllOverlapped.find(GetParam()) != AllOverlapped.end()) {
81 ASSERT_FALSE(res);
82 } else {
83 ASSERT_TRUE(res);
84 }
85 }
86}
87
88using threeRangesType = std::tuple<int, unsigned, int, unsigned, int, unsigned>;
89class ThreeRangesTest : public ::testing::TestWithParam<threeRangesType> {
90protected:
91 ThreeRangesTest() = default;
92 virtual void SetUp() {
93 r0 = Range<int>(std::get<0>(GetParam()), std::get<1>(GetParam()));
94 r1 = Range<int>(std::get<2>(GetParam()), std::get<3>(GetParam()));
95 r2 = Range<int>(std::get<4>(GetParam()), std::get<5>(GetParam()));
96 }
97
101};
103 Unsigned, ThreeRangesTest,
104 testing::Combine(testing::Range(0, 3), testing::Range(0U, 3U),
105 testing::Range(0, 3), testing::Range(0U, 3U),
106 testing::Range(0, 3), testing::Range(0U, 3U)));
107
108TEST_P(ThreeRangesTest, NORangesSetDataTest) {
110 auto res = s.insert(r0);
111 ASSERT_TRUE(res);
112
113 res = s.insert(r1);
114 ASSERT_EQ(res, !RangesOverlap(r1, r0));
115 if (!res)
116 return; // If we already have overlap don't proceed further.
117
118 res = s.insert(r2);
119 ASSERT_EQ(res, !RangesOverlap(r0, r2) && !RangesOverlap(r1, r2));
120}
121
122} // namespace
123
124} // namespace rawspeed_test
#define s
INSTANTIATE_TEST_SUITE_P(MD5Test, MD5Test, ::testing::ValuesIn(testCases))
TEST_P(MD5Test, CheckTestCaseSet)
Definition MD5Test.cpp:388
std::tuple< int, unsigned, int, unsigned, int, unsigned > threeRangesType