-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_dbscan_2.c
44 lines (35 loc) · 1.65 KB
/
test_dbscan_2.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <time.h>
#include <string.h>
#include "quadtree.h"
#include "dbscan.h"
int main(int argc, char **argv) {
QUADTREE *ref = NULL;
unsigned int clusters[6];
unsigned int expected_clusters1[] = {0,0,0,0,0,0};
unsigned int expected_clusters2[] = {1,1,1,1,2,2};
unsigned int expected_clusters3[] = {1,1,1,1,0,0};
assert(!quadtree_init(&ref, 7, 7));
// x is the document, y is the label
assert(quadtree_insert(ref, 0, 1));
assert(quadtree_insert(ref, 1, 1)); // Expect the distance between 0 and 1 to be 0.5
assert(quadtree_insert(ref, 1, 3)); // Expect the distance between 1 and 2 to be 0.5
assert(quadtree_insert(ref, 2, 0)); // Expect the distance between 2 and 3 to be 0.5
assert(quadtree_insert(ref, 2, 3)); // Expect the distance between 3 and 4 to be 0
assert(quadtree_insert(ref, 3, 0)); // Expect the distnace between 4 and 5 to be 0.5
assert(quadtree_insert(ref, 4, 2));
assert(quadtree_insert(ref, 5, 2));
assert(quadtree_insert(ref, 5, 4));
for (int i = 0; i < 6; i++) clusters[i] = i;
assert(!DBSCAN(ref, clusters, 6, 0.005f, 2, &neighbours_search));
assert(!memcmp(clusters, expected_clusters1, sizeof(unsigned int) * 6));
for (int i = 0; i < 6; i++) clusters[i] = i;
assert(!DBSCAN(ref, clusters, 6, 0.67f, 2, &neighbours_search));
assert(!memcmp(clusters, expected_clusters2, sizeof(unsigned int) * 6));
for (int i = 0; i < 6; i++) clusters[i] = i;
assert(!DBSCAN(ref, clusters, 6, 0.67f, 3, &neighbours_search));
assert(!memcmp(clusters, expected_clusters3, sizeof(unsigned int) * 6));
return 0;
}