-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPruebas.cpp
More file actions
260 lines (179 loc) · 5.55 KB
/
Pruebas.cpp
File metadata and controls
260 lines (179 loc) · 5.55 KB
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
/*
* Pruebas.cpp
*
* Created on: Jun 1, 2012
* Author: vdiego
*/
#include "Arbolito.h"
#include "Arbol/BKDArbol.h"
#include "Arbol/BKDManagerMemoria.h"
#include "Disco/Buffer.h"
#include "Disco/Bloque.h"
#include "Disco/Registro.h"
#include "Disco/RegistroDeLongitudVariable.h"
#include "Disco/RegistroDeLongitudFija.h"
#include "Disco/IndicesManager.h"
#include "Claves/Incidente.h"
#include "Arbol/BKDRegistro.h"
#include "IndiceDatos.h"
#include "Claves/InstanciadorIncidentes.h"
#include "Claves/ClaveIncidente.h"
#include "Claves/Incidente.h"
#include "Comun/Utils.h"
#include <string.h>
#include <iostream>
#include <fstream>
#include <sstream>
#include <stdio.h>
#include <vector>
#include <ctime>
using namespace std;
namespace Pruebas
{
int PruebaArbolB2()
{
string filePath = "PruebaArbolB2.UBA";
int cap_hoja = 4;
int cap_int = 3;
Utils::debugMode = true;
//BKDArbol* arbol = BKDArbol::CrearEnMemoria(cap_hoja, cap_int);
BKDArbol* arbol = BKDArbol::CrearEnDisco(filePath, 128, new InstanciadorIncidentes());
//BKDArbol* arbol = BKDArbol::AbrirDeDisco(filePath, new InstanciadorIncidentes());
cout << endl;
cout << "======================== Comenzando pruebas de Arbol BKD ... =============";
cout << endl << endl;
cout << endl;
cout << "Capacidad Hoja: " << cap_hoja << endl;
cout << "Capacidad Interno: " << cap_int << endl;
cout << "Archivo: \"" << filePath << "\"" << endl;
cout << endl;
cout << "Insertando valores 0..999";
cout << endl;
int cantRegs = 7;
vector<string> clavesInsert = vector<string>();
for (int i = 0; i < cantRegs; i++)
{
std::stringstream ss;
ss << i;
clavesInsert.push_back(ss.str());
}
for (int i = 0; i < cantRegs; i++)
//for (int i = cantRegs-1; i >= 0; i--)
{
stringstream ss;
ss << "Mitre;2011-10-2T12:12:45;no_cierra_puertas;incendio;" << i;
Incidente reg = Incidente(ss.str());
if (!arbol->InsertarRegistro(reg))
{
cerr << "Error al insertar clave " << reg.formacion << endl;
delete arbol;
return -1;
}
Incidente reg2 = Incidente("Belgrano_norte;2010-10-22T12:09:25;motores_al_80;desacoplado;25");
if (!arbol->InsertarRegistro(reg2))
{
cerr << "Error al insertar clave " << reg.formacion << endl;
delete arbol;
return -1;
}
Incidente reg3 = Incidente("Mitre;2011-10-2T13:12:45;no_cierra_puertas;incendio;17");
if (!arbol->InsertarRegistro(reg3))
{
cerr << "Error al insertar clave " << reg.formacion << endl;
delete arbol;
return -1;
}
Incidente reg4 = Incidente("Sarmiento;2012-03-25T19:47:02;frena_80;choque_con_otra_formacion;12");
if (!arbol->InsertarRegistro(reg4))
{
cerr << "Error al insertar clave " << reg.formacion << endl;
delete arbol;
return -1;
}
}
cout << endl;
cout << "Imprimiendo Arbol B+ ...";
cout << endl << endl;
arbol->DebugPrintAll();
cout << endl;
cout << "Buscando claves '-2', '0', '7', '99', '7', '666', '1249023'";
cout << endl << endl;
int busq[] = {-2, 0, 7, 99, 7, 666, 1249023};
/*
for(int i = 0; i < 7; i++)
{
ClaveInt claveBusqueda = ClaveInt(busq[i]);
BKDRegistro* regBusq = NULL;
bool res = arbol->BuscarRegistro(claveBusqueda, ®Busq);
if (!res)
cout << " NOPE ";
else if (((Incidente*)regBusq)->formacion != busq[i])
cout << " BAD ";
else
cout << " OK ";
delete regBusq;
}*/
cout << endl;
cout << "Buscando Incidente Mitre;2011-10-2T12:12:45;no_cierra_puertas;incendio;15";
cout << endl << endl;
BKDRegistro* regBusq = NULL;
Incidente regBus = Incidente("Mitre;2011-10-2T12:12:45;no_cierra_puertas;incendio;15");
ClaveIncidente claveBus = ClaveIncidente(regBus);
bool res = arbol->BuscarRegistro(claveBus, ®Busq);
if (!res)
cout << " NOPE ";
else
cout << " OK ";
cout << endl;
cout << endl;
//ClaveInt claveInicio = ClaveInt(0);
//ClaveInt claveFin = ClaveInt(500);
Incidente regInicio = Incidente("Mitre;-;no_cierra_puertas;-;-");
Incidente regFin = Incidente("Mitre;-;no_cierra_puertas;-;-");
ClaveIncidente claveInicio = ClaveIncidente(regInicio);
ClaveIncidente claveFin = ClaveIncidente(regFin);
cout << endl;
cout << "Buscando rango de claves '"<< claveInicio.ToString() << "' al '" << claveFin.ToString() << "'";
cout << endl << endl;
list<BKDRegistro*> resultadoRango;
arbol->BuscarPorRango(claveInicio, claveFin, resultadoRango);
cout << "Cantidad de registros encontrados: " << resultadoRango.size() << endl;
if (resultadoRango.size() > 0)
{
cout << "Registros: ";
for (list<BKDRegistro*>::iterator it = resultadoRango.begin(); it != resultadoRango.end(); it++)
{
cout << "{" << (*it)->ToString() << "} ";
delete *it;
}
cout << endl;
}
cout << endl;
cout << endl;
cout << "======================== Fin pruebas de Arbol BKD ========================";
cout << endl << endl;
delete arbol;
cout << ("Pulse enter para terminar.");
cout << endl << endl;
getchar();
return 0;
}
int PruebaArbolDisco()
{
string filePath = "TreeTest.uba";
int tamanioBloque = 512;
IndiceDatos* indice = IndiceDatos::Crear(filePath, tamanioBloque);
cout << endl;
cout << "======================== Comenzando pruebas de Arbol en Disco ... =============";
cout << endl << endl;
cout << "Archivo: \"" << filePath << "\"" << endl << endl;
cout << endl;
cout << "======================== Fin pruebas de Arbol en Disco ========================";
cout << endl << endl;
delete indice;
cout << ("Pulse enter para terminar.");
cout << endl << endl;
getchar();
return 0;
}
}