35 #include <unordered_set>
36 #include "DGtal/base/Common.h"
37 #include "DGtal/base/SetFunctions.h"
38 #include "DGtalCatch.h"
41 using namespace DGtal;
44 using DGtal::functions::setops::operator&;
45 using DGtal::functions::setops::operator-;
46 using DGtal::functions::setops::operator^;
54 std::unordered_set<int> )
57 int S1[ 10 ] = { 4, 15, 20, 17, 9, 7, 13, 12, 1, 3 };
58 int S2[ 6 ] = { 17, 14, 19, 2, 3, 4 };
59 TestType C1( S1, S1 + 10 );
60 TestType C2( S2, S2 + 6 );
61 TestType C1_minus_C2 = C1 - C2;
62 REQUIRE( C1_minus_C2.size() == 7 );
63 TestType C2_minus_C1 = C2 - C1;
64 REQUIRE( C2_minus_C1.size() == 3 );
65 REQUIRE( ( C1_minus_C2 - C1 ).size() == 0 );
66 REQUIRE( ( C2_minus_C1 - C2 ).size() == 0 );
67 REQUIRE( ( C1_minus_C2 - C2 ).size() == C1_minus_C2.size() );
68 REQUIRE( ( C2_minus_C1 - C1 ).size() == C2_minus_C1.size() );
71 REQUIRE( C1_union_C2.size() == 13 );
72 REQUIRE( C1_union_C2.size() == C2_union_C1.size() );
73 REQUIRE( ( DGtal::functions::setops::operator|(C1_minus_C2 , C2) ).size() == (DGtal::functions::setops::operator|(C2_minus_C1 , C1) ).size() );
75 TestType C1_intersection_C2 = C1 & C2;
76 TestType C2_intersection_C1 = C2 & C1;
77 REQUIRE( C1_intersection_C2.size() == 3 );
78 REQUIRE( C1_intersection_C2.size() == C2_intersection_C1.size() );
80 REQUIRE( ( DGtal::functions::setops::operator|(DGtal::functions::setops::operator|(C1_minus_C2 , C1_intersection_C2) , C2_minus_C1) ).size() == C1_union_C2.size() );
82 TestType C1_symdiff_C2 = C1 ^ C2;
83 TestType C2_symdiff_C1 = C2 ^ C1;
84 REQUIRE( C1_symdiff_C2.size() == C2_symdiff_C1.size() );
85 REQUIRE( C1_symdiff_C2.size() == ( C1_union_C2 - C1_intersection_C2 ).size() );
86 REQUIRE( C1_symdiff_C2.size() == ( DGtal::functions::setops::operator|(C1_minus_C2 , C2_minus_C1) ).size() );
88 REQUIRE(
isEqual( C1_symdiff_C2, C1_union_C2 - C1_intersection_C2 ) );
89 REQUIRE(
isEqual( C1_symdiff_C2, DGtal::functions::setops::operator|(C1_minus_C2 , C2_minus_C1) ) );
90 REQUIRE(
isEqual( DGtal::functions::setops::operator|(DGtal::functions::setops::operator|(C1_minus_C2 , C1_intersection_C2) , C2_minus_C1), C1_union_C2 ) );
105 static const int NB = 10000;
106 static std::default_random_engine generator;
107 static std::uniform_int_distribution<int> distribution(1,NB);
111 return distribution(generator);
115 TEMPLATE_TEST_CASE(
"SetFunctions benchmark operator | (sequences)",
"[set_functions]",
118 typedef typename TestType::size_type
Size;
121 for (
int i = 0; i < NB; ++i ) S1.insert( randomNB( ) );
122 for (
int i = 0; i < NB; ++i ) S2.insert( randomNB( ) );
123 TestType A( S1.begin(), S1.end() );
124 TestType B( S2.begin(), S2.end() );
127 std::random_shuffle( A.begin(), A.end() );
128 std::random_shuffle( B.begin(), B.end() );
130 SECTION(
" - benchmark set operators |" )
134 Size size_A = A.size();
135 Size size_B = B.size();
136 Size size_AorB = AorB.size();
142 std::unordered_set<int> )
144 typedef typename TestType::size_type
Size;
146 for (
int i = 0; i < NB; ++i ) S1.insert( randomNB( ) );
148 for (
int i = 0; i < NB; ++i ) S2.insert( randomNB( ) );
149 TestType A( S1.begin(), S1.end() );
150 TestType B( S2.begin(), S2.end() );
153 SECTION(
" - benchmark set operators |" )
157 Size size_A = A.size();
158 Size size_B = B.size();
159 Size size_AorB = AorB.size();
164 TEMPLATE_TEST_CASE(
"SetFunctions benchmark operator & (sequences)",
"[set_functions]",
167 typedef typename TestType::size_type
Size;
169 for (
int i = 0; i < NB; ++i ) S1.insert( randomNB( ) );
171 for (
int i = 0; i < NB; ++i ) S2.insert( randomNB( ) );
172 TestType A( S1.begin(), S1.end() );
173 TestType B( S2.begin(), S2.end() );
176 std::random_shuffle( A.begin(), A.end() );
177 std::random_shuffle( B.begin(), B.end() );
179 SECTION(
" - benchmark set operators &" )
183 Size size_A = A.size();
184 Size size_B = B.size();
185 Size size_AandB = AandB.size();
186 REQUIRE( size_AandB <= std::min( size_A, size_B ) );
191 std::unordered_set<int> )
193 typedef typename TestType::size_type
Size;
195 for (
int i = 0; i < NB; ++i ) S1.insert( randomNB( ) );
197 for (
int i = 0; i < NB; ++i ) S2.insert( randomNB( ) );
198 TestType A( S1.begin(), S1.end() );
199 TestType B( S2.begin(), S2.end() );
202 SECTION(
" - benchmark set operators &" )
206 Size size_A = A.size();
207 Size size_B = B.size();
208 Size size_AandB = AandB.size();
209 REQUIRE( size_AandB <= std::min( size_A, size_B ) );
214 TEMPLATE_TEST_CASE(
"SetFunctions benchmark operator - (sequences)",
"[set_functions]",
217 typedef typename TestType::size_type
Size;
219 for (
int i = 0; i < NB; ++i ) S1.insert( randomNB( ) );
221 for (
int i = 0; i < NB; ++i ) S2.insert( randomNB( ) );
222 TestType A( S1.begin(), S1.end() );
223 TestType B( S2.begin(), S2.end() );
226 std::random_shuffle( A.begin(), A.end() );
227 std::random_shuffle( B.begin(), B.end() );
229 SECTION(
" - benchmark set operators -" )
233 Size size_A = A.size();
234 Size size_B = B.size();
235 Size size_AminusB = AminusB.size();
236 REQUIRE( size_AminusB <= size_A );
237 boost::ignore_unused_variable_warning(size_B);
242 std::unordered_set<int> )
244 typedef typename TestType::size_type
Size;
246 for (
int i = 0; i < NB; ++i ) S1.insert( randomNB( ) );
248 for (
int i = 0; i < NB; ++i ) S2.insert( randomNB( ) );
249 TestType A( S1.begin(), S1.end() );
250 TestType B( S2.begin(), S2.end() );
253 SECTION(
" - benchmark set operators -" )
257 Size size_A = A.size();
258 Size size_B = B.size();
259 Size size_AminusB = AminusB.size();
260 REQUIRE( size_AminusB <= size_A );
261 boost::ignore_unused_variable_warning(size_B);
266 TEMPLATE_TEST_CASE(
"SetFunctions benchmark operator ^ (sequences)",
"[set_functions]",
269 typedef typename TestType::size_type
Size;
271 for (
int i = 0; i < NB; ++i ) S1.insert( randomNB( ) );
273 for (
int i = 0; i < NB; ++i ) S2.insert( randomNB( ) );
274 TestType A( S1.begin(), S1.end() );
275 TestType B( S2.begin(), S2.end() );
278 std::random_shuffle( A.begin(), A.end() );
279 std::random_shuffle( B.begin(), B.end() );
281 SECTION(
" - benchmark set operators ^" )
285 Size size_A = A.size();
286 Size size_B = B.size();
287 Size size_AxorB = AxorB.size();
293 std::unordered_set<int> )
295 typedef typename TestType::size_type
Size;
297 for (
int i = 0; i < NB; ++i ) S1.insert( randomNB( ) );
299 for (
int i = 0; i < NB; ++i ) S2.insert( randomNB( ) );
300 TestType A( S1.begin(), S1.end() );
301 TestType B( S2.begin(), S2.end() );
304 SECTION(
" - benchmark set operators ^" )
308 Size size_A = A.size();
309 Size size_B = B.size();
310 Size size_AxorB = AxorB.size();
Container operator|(const Container &S1, const Container &S2)
functions namespace gathers all DGtal functionsxs.
bool isEqual(const Container &S1, const Container &S2)
bool isSubset(const Container &S1, const Container &S2)
DGtal is the top-level namespace which contains all DGtal functions and types.
HalfEdgeDataStructure::Size Size
TEMPLATE_TEST_CASE("Star shapes", "move() method", AccFlower, Astroid, Ball, Ellipse, Flower, Lemniscate, NGon, BallImplicit, HyperCubeImplicit, Norm1BallImplicit, RoundedHyperCubeImplicit)
SECTION("Testing constant forward iterators")
REQUIRE(domain.isInside(aPoint))