From fe66646deb3f2111948a36438c30d74464b7a082 Mon Sep 17 00:00:00 2001 From: Paul Ramsey Date: Tue, 30 Jun 2015 20:48:13 +0000 Subject: [PATCH] CUnit test case fix from dbaston git-svn-id: http://svn.osgeo.org/postgis/trunk@13769 b70326c6-7e19-0410-871a-916f4a2858ee --- liblwgeom/cunit/cu_unionfind.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/liblwgeom/cunit/cu_unionfind.c b/liblwgeom/cunit/cu_unionfind.c index e30a4efce..5f679b9e5 100644 --- a/liblwgeom/cunit/cu_unionfind.c +++ b/liblwgeom/cunit/cu_unionfind.c @@ -64,19 +64,34 @@ static void test_unionfind_ordered_by_cluster(void) .cluster_sizes = final_sizes }; - uint32_t* actual_ids_by_cluster = UF_ordered_by_cluster(&uf); - // uint32_t expected_ids_by_cluster[] = { 0, 7, 8, 1, 2, 3, 9, 4, 5, 6 }; + uint32_t* ids_by_cluster = UF_ordered_by_cluster(&uf); - // CU_ASSERT_EQUAL(0, memcmp(actual_ids_by_cluster, expected_ids_by_cluster, 10 * sizeof(uint32_t))); + char encountered_cluster[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - lwfree(actual_ids_by_cluster); + uint32_t i; + for (i = 0; i < uf.N; i++) + { + uint32_t c = final_clusters[ids_by_cluster[i]]; + if (!encountered_cluster[c]) + { + encountered_cluster[c] = 1; + } + else + { + /* If we've seen an element of this cluster before, then the + * current cluster must be the same as the previous cluster. */ + uint32_t c_prev = final_clusters[ids_by_cluster[i-1]]; + CU_ASSERT_EQUAL(c, c_prev); + } + } + lwfree(ids_by_cluster); } void unionfind_suite_setup(void); void unionfind_suite_setup(void) { CU_pSuite suite = CU_add_suite("Clustering Union-Find", NULL, NULL); - PG_ADD_TEST(suite, test_unionfind_create), - PG_ADD_TEST(suite, test_unionfind_union), - PG_ADD_TEST(suite, test_unionfind_ordered_by_cluster); + PG_ADD_TEST(suite, test_unionfind_create); + PG_ADD_TEST(suite, test_unionfind_union); + PG_ADD_TEST(suite, test_unionfind_ordered_by_cluster); } -- 2.40.0