34#include "DGtal/base/Common.h"
35#include "DGtal/kernel/IntegralIntervals.h"
36#include "DGtalCatch.h"
47SCENARIO(
"IntegralIntervals< int > unit tests",
"[intervals]" )
53 WHEN(
"Inserting many intervals" ) {
58 for (
int i = 0; i < nb; i++ )
60 int f = rand() % 1000;
61 int l = std::min( f + rand() % 10, 999 );
64 for (
int k = f; k <= l; k++ ) X.insert( k );
65 nb_ok += V.isValid() ? 1 : 0;
66 nb_count_ok += ( V.size() == X.size() ) ? 1 : 0;
68 std::cout << V <<
" => " << ( V.isValid() ?
"OK" :
"ERROR" ) << std::endl;
69 if ( V.size() != X.size() )
71 std::cout <<
"Bad count #V=" << V.size() <<
" #X=" << X.size()
73 for (
auto i : X ) std::cout <<
" " << i;
74 std::cout << std::endl;
78 THEN(
"The object remains consistent." ) {
84 WHEN(
"Erasing many intervals" ) {
90 for (
int i = 0; i < 1000; i++ ) X.insert( i );
91 for (
int i = 0; i < nb; i++ )
93 int f = rand() % 1000;
94 int l = std::min( f + rand() % 10, 999 );
97 for (
int k = f; k <= l; k++ ) X.erase( k );
98 nb_ok += V.isValid() ? 1 : 0;
99 nb_count_ok += ( V.size() == X.size() ) ? 1 : 0;
101 std::cout << V <<
" => " << ( V.isValid() ?
"OK" :
"ERROR" ) << std::endl;
102 if ( V.size() != X.size() )
104 std::cout <<
"Bad count #V=" << V.size() <<
" #X=" << X.size()
106 for (
auto i : X ) std::cout <<
" " << i;
107 std::cout << std::endl;
111 THEN(
"The object remains consistent." ) {
118SCENARIO(
"IntegralIntervals< int > set operations tests",
"[intervals]" )
124 for (
int i = 0; i < 1000; i++ ) X.
insert( rand() % 1000 );
125 for (
int i = 0; i < 1000; i++ ) Y.insert( rand() % 1000 );
126 Intervals A( X.cbegin(), X.cend() );
127 Intervals B( Y.cbegin(), Y.cend() );
128 std::vector< int > X_cup_Y, X_cap_Y, X_minus_Y, X_delta_Y;
129 std::set_union( X.cbegin(), X.cend(), Y.cbegin(), Y.cend(),
130 std::back_inserter( X_cup_Y ) );
131 std::set_intersection( X.cbegin(), X.cend(), Y.cbegin(), Y.cend(),
132 std::back_inserter( X_cap_Y ) );
133 std::set_difference( X.cbegin(), X.cend(), Y.cbegin(), Y.cend(),
134 std::back_inserter( X_minus_Y ) );
135 std::set_symmetric_difference( X.cbegin(), X.cend(), Y.cbegin(), Y.cend(),
136 std::back_inserter( X_delta_Y ) );
137 Intervals A_cup_B = A.set_union( B );
138 Intervals A_cap_B = A.set_intersection( B );
139 Intervals A_minus_B = A.set_difference( B );
140 Intervals A_delta_B = A.set_symmetric_difference( B );
141 bool A_cup_B_subset_A_cup_B = A_cup_B.includes( A_cup_B );
142 bool A_subset_A_cup_B = A_cup_B.includes( A );
143 bool B_subset_A_cup_B = A_cup_B.includes( B );
144 bool A_cap_B_subset_A_cup_B = A_cup_B.includes( A_cap_B );
145 bool A_minus_B_subset_A = A.includes( A_minus_B );
146 bool A_delta_B_subset_A_cup_B = A_cup_B.includes( A_delta_B );
147 bool A_delta_B_subset_A = A.includes( A_delta_B );
148 bool A_delta_B_subset_B = B.includes( A_delta_B );
149 THEN(
"Interval can be constructed from sets" ) {
150 REQUIRE( X.size() == A.size() );
151 REQUIRE( Y.size() == B.size() );
153 THEN(
"Set operations on intervals are correct" ) {
154 REQUIRE( X_cup_Y.size() == A_cup_B.size() );
155 REQUIRE( X_cap_Y.size() == A_cap_B.size() );
156 REQUIRE( X_minus_Y.size() == A_minus_B.size() );
157 REQUIRE( X_delta_Y.size() == A_delta_B.size() );
159 THEN(
"Inclusions are correct" ) {
160 REQUIRE( A_cup_B.includes( A_cup_B ) );
161 REQUIRE( A_cup_B.includes( A ) );
162 REQUIRE( ! A_cup_B.equals( A ) );
163 REQUIRE( ! A.includes( A_cup_B ) );
164 REQUIRE( A_cup_B.includes( B ) );
165 REQUIRE( ! B.includes( A_cup_B ) );
166 REQUIRE( ! B.equals( A_cup_B ) );
167 REQUIRE( A_cup_B.includes( A_cap_B ) );
168 REQUIRE( ! A_cap_B.includes( A_cup_B ) );
169 REQUIRE( A.includes( A_minus_B ) );
170 REQUIRE( ! A_minus_B.includes( A ) );
171 REQUIRE( A_cup_B.includes( A_delta_B ) );
172 REQUIRE( ! A_delta_B.includes( A_cup_B ) );
173 REQUIRE( ! A.includes( A_delta_B ) );
174 REQUIRE( ! B.includes( A_delta_B ) );
Point::Coordinate Integer
DGtal is the top-level namespace which contains all DGtal functions and types.
REQUIRE(domain.isInside(aPoint))
SCENARIO("UnorderedSetByBlock< PointVector< 2, int > unit tests with 32 bits blocks", "[unorderedsetbyblock][2d]")