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 j : X ) std::cout <<
" " << j;
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 j : X ) std::cout <<
" " << j;
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 THEN(
"Interval can be constructed from sets" ) {
142 REQUIRE( X.size() == A.size() );
143 REQUIRE( Y.size() == B.size() );
145 THEN(
"Set operations on intervals are correct" ) {
146 REQUIRE( X_cup_Y.size() == A_cup_B.size() );
147 REQUIRE( X_cap_Y.size() == A_cap_B.size() );
148 REQUIRE( X_minus_Y.size() == A_minus_B.size() );
149 REQUIRE( X_delta_Y.size() == A_delta_B.size() );
151 THEN(
"Inclusions are correct" ) {
152 REQUIRE( A_cup_B.includes( A_cup_B ) );
153 REQUIRE( A_cup_B.includes( A ) );
154 REQUIRE( ! A_cup_B.equals( A ) );
155 REQUIRE( ! A.includes( A_cup_B ) );
156 REQUIRE( A_cup_B.includes( B ) );
157 REQUIRE( ! B.includes( A_cup_B ) );
158 REQUIRE( ! B.equals( A_cup_B ) );
159 REQUIRE( A_cup_B.includes( A_cap_B ) );
160 REQUIRE( ! A_cap_B.includes( A_cup_B ) );
161 REQUIRE( A.includes( A_minus_B ) );
162 REQUIRE( ! A_minus_B.includes( A ) );
163 REQUIRE( A_cup_B.includes( A_delta_B ) );
164 REQUIRE( ! A_delta_B.includes( A_cup_B ) );
165 REQUIRE( ! A.includes( A_delta_B ) );
166 REQUIRE( ! B.includes( A_delta_B ) );