PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ test_unionfind_union()

static void test_unionfind_union ( void  )
static

Definition at line 33 of file cu_unionfind.c.

References ASSERT_INT_EQUAL, ASSERT_INTARRAY_EQUAL, UNIONFIND::cluster_sizes, UNIONFIND::clusters, UNIONFIND::N, UNIONFIND::num_clusters, UF_create(), UF_destroy(), and UF_union().

Referenced by unionfind_suite_setup().

34 {
35  UNIONFIND *uf = UF_create(10);
36 
37  UF_union(uf, 0, 7); /* both have size = 1, so 7 becomes 0 */
38  UF_union(uf, 3, 2); /* both have size = 1, so 3 becomes 2 */
39  UF_union(uf, 8, 7); /* add 8 (smaller) to 0-7 (larger) */
40  UF_union(uf, 1, 2); /* add 1 (smaller) to 2-3 (larger) */
41 
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 };
44 
45  ASSERT_INT_EQUAL(uf->N, 10);
47  ASSERT_INTARRAY_EQUAL(uf->clusters, expected_final_ids, 10);
48  ASSERT_INTARRAY_EQUAL(uf->cluster_sizes, expected_final_sizes, 10);
49 
50  UF_destroy(uf);
51 }
void UF_destroy(UNIONFIND *uf)
Definition: lwunionfind.c:53
uint32_t * clusters
Definition: lwunionfind.h:33
uint32_t * cluster_sizes
Definition: lwunionfind.h:34
uint32_t N
Definition: lwunionfind.h:36
unsigned int uint32_t
Definition: uthash.h:78
#define ASSERT_INT_EQUAL(o, e)
uint32_t num_clusters
Definition: lwunionfind.h:35
UNIONFIND * UF_create(uint32_t N)
Definition: lwunionfind.c:34
#define ASSERT_INTARRAY_EQUAL(o, e, n)
void UF_union(UNIONFIND *uf, uint32_t i, uint32_t j)
Definition: lwunionfind.c:84
Here is the call graph for this function:
Here is the caller graph for this function: