@@ -99,6 +99,44 @@ BOOST_AUTO_TEST_CASE(TimedGrid_1D_withtime) {
9999 }
100100}
101101
102+ BOOST_AUTO_TEST_CASE (TimedGrid_1D_duplicate_cells) {
103+ // Cells with same position but time difference larger than tolerance should
104+ // not be considered duplicates
105+ CellCollection cells = {Cell (0ul , 0 , 0 , 0.0 ), Cell (1ul , 0 , 0 , 1.0 )};
106+ ClusterCollection clusters;
107+ Ccl::ClusteringData data;
108+
109+ Ccl::createClusters<CellCollection, ClusterCollection, 1 >(
110+ data, cells, clusters, Ccl::TimedConnect<Cell, 1 >(0.5 ));
111+ BOOST_CHECK_EQUAL (2ul , clusters.size ());
112+
113+ // Cells with same position and time difference within tolerance should be
114+ // considered duplicates
115+ cells = {Cell (0ul , 0 , 0 , 0.0 ), Cell (1ul , 0 , 0 , 0.4 )};
116+ clusters.clear ();
117+ data.clear ();
118+
119+ BOOST_CHECK_THROW (
120+ (Ccl::createClusters<CellCollection, ClusterCollection, 1 >(
121+ data, cells, clusters, Ccl::TimedConnect<Cell, 1 >(0.5 ))),
122+ std::invalid_argument);
123+ }
124+
125+ BOOST_AUTO_TEST_CASE (TimedGrid_1D_space_and_time) {
126+ // Cells with the same position but large time differences are not duplicates.
127+ // However, they can still be clustered through a neighboring cell if it is
128+ // within the time tolerance for both.
129+ CellCollection cells = {Cell (0ul , 0 , 0 , 0.0 ), Cell (1ul , 1 , 0 , 0.4 ),
130+ Cell (2ul , 0 , 0 , 0.8 )};
131+ ClusterCollection clusters;
132+ Ccl::ClusteringData data;
133+
134+ Ccl::createClusters<CellCollection, ClusterCollection, 1 >(
135+ data, cells, clusters, Ccl::TimedConnect<Cell, 1 >(0.5 ));
136+ BOOST_CHECK_EQUAL (1ul , clusters.size ());
137+ BOOST_CHECK_EQUAL (clusters[0 ].ids .size (), 3ul );
138+ }
139+
102140BOOST_AUTO_TEST_CASE (TimedGrid_2D_notime) {
103141 // 4x4 matrix
104142 /*
@@ -262,4 +300,72 @@ BOOST_AUTO_TEST_CASE(TimedGrid_2D_noTollerance) {
262300 }
263301}
264302
303+ BOOST_AUTO_TEST_CASE (TimedGrid_2D_duplicate_cells) {
304+ // Cells with same position but time difference larger than tolerance should
305+ // not be considered duplicates
306+ CellCollection cells = {Cell (0ul , 0 , 0 , 0.0 ), Cell (1ul , 0 , 0 , 1.0 )};
307+ ClusterCollection clusters;
308+ Ccl::ClusteringData data;
309+
310+ Ccl::createClusters<CellCollection, ClusterCollection, 2 >(
311+ data, cells, clusters, Ccl::TimedConnect<Cell, 2 >(0.5 ));
312+ BOOST_CHECK_EQUAL (2ul , clusters.size ());
313+
314+ // Cells with same position and time difference within tolerance should be
315+ // considered duplicates
316+ cells = {Cell (0ul , 0 , 0 , 0.0 ), Cell (1ul , 0 , 0 , 0.4 )};
317+ clusters.clear ();
318+ data.clear ();
319+
320+ BOOST_CHECK_THROW (
321+ (Ccl::createClusters<CellCollection, ClusterCollection, 2 >(
322+ data, cells, clusters, Ccl::TimedConnect<Cell, 2 >(0.5 ))),
323+ std::invalid_argument);
324+ }
325+
326+ BOOST_AUTO_TEST_CASE (TimedGrid_2D_space_and_time_conn4) {
327+ // Cells with the same position but large time differences are not duplicates.
328+ // However, they can still be clustered through a neighboring cell if it is
329+ // within the time tolerance for both:
330+ // 3x3 matrix
331+ /*
332+ O X/Z O
333+ X/Z Y X/Z
334+ O X/Z O
335+ */
336+ CellCollection cells = {
337+ Cell (0ul , 1 , 0 , 0.0 ), Cell (1ul , 0 , 1 , 0.0 ), Cell (2ul , 2 , 1 , 0.0 ),
338+ Cell (3ul , 1 , 2 , 0.0 ), Cell (4ul , 1 , 0 , 0.8 ), Cell (5ul , 0 , 1 , 0.8 ),
339+ Cell (6ul , 2 , 1 , 0.8 ), Cell (7ul , 1 , 2 , 0.8 ), Cell (8ul , 1 , 1 , 0.4 )};
340+ ClusterCollection clusters;
341+ Ccl::ClusteringData data;
342+
343+ Ccl::createClusters<CellCollection, ClusterCollection, 2 >(
344+ data, cells, clusters, Ccl::TimedConnect<Cell, 2 >(0.5 , false ));
345+ BOOST_CHECK_EQUAL (1ul , clusters.size ());
346+ BOOST_CHECK_EQUAL (clusters[0 ].ids .size (), 9ul );
347+ }
348+
349+ BOOST_AUTO_TEST_CASE (TimedGrid_2D_space_and_time_conn8) {
350+ // Cells with the same position but large time differences are not duplicates.
351+ // However, they can still be clustered through a neighboring cell if it is
352+ // within the time tolerance for both:
353+ // 3x3 matrix
354+ /*
355+ Z X O
356+ X Y O
357+ X/Z O O
358+ */
359+ CellCollection cells = {Cell (0ul , 0 , 0 , 0.0 ), Cell (1ul , 0 , 2 , 0.0 ),
360+ Cell (2ul , 1 , 0 , 0.8 ), Cell (3ul , 0 , 1 , 0.8 ),
361+ Cell (4ul , 0 , 2 , 0.8 ), Cell (5ul , 1 , 1 , 0.4 )};
362+ ClusterCollection clusters;
363+ Ccl::ClusteringData data;
364+
365+ Ccl::createClusters<CellCollection, ClusterCollection, 2 >(
366+ data, cells, clusters, Ccl::TimedConnect<Cell, 2 >(0.5 , true ));
367+ BOOST_CHECK_EQUAL (1ul , clusters.size ());
368+ BOOST_CHECK_EQUAL (clusters[0 ].ids .size (), 6ul );
369+ }
370+
265371BOOST_AUTO_TEST_SUITE_END ()
0 commit comments