DGtal 1.4.0
Loading...
Searching...
No Matches
testIntegralIntervals.cpp File Reference
#include <iostream>
#include <vector>
#include <algorithm>
#include "DGtal/base/Common.h"
#include "DGtal/kernel/IntegralIntervals.h"
#include "DGtalCatch.h"
Include dependency graph for testIntegralIntervals.cpp:

Go to the source code of this file.

Functions

 SCENARIO ("IntegralIntervals< int > unit tests", "[intervals]")
 
 SCENARIO ("IntegralIntervals< int > set operations tests", "[intervals]")
 

Detailed Description

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Author
Jacques-Olivier Lachaud (jacqu.nosp@m.es-o.nosp@m.livie.nosp@m.r.la.nosp@m.chaud.nosp@m.@uni.nosp@m.v-sav.nosp@m.oie..nosp@m.fr ) Laboratory of Mathematics (CNRS, UMR 5127), University of Savoie, France
Date
2022/07/01

Functions for testing class IntegralIntervals.

This file is part of the DGtal library.

Definition in file testIntegralIntervals.cpp.

Function Documentation

◆ SCENARIO() [1/2]

SCENARIO ( "IntegralIntervals< int > set operations tests" ,
"" [intervals] )

Definition at line 118 of file testIntegralIntervals.cpp.

119{
120 typedef int Integer;
121 typedef IntegralIntervals< Integer > Intervals;
122
123 std::set< int > X,Y;
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() );
144 }
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() );
150 }
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 ) );
167 }
168}
REQUIRE(domain.isInside(aPoint))

References REQUIRE().

◆ SCENARIO() [2/2]

SCENARIO ( "IntegralIntervals< int > unit tests" ,
"" [intervals] )

Definition at line 47 of file testIntegralIntervals.cpp.

48{
49 typedef int Integer;
50 typedef IntegralIntervals< Integer > Intervals;
51
52 Intervals V;
53 WHEN( "Inserting many intervals" ) {
54 int nb = 1000;
55 int nb_ok = 0;
56 int nb_count_ok = 0;
57 std::set< int > X;
58 for ( int i = 0; i < nb; i++ )
59 {
60 int f = rand() % 1000;
61 int l = std::min( f + rand() % 10, 999 );
62 // std::cout << "V + (" << f << "," << l << ") = ";
63 V.insert( f, l );
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;
67 if ( ! V.isValid() )
68 std::cout << V << " => " << ( V.isValid() ? "OK" : "ERROR" ) << std::endl;
69 if ( V.size() != X.size() )
70 {
71 std::cout << "Bad count #V=" << V.size() << " #X=" << X.size()
72 << std::endl;
73 for ( auto j : X ) std::cout << " " << j;
74 std::cout << std::endl;
75 break;
76 }
77 }
78 THEN( "The object remains consistent." ) {
79 REQUIRE( nb == nb_ok );
80 REQUIRE( nb == nb_count_ok );
81 }
82 }
83
84 WHEN( "Erasing many intervals" ) {
85 int nb = 1000;
86 int nb_ok = 0;
87 int nb_count_ok = 0;
88 std::set< int > X;
89 V.insert( 0, 999 );
90 for ( int i = 0; i < 1000; i++ ) X.insert( i );
91 for ( int i = 0; i < nb; i++ )
92 {
93 int f = rand() % 1000;
94 int l = std::min( f + rand() % 10, 999 );
95 // std::cout << "V + (" << f << "," << l << ") = ";
96 V.erase( f, l );
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;
100 if ( ! V.isValid() )
101 std::cout << V << " => " << ( V.isValid() ? "OK" : "ERROR" ) << std::endl;
102 if ( V.size() != X.size() )
103 {
104 std::cout << "Bad count #V=" << V.size() << " #X=" << X.size()
105 << std::endl;
106 for ( auto j : X ) std::cout << " " << j;
107 std::cout << std::endl;
108 break;
109 }
110 }
111 THEN( "The object remains consistent." ) {
112 REQUIRE( nb == nb_ok );
113 REQUIRE( nb == nb_count_ok );
114 }
115 }
116}
STL namespace.

References REQUIRE().