-
Notifications
You must be signed in to change notification settings - Fork 84
/
debug.cpp
178 lines (145 loc) · 3.49 KB
/
debug.cpp
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#include <iostream>
#include <limits>
#include "debug.h"
void DEBUG_RUN_TESTS(float *x, float *y, float *mass, int *count, int *start, int *sorted, int *child, float *left, float *right, float *bottom, float *top, int n, int m)
{
long test; // parameter determining whether test passed or failed
//***********************************************************************
// x, y, & mass array tests
//***********************************************************************
//***********************************************************************
// count array tests
//***********************************************************************
// test 1
test = 1;
for(int i=n;i<m;i++){
int c = count[i];
for(int j=0;j<4;j++){
if(child[4*i + j] != -1){
c -= count[child[4*i + j]];
}
}
if(c != 0){
test = 0;
}
}
if(test == 1){
std::cout<<"COUNT ARRAY TEST 1 RESULT = PASS: "<<std::endl;
}
else{
std::cout<<"COUNT ARRAY TEST 1 RESULT = FAIL: "<<std::endl;
}
//***********************************************************************
// child array tests
//***********************************************************************
// test 1
test = 0;
for(int j=0;j<4*m;j++){
if(child[j] >=0 && child[j] < n){
test += child[j];
}
}
if(test == (long)n*(long)(n-1)/2){
std::cout<<"CHILD ARRAY TEST 1 RESULT = PASS: "<<std::endl;
}
else{
std::cout<<"CHILD ARRAY TEST 1 RESULT = FAIL: "<<std::endl;
}
// test 2
test = 1;
for(int i=0;i<4*m;i++){
if(child[i] >= m){
test = 0;
}
}
if(test == 1){
std::cout<<"CHILD ARRAY TEST 2 RESULT = PASS: "<<std::endl;
}
else{
std::cout<<"CHILD ARRAY TEST 2 RESULT = FAIL: "<<std::endl;
}
// test 3
test = 1;
for(int i=0;i<4*m;i++){
if(child[i] < -1){
test = 0;
}
}
if(test == 1){
std::cout<<"CHILD ARRAY TEST 3 RESULT = PASS: "<<std::endl;
}
else{
std::cout<<"CHILD ARRAY TEST 3 RESULT = FAIL: "<<std::endl;
}
// test 4
int min = 2*n;
for(int i=0;i<4;i++){
if(child[i] < min){
min = child[i];
}
}
test = 1;
for(int i=4;i<4*(min-1);i++){
if(child[i] != -1){
test = 0;
}
}
if(test == 1){
std::cout<<"CHILD ARRAY TEST 4 RESULT = PASS: "<<std::endl;
}
else{
std::cout<<"CHILD ARRAY TEST 4 RESULT = FAIL: "<<std::endl;
}
//***********************************************************************
// sorted array tests
//***********************************************************************
// test 1
test = 0;
for(int i=0;i<m;i++){
test += sorted[i];
}
if(test == (long)n*(long)(n-1)/2){
std::cout<<"SORTED ARRAY TEST 1 RESULT = PASS: "<<std::endl;
}
else{
std::cout<<"SORTED ARRAY TEST 1 RESULT = FAIL: "<<std::endl;
}
// test 2
int *test_array = new int[n];
for(int i=0;i<n;i++){
test_array[i] = -1;
}
for(int i=0;i<n;i++){
test_array[sorted[i]] = 1;
}
test = 1;
for(int i=0;i<n;i++){
if(test_array[i] != 1){
test = 0;
}
}
delete [] test_array;
if(test == 1){
std::cout<<"SORTED ARRAY TEST 2 RESULT = PASS: "<<std::endl;
}
else{
std::cout<<"SORTED ARRAY TEST 2 RESULT = FAIL: "<<std::endl;
}
//***********************************************************************
// left, right, bottom, and top bounding region tests
//***********************************************************************
// test 1
test = 1;
if(*left > *right){
test = 0;
}
if(*bottom > *top){
test = 0;
}
if(test == 1){
std::cout<<"BOUNDING BOX TEST 1 RESULT = PASS: "<<std::endl;
}
else{
std::cout<<"BOUNDING BOX TEST 1 RESULT = FAIL: "<<std::endl;
}
}