13 #include "CUnit/Basic.h"
15 #include "../lwunionfind.h"
22 uint32_t expected_initial_ids[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
23 uint32_t expected_initial_sizes[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
42 uint32_t expected_final_ids[] = { 0, 2, 2, 2, 4, 5, 6, 0, 0, 9 };
43 uint32_t expected_final_sizes[] = { 3, 0, 3, 0, 1, 1, 1, 0, 0, 1 };
55 uint32_t final_clusters[] = { 0, 2, 2, 2, 4, 5, 6, 0, 0, 2 };
56 uint32_t final_sizes[] = { 3, 0, 4, 0, 1, 1, 1, 0, 0, 0 };
63 .clusters = final_clusters,
64 .cluster_sizes = final_sizes
69 char encountered_cluster[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
72 for (i = 0; i < uf.
N; i++)
74 uint32_t c = final_clusters[ids_by_cluster[i]];
75 if (!encountered_cluster[c])
77 encountered_cluster[c] = 1;
83 uint32_t c_prev = final_clusters[ids_by_cluster[i-1]];
84 CU_ASSERT_EQUAL(c, c_prev);
103 for (i = 0; i < uf->
N; i++)
107 CU_ASSERT_EQUAL(root, uf->
clusters[i]);
143 uint32_t expected_collapsed_ids[] = { 2, 0, 0, 0, 1, 0, 2, 1, 2, 1 };
150 char is_in_cluster[] = { 0, 1, 1, 1, 0, 1, 0, 0, 0, 0 };
151 uint32_t expected_collapsed_ids2[] = { 8, 0, 0, 0, 7, 0, 8, 7, 8, 7 };
155 for (i = 0; i < uf->
N; i++)
157 if (is_in_cluster[i])
168 CU_pSuite suite = CU_add_suite(
"clustering_unionfind", NULL, NULL);
void unionfind_suite_setup(void)
static void test_unionfind_union(void)
static void test_unionfind_ordered_by_cluster(void)
static void test_unionfind_collapse_cluster_ids(void)
static void test_unionfind_create(void)
static void test_unionfind_path_compression(void)
#define ASSERT_INT_EQUAL(o, e)
#define ASSERT_INTARRAY_EQUAL(o, e, n)
#define PG_ADD_TEST(suite, testfunc)
uint32_t * UF_get_collapsed_cluster_ids(UNIONFIND *uf, const char *is_in_cluster)
void UF_destroy(UNIONFIND *uf)
uint32_t UF_find(UNIONFIND *uf, uint32_t i)
UNIONFIND * UF_create(uint32_t N)
uint32_t * UF_ordered_by_cluster(UNIONFIND *uf)
void UF_union(UNIONFIND *uf, uint32_t i, uint32_t j)