MCPcopy Create free account
hub / github.com/SuprDewd/CompetitiveProgramming / test

Function test

code/data-structures/kd_tree.test.cpp:77–194  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

75#define TREE2 1
76
77void test() {
78 /* Field testing: UVa 10245 */
79
80 for (int t = 0; t < 100; t++) {
81 // printf("%d\n", t);
82
83 int startcnt = rng() % 1000;
84
85 vector<kd_tree<CURK>::pt> pts1(startcnt);
86 vector<naive_kd_tree<CURK>::point> pts2(startcnt);
87
88 for (int i = 0; i < startcnt; i++) {
89 randomize_pt();
90 pts1[i] = kd_tree<CURK>::pt(pt);
91 pts2[i] = naive_kd_tree<CURK>::point(pt);
92 }
93
94#if TREE1
95 kd_tree<CURK> tree1(pts1);
96#endif
97
98#if TREE2
99 naive_kd_tree<CURK> tree2(pts2);
100#endif
101
102 for (int i = 0; i < startcnt; i++) {
103#if TREE1
104 assert(tree1.contains(pts1[i]));
105#endif
106
107#if TREE2
108 assert(tree2.contains(pts2[i]));
109#endif
110 }
111
112 int ops = 1000;
113 int found = 0;
114 for (int cop = 0; cop < ops; cop++) {
115 int op = rng() % 3;
116
117 if (op == 0) {
118 // insert
119 randomize_pt();
120#if TREE1
121 tree1.insert(kd_tree<CURK>::pt(pt));
122#endif
123
124#if TREE2
125 tree2.insert(naive_kd_tree<CURK>::point(pt));
126#endif
127 } else if (op == 1) {
128 // contains
129 randomize_pt();
130#if TREE1
131 bool a = tree1.contains(kd_tree<CURK>::pt(pt));
132#endif
133
134#if TREE2

Callers

nothing calls this directly

Calls 9

randomize_ptFunction · 0.85
ptClass · 0.85
dist_toMethod · 0.80
pointClass · 0.70
containsMethod · 0.45
insertMethod · 0.45
nearest_neighbourMethod · 0.45
distMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected