/
main-test.c
187 lines (153 loc) · 3.66 KB
/
main-test.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
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
179
180
181
182
183
184
185
186
#include "libutil.h"
#include "libset.h"
#define len 10
#define bsize 10
int
main(int argc, char **argv)
{
argc = 0;
argv = NULL;
int i = 0;
int found = 0;
/* test set funtionality */
uint64_t array1[len] = {3,4,7,8,10,13,15,23,27,30};
uint64_t array2[len] = {1,2,3,6,13,30,41,55,66,70};
/* test linear search */
while(i!=len)
{
if((linear_search(array1, len, array2[i]))==9)
{
printf("[LINEAR SEARCH] - Search last entry - OK\n");
}
if((linear_search(array1, len, array2[i]))==0)
{
printf("[LINEAR SEARCH] - Search first entry - OK\n");
}
if((linear_search(array1, len, array2[i]))==5)
{
printf("[LINEAR SEARCH] - Search middle entry - OK\n");
}
if((linear_search(array1, len, 31))!=-1)
{
found = 1;
}
i++;
}
if(found == 0)
{
printf("[LINEAR SEARCH] - Search larger entry - OK\n\n");
}
/* test binary search */
/* Refresh counters */
i = 0;
found = 0;
while(i!=len)
{
if((binary_search(array1, len, array2[i]))==9)
{
printf("[BINARY SEARCH] - Search last entry - OK\n");
}
if((binary_search(array1, len, array2[i]))==0)
{
printf("[BINARY SEARCH] - Search first entry - OK\n");
}
if((binary_search(array1, len, array2[i]))==5)
{
printf("[BINARY SEARCH] - Search middle entry - OK\n");
}
if((binary_search(array1, len, 31))!=-1)
{
found = 1;
}
i++;
}
if(found == 0)
{
printf("[BINARY SEARCH] - Search larger entry - OK\n\n");
}
/* test interpolation search */
/* Refresh counters */
i = 0;
found = 0;
while(i!=len)
{
if((interpolation_search(array1, len, array2[i]))==9)
{
printf("[INTERPOLATION SEARCH] - Search last entry - OK\n");
}
if((interpolation_search(array1, len, array2[i]))==0)
{
printf("[INTERPOLATION SEARCH] - Search first entry - OK\n");
}
if((interpolation_search(array1, len, array2[i]))==5)
{
printf("[INTERPOLATION SEARCH] - Search middle entry - OK\n");
}
if((interpolation_search(array1, len, 31))!=-1)
{
found = 1;
}
i++;
}
if(found == 0)
{
printf("[INTERPOLATION SEARCH] - Search larger entry - OK\n\n");
}
/* test exponential search */
/* Refresh counters */
i = 0;
found = 0;
while(i!=len)
{
if((exponential_search(array1, len, array2[i]))==9)
{
printf("[EXPONENTIAL SEARCH] - Search last entry - OK\n");
}
if((exponential_search(array1, len, array2[i]))==0)
{
printf("[EXPONENTIAL SEARCH] - Search first entry - OK\n");
}
if((exponential_search(array1, len, array2[i]))==5)
{
printf("[EXPONENTIAL SEARCH] - Search middle entry - OK\n");
}
if((exponential_search(array1, len, 31))!=-1)
{
found = 1;
}
i++;
}
if(found == 0)
{
printf("[EXPONENTIAL SEARCH] - Search larger entry - OK\n\n");
}
/* test block search */
/* Refresh counters */
i = 0;
found = 0;
while(i!=len)
{
if((block_search(array1, len, array2[i], bsize))==9)
{
printf("[BLOCK SEARCH] - Search last entry - OK\n");
}
if((block_search(array1, len, array2[i], bsize))==0)
{
printf("[BLOCK SEARCH] - Search first entry - OK\n");
}
if((block_search(array1, len, array2[i], bsize))==5)
{
printf("[BLOCK SEARCH] - Search middle entry - OK\n");
}
if((block_search(array1, len, 31, bsize))!=-1)
{
found = 1;
}
i++;
}
if(found == 0)
{
printf("[BLOCK SEARCH] - Search larger entry - OK\n\n");
}
return EXIT_SUCCESS;
}