PostGIS  2.5.0beta1dev-r@@SVN_REVISION@@

◆ test_unionfind_collapse_cluster_ids()

static void test_unionfind_collapse_cluster_ids ( void  )
static

Definition at line 113 of file cu_unionfind.c.

References ASSERT_INT_EQUAL, ASSERT_INTARRAY_EQUAL, UNIONFIND::cluster_sizes, UNIONFIND::clusters, lwfree(), UNIONFIND::N, UF_create(), UF_destroy(), UF_get_collapsed_cluster_ids(), and unionfind_suite_setup().

Referenced by unionfind_suite_setup().

114 {
115  UNIONFIND* uf = UF_create(10);
116 
117  uf->clusters[0] = 8;
118  uf->clusters[1] = 5;
119  uf->clusters[2] = 5;
120  uf->clusters[3] = 5;
121  uf->clusters[4] = 7;
122  uf->clusters[5] = 5;
123  uf->clusters[6] = 8;
124  uf->clusters[7] = 7;
125  uf->clusters[8] = 8;
126  uf->clusters[9] = 7;
127 
128  uf->cluster_sizes[0] = 3;
129  uf->cluster_sizes[1] = 4;
130  uf->cluster_sizes[2] = 4;
131  uf->cluster_sizes[3] = 4;
132  uf->cluster_sizes[4] = 3;
133  uf->cluster_sizes[5] = 4;
134  uf->cluster_sizes[6] = 3;
135  uf->cluster_sizes[7] = 3;
136  uf->cluster_sizes[8] = 3;
137  uf->cluster_sizes[9] = 3;
138 
139  /* 5 -> 0
140  * 7 -> 1
141  * 8 -> 2
142  */
143  uint32_t expected_collapsed_ids[] = { 2, 0, 0, 0, 1, 0, 2, 1, 2, 1 };
144  uint32_t* collapsed_ids = UF_get_collapsed_cluster_ids(uf, NULL);
145 
146  ASSERT_INTARRAY_EQUAL(collapsed_ids, expected_collapsed_ids, 10);
147 
148  lwfree(collapsed_ids);
149 
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 };
152 
153  collapsed_ids = UF_get_collapsed_cluster_ids(uf, is_in_cluster);
154  uint32_t i;
155  for (i = 0; i < uf->N; i++)
156  {
157  if (is_in_cluster[i])
158  ASSERT_INT_EQUAL(expected_collapsed_ids2[i], collapsed_ids[i]);
159  }
160 
161  lwfree(collapsed_ids);
162  UF_destroy(uf);
163 }
void UF_destroy(UNIONFIND *uf)
Definition: lwunionfind.c:53
void lwfree(void *mem)
Definition: lwutil.c:244
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)
UNIONFIND * UF_create(uint32_t N)
Definition: lwunionfind.c:34
#define ASSERT_INTARRAY_EQUAL(o, e, n)
uint32_t * UF_get_collapsed_cluster_ids(UNIONFIND *uf, const char *is_in_cluster)
Definition: lwunionfind.c:145
Here is the call graph for this function:
Here is the caller graph for this function: