00001
00012 #include <iostream>
00013 #include <iomanip>
00014 #include <list>
00015 #include <vector>
00016 #include <fstream>
00017 #include <istream>
00018 #include <sstream>
00019
00020 using namespace std;
00021
00022 #include "RamDiscoCasoPrueba.hpp"
00023
00024 CPPUNIT_TEST_SUITE_REGISTRATION(RamDiscoCasoPrueba);
00025
00026 #include "RamDisco.hpp"
00027
00028 #include "CasosPrueba.hpp"
00029
00030
00031 void RamDiscoCasoPrueba::prueba_precalcula_escribe_con_hermanos()
00032 {
00033 CPPUNIT_ASSERT(precalcula_escribe_con_hermanos(NULL) == 0);
00034
00035 NodoTrieS *n = new NodoTrieS("abc");
00036 long p = precalcula_escribe_con_hermanos(n) ;
00037
00038 CPPUNIT_ASSERT(p == 16);
00039 delete n;
00040
00041 n = new NodoTrieS("bc");
00042 NodoTrieS *n2 = new NodoTrieS("a", n);
00043 p = precalcula_escribe_con_hermanos(n2) ;
00044
00045 CPPUNIT_ASSERT(p == 14);
00046 delete n2;
00047
00048 n = new NodoTrieS("bc");
00049 n2 = new NodoTrieS("a", NULL, n);
00050 p = precalcula_escribe_con_hermanos(n2) ;
00051
00052 CPPUNIT_ASSERT(p == 28);
00053 delete n;
00054
00055 }
00056
00057 void RamDiscoCasoPrueba::prueba_precalcula_escribe()
00058 {
00059 CPPUNIT_ASSERT(precalcula_escribe(NULL) == 0);
00060
00061 NodoTrieS *n = new NodoTrieS("abc");
00062 long p = precalcula_escribe(n) ;
00063
00064 CPPUNIT_ASSERT(p == 16);
00065 delete n;
00066
00067 n = new NodoTrieS("bc");
00068 NodoTrieS *n2 = new NodoTrieS("a", n);
00069 p = precalcula_escribe(n2) ;
00070
00071 CPPUNIT_ASSERT(p == 29);
00072 delete n2;
00073
00074 n = new NodoTrieS("bc");
00075 n2 = new NodoTrieS("a", NULL, n);
00076 p = precalcula_escribe(n2) ;
00077
00078 CPPUNIT_ASSERT(p == 28);
00079 delete n;
00080
00081 }
00082
00083
00084 extern stringstream *depuraos;
00085
00086
00087 void RamDiscoCasoPrueba::prueba_leePlano()
00088 {
00089 fstream os("ej.indice", ios_base::out);
00090 os << ps15;
00091 os.close();
00092
00093 vector<Doc> docs;
00094 docs.push_back(Doc("ej.txt","m","2010-01-05"));
00095 escribeRelacion("ej.relacion", docs, NULL);
00096
00097 docs.clear();
00098
00099 NodoTrieS *n = leePlano("ej.indice", "ej.relacion", docs);
00100 cout << n->preorden() << endl;
00101 CPPUNIT_ASSERT(docs.size() == 1);
00102 CPPUNIT_ASSERT(n->preorden() == "JESUSORAMTAM");
00103 }
00104
00105
00106 void RamDiscoCasoPrueba::prueba_escribePlano()
00107 {
00108
00109 NodoTrieS t;
00110 leeTexto("verdad.txt", 1, t, false);
00111 fstream os("verdad.docindice", ios_base::out);
00112 escribePlanoStream(&t, os, 0);
00113 os.close();
00114
00115 NodoTrieS *ct = new NodoTrieS();
00116 string rs;
00117
00118 ct->inserta("BUEN", Pos(1,1));
00119 ct->inserta("PODEROSO", Pos(1,2));
00120 ct->inserta("BUENO", Pos(1,3));
00121 ct->inserta("BUENOS", Pos(1,4));
00122 ct->inserta("A", Pos(1,5));
00123 ct->inserta("C", Pos(1,6));
00124 ct->inserta("BUEN", Pos(1,7));
00125 ct->inserta("BUENA", Pos(1,8));
00126 ct->inserta("BUENO", Pos(1,9));
00127 ct->inserta("BU", Pos(1,11));
00128 ct->inserta("BUS", Pos(1,12));
00129 ct->inserta("AMIGO", Pos(1,13));
00130
00131 NodoTrieS *n7=new NodoTrieS("PODEROSS", NULL, NULL, Pos(18,1));
00132 NodoTrieS *n5=new NodoTrieS("CASA", NULL, n7, Pos(16,1));
00133 NodoTrieS *n2=new NodoTrieS("CAD1", NULL, NULL, Pos(15,1));
00134 NodoTrieS *n3=new NodoTrieS("B", n2, n5);
00135 NodoTrieS *n6=new NodoTrieS("MIGA", NULL, NULL, Pos(17,1));
00136 NodoTrieS *n4=new NodoTrieS("A", n6, n3, Pos(14,1));
00137
00138 NodoTrieS *rm = mezcla(ct, n4);
00139 ct = NULL;
00140 n4=NULL;
00141
00142 vector<Doc> docs;
00143 docs.push_back(Doc("ejemplo.txt", "12345678901234567890123456789012",
00144 "2009-09-30"));
00145 escribePlano(*rm, docs, "prueba.indice", "prueba.relacion");
00146
00147 cerr << "Examinar resultado con: less prueba.indice" << endl;
00148 delete rm;
00149
00150 }
00151
00152
00153 void RamDiscoCasoPrueba::prueba_leeTexto()
00154 {
00155
00156 fstream os("verdad.txt", ios_base::out);
00157 os << "LA VERDAD SI NOS LIBERARÁ SI" << endl;
00158 os.close();
00159 NodoTrieS t;
00160 leeTexto("verdad.txt", 1, t, false);
00161
00162
00163 CPPUNIT_ASSERT(t.preorden() == "LAIBERARÁNOSSIVERDAD");
00164
00165
00166 std::stringstream sos;
00167 llena_ss(sos, &t);
00168
00169
00170 }
00171
00172
00173 void RamDiscoCasoPrueba::prueba_mezclaDiscoRam()
00174 {
00175
00176 std::stringstream sos;
00177 std::stringstream sis1;
00178 NodoTrieS *a2 = NULL;
00179
00180 try {
00181 sos.clear();
00182 sos.str("");
00183 sis1.clear();
00184 sis1.str("");
00185 mezclaDiscoRam(sis1, a2, 0, sos, false, false, NULL, NULL);
00186 CPPUNIT_ASSERT(sos.str() == "\n" );
00187
00188 sos.clear();
00189 sos.str("");
00190 sis1.clear();
00191 sis1.str("\n");
00192 a2 = new NodoTrieS();
00193 mezclaDiscoRam(sis1, a2, 0, sos, false, false, NULL, NULL);
00194 CPPUNIT_ASSERT(sos.str() == "\n" );
00195
00196 sos.clear();
00197 sos.str("");
00198 sis1.clear();
00199 sis1.str("\n");
00200 mezclaDiscoRam(sis1, a2, 0, sos, true, true, NULL, NULL);
00201 CPPUNIT_ASSERT(sos.str() == "\n" );
00202
00203 sos.clear();
00204 sos.str("");
00205 sis1.clear();
00206 sis1.str("x");
00207 CPPUNIT_ASSERT_THROW(mezclaDiscoRam(sis1, a2, 0, sos, false, false, NULL, NULL),
00208 std::string);
00209
00210 sos.clear();
00211 sos.str("");
00212 sis1.clear();
00213 sis1.str(ps1 + "\n");
00214 mezclaDiscoRam(sis1, a2, 0, sos, true, true, NULL, NULL);
00215
00216 CPPUNIT_ASSERT(sos.str() == (ps1 + "\n") );
00217 delete a2;
00218
00219
00220 sos.clear();
00221 sos.str("");
00222 sis1.clear();
00223 sis1.str(ps4);
00224 a2 = NULL;
00225 mezclaDiscoRam(sis1, a2, 0, sos, true, true, NULL, NULL);
00226
00227 CPPUNIT_ASSERT(sos.str() == ps4 );
00228
00229 sos.clear();
00230 sos.str("");
00231 sis1.clear();
00232 sis1.str("\n");
00233 a2 = new NodoTrieS("a");
00234
00235 mezclaDiscoRam(sis1, a2, 0, sos, true, true, NULL, NULL);
00236 CPPUNIT_ASSERT(sos.str() == (ps1 + "\n") );
00237 delete a2;
00238
00239 sos.clear();
00240 sos.str("");
00241 sis1.clear();
00242 sis1.str("\n");
00243
00244 a2 = new NodoTrieS("m");
00245 a2 = new NodoTrieS("a", a2, NULL);
00246 mezclaDiscoRam(sis1, a2, 0, sos, true, true, NULL, NULL);
00247
00248
00249 CPPUNIT_ASSERT(sos.str() == ps4);
00250 delete a2;
00251
00252
00253 sos.clear();
00254 sos.str("");
00255 sis1.clear();
00256 sis1.str(ps2 + "\n");
00257 a2 = NULL;
00258
00259 mezclaDiscoRam(sis1, a2, 0, sos, true, true, NULL, NULL);
00260 CPPUNIT_ASSERT(sos.str() == (ps2 + "\n") );
00261 delete a2;
00262
00263 sos.clear();
00264 sos.str("");
00265 sis1.clear();
00266 sis1.str(ps1 + "\n");
00267 a2 = new NodoTrieS("a", NULL, NULL);
00268
00269 mezclaDiscoRam(sis1, a2, 0, sos, true, true, NULL, NULL);
00270 CPPUNIT_ASSERT(sos.str() == (ps1 + "\n") );
00271 delete a2;
00272
00273 sos.clear();
00274 sos.str("");
00275 sis1.clear();
00276 sis1.str(ps4);
00277 a2 = new NodoTrieS("m");
00278 a2 = new NodoTrieS("a", a2, NULL);
00279
00280 mezclaDiscoRam(sis1, a2, 0, sos, true, true, NULL, NULL);
00281 CPPUNIT_ASSERT(sos.str() == ps4 );
00282 delete a2;
00283
00284
00285 sos.clear();
00286 sos.str("");
00287 sis1.clear();
00288 sis1.str(ps2 + "\n");
00289 a2 = new NodoTrieS("a", NULL, NULL, Pos(2,2));
00290
00291 mezclaDiscoRam(sis1, a2, 0, sos, true, true, NULL, NULL);
00292 CPPUNIT_ASSERT(sos.str() == (ps2 + "\n") );
00293 delete a2;
00294
00295 sos.clear();
00296 sos.str("");
00297 sis1.clear();
00298 sis1.str(ps2 + "\n");
00299 set<Pos> cpos;
00300 cpos.insert(Pos(2,2));
00301 cpos.insert(Pos(2,4));
00302 a2 = new NodoTrieS("a", NULL, NULL, cpos);
00303 stringstream s2;
00304 s2.clear();
00305 llena_ss(s2, a2);
00306
00307
00308 mezclaDiscoRam(sis1, a2, 0, sos, true, true, NULL, NULL);
00309
00310
00311 CPPUNIT_ASSERT(sos.str() == (ps3 + "\n") );
00312 delete a2;
00313
00314 sos.clear();
00315 sos.str("");
00316 sis1.clear();
00317 sis1.str(ps5);
00318
00319 a2 = new NodoTrieS("b");
00320 a2 = new NodoTrieS("a", NULL, a2);
00321 llena_ss(s2, a2);
00322
00323
00324 mezclaDiscoRam(sis1, a2, 0, sos, false, false, NULL, NULL);
00325
00326
00327 CPPUNIT_ASSERT(sos.str() == (ps1 + "\n") );
00328 delete a2;
00329
00330 sos.clear();
00331 sos.str("");
00332 sis1.clear();
00333 sis1.str(ps8);
00334 a2 = new NodoTrieS("b", NULL, NULL, Pos(2,2));
00335 a2 = new NodoTrieS("a", NULL, a2);
00336
00337
00338 mezclaDiscoRam(sis1, a2, 0, sos, true, false, NULL, NULL);
00339 CPPUNIT_ASSERT(sos.str() == ps8 );
00340 delete a2;
00341
00342 sos.clear();
00343 sos.str("");
00344 sis1.clear();
00345 sis1.str(ps8);
00346
00347
00348 a2 = new NodoTrieS("b", NULL, NULL, Pos(2,2));
00349 a2 = new NodoTrieS("a", NULL, a2);
00350 mezclaDiscoRam(sis1, a2, 0, sos, false, true, NULL, NULL);
00351 CPPUNIT_ASSERT(sos.str() == ps9);
00352 delete a2;
00353
00354 sos.clear();
00355 sos.str("");
00356 sis1.clear();
00357 sis1.str(ps8);
00358
00359
00360 a2 = new NodoTrieS("b", NULL, NULL, Pos(2,2));
00361 a2 = new NodoTrieS("a", NULL, a2);
00362 mezclaDiscoRam(sis1, a2, 0, sos, true, true, NULL, NULL);
00363
00364 CPPUNIT_ASSERT(sos.str() == ps10);
00365 delete a2;
00366
00367 sos.clear();
00368 sos.str("");
00369 sis1.clear();
00370 sis1.str(ps9);
00371
00372
00373 a2 = new NodoTrieS("b", NULL, NULL, Pos(2,4));
00374 a2 = new NodoTrieS("a", NULL, a2);
00375 mezclaDiscoRam(sis1, a2, 0, sos, true, true, NULL, NULL);
00376 CPPUNIT_ASSERT(sos.str() == ps10);
00377 delete a2;
00378
00379 sos.clear();
00380 sos.str("");
00381 sis1.clear();
00382 sis1.str(ps1 + "\n");
00383
00384
00385 a2 = new NodoTrieS("am", NULL, NULL);
00386 mezclaDiscoRam(sis1, a2, 0, sos, true, true, NULL, NULL);
00387
00388 CPPUNIT_ASSERT(sos.str() == ps4 );
00389 delete a2;
00390
00391 sos.clear();
00392 sos.str("");
00393 sis1.clear();
00394 sis1.str(ps11);
00395
00396
00397 a2 = new NodoTrieS("a", NULL, NULL);
00398 mezclaDiscoRam(sis1, a2, 0, sos, true, true, NULL, NULL);
00399
00400 CPPUNIT_ASSERT(sos.str() == ps4 );
00401 delete a2;
00402
00403
00404 sos.clear();
00405 sos.str("");
00406 sis1.clear();
00407 sis1.str(ps12);
00408
00409
00410 a2 = new NodoTrieS("am", NULL, NULL);
00411 mezclaDiscoRam(sis1, a2, 0, sos, true, true, NULL, NULL);
00412
00413 CPPUNIT_ASSERT(sos.str() == ps13 );
00414 delete a2;
00415
00416 sos.clear();
00417 sos.str("");
00418 sis1.clear();
00419 sis1.str(ps11);
00420
00421
00422 a2 = new NodoTrieS("l", NULL, NULL);
00423 a2 = new NodoTrieS("a", a2, NULL);
00424 llena_ss(s2, a2);
00425
00426
00427
00428 mezclaDiscoRam(sis1, a2, 0, sos, true, true, NULL, NULL);
00429
00430 CPPUNIT_ASSERT(sos.str() == ps13 );
00431 delete a2;
00432
00433
00434 NodoTrieS *nam = new NodoTrieS("am", NULL, NULL, set<Pos>());
00435 llena_ss(sis1, nam);
00436 NodoTrieS *na = new NodoTrieS();
00437 na->inserta("a", Pos(1,1));
00438
00439 sos.clear();
00440 sos.str("");
00441 mezclaDiscoRam(sis1, na, 0, sos, true, true, NULL, NULL);
00442 delete na;
00443
00444 NodoTrieS *nm = new NodoTrieS("m", NULL, NULL, set<Pos>());
00445 na = new NodoTrieS("a", nm, NULL, Pos(1,1));
00446 std::stringstream sist;
00447 llena_ss(sist, na);
00448
00449
00450 CPPUNIT_ASSERT(sos.str() == sist.str());
00451 delete na;
00452 delete nam;
00453
00454
00455 sos.clear();
00456 sos.str("");
00457 nam = new NodoTrieS("am", NULL, NULL, set<Pos>());
00458 llena_ss(sis1, nam);
00459 NodoTrieS *no = new NodoTrieS("o", NULL, NULL, set<Pos>());
00460 na = new NodoTrieS("a", no, NULL, set<Pos>());
00461
00462
00463 mezclaDiscoRam(sis1, na, 0, sos, true, true, NULL, NULL);
00464 delete na;
00465 delete nam;
00466
00467 no = new NodoTrieS("o", NULL, NULL, set<Pos>());
00468 nm = new NodoTrieS("m", NULL, no , set<Pos>());
00469 na = new NodoTrieS("a", nm, NULL, set<Pos>());
00470 llena_ss(sist, na);
00471
00472 CPPUNIT_ASSERT(sos.str() == sist.str() );
00473 delete na;
00474
00475
00476 NodoTrieS *naa = new NodoTrieS("aa", NULL, NULL, set<Pos>());
00477 llena_ss(sis1, naa);
00478 NodoTrieS *nab = new NodoTrieS();
00479 nab->inserta("ab", Pos(1,1));
00480
00481 llena_ss(s2, nab);
00482
00483
00484
00485 sos.clear();
00486 sos.str("");
00487 mezclaDiscoRam(sis1, nab, 0, sos, true, true, NULL, NULL);
00488 delete naa;
00489 delete nab;
00490 NodoTrieS *nb = new NodoTrieS();
00491 nb->inserta("b", Pos(1,1));
00492 NodoTrieS *na2 = new NodoTrieS("a", NULL, nb, set<Pos>());
00493 na = new NodoTrieS("a", na2, NULL, set<Pos>());
00494 llena_ss(sist,na);
00495
00496
00497 CPPUNIT_ASSERT(sos.str() == sist.str() );
00498 delete na;
00499
00500
00501 sos.clear();
00502 sos.str("");
00503 nm = new NodoTrieS("m", NULL, NULL, set<Pos>());
00504 naa = new NodoTrieS("aa", nm, NULL, set<Pos>());
00505 llena_ss(sis1, naa);
00506 delete naa;
00507 nm = new NodoTrieS("m", NULL, NULL, set<Pos>());
00508 nab = new NodoTrieS("ab", nm, NULL, set<Pos>());
00509
00510
00511 mezclaDiscoRam(sis1, nab, 0, sos, true, true, NULL, NULL);
00512 NodoTrieS *nm2 = new NodoTrieS("m", NULL, NULL, set<Pos>());
00513 nm = new NodoTrieS("m", NULL, NULL, set<Pos>());
00514 nab = new NodoTrieS("b", nm, NULL, set<Pos>());
00515 naa = new NodoTrieS("a", nm2, nab, set<Pos>());
00516 na = new NodoTrieS("a", naa, NULL, set<Pos>());
00517 llena_ss(sist, na);
00518 delete na;
00519
00520 CPPUNIT_ASSERT(sos.str() == sist.str() );
00521
00522
00523 sos.clear();
00524 sos.str("");
00525 nab = new NodoTrieS("ab", NULL, NULL, set<Pos>());
00526 llena_ss(sis1, nab);
00527 delete nab;
00528 naa = new NodoTrieS();
00529 naa->inserta("aa", Pos(1,1));
00530
00531 mezclaDiscoRam(sis1, naa, 0, sos, true, true, NULL, NULL);
00532 delete naa;
00533 nb = new NodoTrieS("b");
00534 naa = new NodoTrieS("a",NULL, nb, Pos(1,1));
00535 na = new NodoTrieS("a", naa, NULL);
00536 llena_ss(sist, na);
00537 delete na;
00538
00539 CPPUNIT_ASSERT(sos.str() == sist.str() );
00540
00541 sos.clear();
00542 sos.str("");
00543 nm = new NodoTrieS("m");
00544 nab = new NodoTrieS("ab", nm, NULL);
00545 llena_ss(sis1, nab);
00546 delete nab;
00547 nm = new NodoTrieS("m");
00548 naa = new NodoTrieS("aa", nm, NULL);
00549
00550 mezclaDiscoRam(sis1, naa, 0, sos, true, true, NULL, NULL);
00551 delete naa;
00552
00553 nm = new NodoTrieS("m");
00554 nab = new NodoTrieS("b", nm);
00555 nm2 = new NodoTrieS("m");
00556 naa = new NodoTrieS("a", nm2, nab);
00557 na = new NodoTrieS("a", naa);
00558 llena_ss(sist, na);
00559 delete na;
00560
00561
00562 CPPUNIT_ASSERT(sos.str() == sist.str());
00563
00564 sos.clear();
00565 sos.str("");
00566 na = new NodoTrieS("a");
00567 llena_ss(sis1, na);
00568 delete na;
00569 nb = new NodoTrieS("b", NULL, NULL, Pos(1,1));
00570
00571 mezclaDiscoRam(sis1, nb, 0, sos, true, true, NULL, NULL);
00572 delete nb;
00573 nb = new NodoTrieS("b", NULL, NULL, Pos(1,1));
00574 na = new NodoTrieS("a", NULL, nb);
00575 llena_ss(sist, na);
00576 delete na;
00577
00578 CPPUNIT_ASSERT(sos.str() == sist.str() );
00579
00580 sos.clear();
00581 sos.str("");
00582 NodoTrieS *nr = new NodoTrieS("r");
00583 no = new NodoTrieS("o", nr);
00584 nm = new NodoTrieS("m", no);
00585 na = new NodoTrieS("a", nm);
00586 llena_ss(sis1, na);
00587 delete na;
00588 na = new NodoTrieS();
00589 na->inserta("a", Pos(1,1));
00590
00591 mezclaDiscoRam(sis1, na, 0, sos, true, true, NULL, NULL);
00592 delete na;
00593 nr = new NodoTrieS("r");
00594 no = new NodoTrieS("o", nr);
00595 nm = new NodoTrieS("m", no);
00596 na = new NodoTrieS("a", nm);
00597 na->inserta("a", Pos(1,1));
00598 llena_ss(sist, na);
00599 delete na;
00600
00601 CPPUNIT_ASSERT(sos.str() == sist.str());
00602
00603 sos.clear();
00604 sos.str("");
00605 na = new NodoTrieS();
00606 na->inserta("a", Pos(1,1));
00607 llena_ss(sis1, na);
00608 delete na;
00609 nr = new NodoTrieS("r");
00610 no = new NodoTrieS("o", nr);
00611 nm = new NodoTrieS("m", no);
00612 na = new NodoTrieS("a", nm);
00613
00614 mezclaDiscoRam(sis1, na, 0, sos, true, true, NULL, NULL);
00615 delete na;
00616 nr = new NodoTrieS("r");
00617 no = new NodoTrieS("o", nr);
00618 nm = new NodoTrieS("m", no);
00619 na = new NodoTrieS("a", nm);
00620 na->inserta("a", Pos(1,1));
00621 llena_ss(sist, na);
00622 delete na;
00623
00624 CPPUNIT_ASSERT(sos.str() == sist.str());
00625
00626
00627 sos.clear();
00628 sos.str("");
00629 nb = new NodoTrieS("b");
00630 na = new NodoTrieS("a", NULL, nb);
00631 llena_ss(sis1, na);
00632 delete na;
00633 na = new NodoTrieS("a");
00634 mezclaDiscoRam(sis1, na, 0, sos, false, true, NULL, NULL);
00635
00636 llena_ss(s2, na);
00637 delete na;
00638 CPPUNIT_ASSERT(sos.str() == s2.str() );
00639
00640 sos.clear();
00641 sos.str("");
00642
00643 na = new NodoTrieS("a");
00644 llena_ss(sis1, na);
00645 delete na;
00646 nb = new NodoTrieS("b");
00647 na = new NodoTrieS("a", NULL, nb);
00648
00649 mezclaDiscoRam(sis1, na, 0, sos, true, false, NULL, NULL);
00650 delete na;
00651
00652 CPPUNIT_ASSERT(sos.str() == sis1.str() );
00653
00654
00655
00656
00657
00658
00659 sos.clear();
00660 sos.str("");
00661
00662 na = new NodoTrieS("a");
00663 llena_ss(sis1, na);
00664 delete na;
00665 nr = new NodoTrieS("r");
00666 no = new NodoTrieS("o", nr);
00667 nm = new NodoTrieS("m", no);
00668 na = new NodoTrieS("a", nm);
00669 na->inserta("a", Pos(1,1));
00670
00671 mezclaDiscoRam(sis1, na, 0, sos, true, false, NULL, NULL);
00672
00673 llena_ss(s2, na);
00674 delete na;
00675 CPPUNIT_ASSERT(sos.str()== s2.str());
00676
00677 sos.clear();
00678 sos.str("");
00679
00680
00681 nr = new NodoTrieS("r");
00682 no = new NodoTrieS("o", nr);
00683 nm = new NodoTrieS("m", no);
00684 na = new NodoTrieS("a", nm);
00685 na->inserta("a", Pos(1,1));
00686 llena_ss(sis1, na);
00687 delete na;
00688 na = new NodoTrieS("a");
00689
00690 mezclaDiscoRam(sis1, na, 0, sos, false, false, NULL, NULL);
00691 delete na;
00692
00693 CPPUNIT_ASSERT(sos.str() == sis1.str());
00694
00695
00696
00697
00698 sos.clear();
00699 sos.str("");
00700 sos << "a{0000=00000}";
00701 NodoTrieS *nc = new NodoTrieS("c");
00702 nb = new NodoTrieS("b", NULL, nc);
00703 llena_ss(sis1, nb);
00704 delete nb;
00705 nb = new NodoTrieS("b");
00706
00707 mezclaDiscoRam(sis1, nb, 0, sos, true, true, NULL, NULL);
00708 delete nb;
00709 nc = new NodoTrieS("c");
00710 nb = new NodoTrieS("b", NULL, nc);
00711 na = new NodoTrieS("a", NULL, nb);
00712 llena_ss(sist, na);
00713 delete na;
00714 CPPUNIT_ASSERT(sos.str() == sist.str());
00715
00716 sos.clear();
00717 sos.str("");
00718 sos << "a{0000=00000}";
00719 nc = new NodoTrieS("c");
00720 nb = new NodoTrieS("b", nc);
00721 llena_ss(sis1, nb);
00722 delete nb;
00723 nb = new NodoTrieS("b");
00724
00725 mezclaDiscoRam(sis1, nb, 0, sos, true, true, NULL, NULL);
00726 delete nb;
00727 nc = new NodoTrieS("c");
00728 nb = new NodoTrieS("b", nc);
00729 na = new NodoTrieS("a", NULL, nb);
00730 llena_ss(sist, na);
00731 delete na;
00732 CPPUNIT_ASSERT(sos.str() == sist.str() );
00733
00734 sos.clear();
00735 sos.str("");
00736 na = new NodoTrieS();
00737 na->inserta("a", Pos(1,1));
00738 llena_ss(sis1, na);
00739 delete na;
00740 nr = new NodoTrieS("r");
00741 no = new NodoTrieS("o", nr);
00742 nm = new NodoTrieS("m", no);
00743 na = new NodoTrieS("a", nm);
00744
00745 vector<long> renum;
00746 renum.push_back(0);
00747 mezclaDiscoRam(sis1, na, 0, sos, true, true, NULL, &renum);
00748 delete na;
00749
00750 nr = new NodoTrieS("r");
00751 no = new NodoTrieS("o", nr);
00752 nm = new NodoTrieS("m", no);
00753 na = new NodoTrieS("a", nm);
00754 na->inserta("a", Pos(1,1));
00755 llena_ss(sist, na);
00756 delete na;
00757 CPPUNIT_ASSERT(sos.str() == sist.str());
00758
00759 sos.clear();
00760 sos.str("");
00761 renum.clear();
00762 renum.push_back(1);
00763 nr = new NodoTrieS("r");
00764 no = new NodoTrieS("o", nr);
00765 nm = new NodoTrieS("m", no);
00766 na = new NodoTrieS("a", nm);
00767 llena_ss(sis1, na);
00768 delete na;
00769 na = new NodoTrieS();
00770 na->inserta("a", Pos(1,1));
00771
00772
00773 mezclaDiscoRam(sis1, na, 0, sos, true, true, NULL, &renum);
00774 delete na;
00775 nr = new NodoTrieS("r");
00776 no = new NodoTrieS("o", nr);
00777 nm = new NodoTrieS("m", no);
00778 na = new NodoTrieS("a", nm);
00779 na->inserta("a", Pos(2,1));
00780 llena_ss(sist, na);
00781 delete na;
00782
00783
00784 CPPUNIT_ASSERT(sos.str() == sist.str());
00785
00786 sos.clear();
00787 sos.str("");
00788 renum.clear();
00789 renum.push_back(0);
00790 nr = new NodoTrieS("r");
00791 no = new NodoTrieS("o", nr);
00792 nm = new NodoTrieS("m", no);
00793 na = new NodoTrieS("a", nm);
00794 llena_ss(sis1, na);
00795 delete na;
00796 nm = new NodoTrieS();
00797 nm->inserta("m", Pos(1, 1));
00798 NodoTrieS *nl = new NodoTrieS("l", NULL, nm);
00799 na = new NodoTrieS("a", nl);
00800
00801 mezclaDiscoRam(sis1, na, 0, sos, true, true, NULL, &renum);
00802 delete na;
00803 nr = new NodoTrieS("r");
00804 no = new NodoTrieS("o", nr);
00805 nm = new NodoTrieS("m", no);
00806 nm->inserta("m", Pos(1, 1));
00807 nl = new NodoTrieS("l", NULL, nm);
00808 na = new NodoTrieS("a", nl);
00809 llena_ss(sist, na);
00810 delete na;
00811
00812
00813 CPPUNIT_ASSERT(sos.str() == sist.str());
00814
00815
00816 sos.clear();
00817 sos.str("");
00818
00819 renum.clear();
00820 renum.push_back(1);
00821 sos << MARCAIND << "\n";
00822 na = new NodoTrieS();
00823 na->inserta("EM", Pos(1, 1));
00824 llena_ss(sis1, na);
00825 delete na;
00826 na = new NodoTrieS();
00827 na->inserta("CINTURA", Pos(1, 1));
00828 na->inserta("CONTABAN", Pos(1, 15));
00829 na->inserta("COMFESABAN", Pos(1, 11));
00830 na->inserta("COMIA", Pos(1, 8));
00831
00832
00833
00834
00835
00836
00837
00838
00839
00840 mezclaDiscoRam(sis1, na, 0, sos, true, true, NULL, &renum);
00841 delete na;
00842 na = new NodoTrieS();
00843 na->inserta("CINTURA", Pos(2, 1));
00844 na->inserta("CONTABAN", Pos(2, 15));
00845 na->inserta("COMFESABAN", Pos(2, 11));
00846 na->inserta("COMIA", Pos(2, 8));
00847 na->inserta("EM", Pos(1, 1));
00848
00849 sist.clear();
00850 sist.str("");
00851 sist.seekp(-1);
00852 sist.seekg(0);
00853 sist.clear();
00854 escribePlanoStream(na, sist, MARCAIND.length() + 1);
00855 sist.seekg(0);
00856 delete na;
00857
00858
00859
00860
00861
00862
00863
00864
00865
00866
00867
00868
00869 CPPUNIT_ASSERT(sos.str() == (MARCAIND + "\n" + sist.str()));
00870 CPPUNIT_ASSERT((long)sos.tellp() == (long)sos.str().size() );
00871
00872 sos.clear();
00873 sos.str("");
00874 renum.clear();
00875 renum.push_back(1);
00876 renum.push_back(1);
00877 renum.push_back(2);
00878 sos << MARCAIND << "\n";
00879 na = new NodoTrieS();
00880 na->inserta("JESUS", Pos(2, 2));
00881 llena_ss(sis1, na, MARCAIND + "\n");
00882 delete na;
00883
00884 na = new NodoTrieS();
00885 na->inserta("JORAM", Pos(3, 2));
00886 na->inserta("JOTAM", Pos(2, 2));
00887
00888
00889 sis1.seekg(MARCAIND.length() + 1);
00890
00891 mezclaDiscoRam(sis1, na, 0, sos, true, true, NULL, &renum);
00892 delete na;
00893
00894
00895 CPPUNIT_ASSERT(sos.str() == ps15);
00896 CPPUNIT_ASSERT((long)sos.tellp() == (long)sos.str().size() );
00897
00898 sos.clear();
00899 sos.str("");
00900 renum.clear();
00901 renum.push_back(1);
00902 sos << MARCAIND << "\n";
00903 na = new NodoTrieS();
00904 na->inserta("LIBRE", Pos(1, 2));
00905 llena_ss(sis1, na, MARCAIND + "\n");
00906 delete na;
00907
00908 na = new NodoTrieS();
00909 na->inserta("LIBERTAD", Pos(1, 2));
00910
00911
00912 sis1.seekg(MARCAIND.length() + 1);
00913
00914 mezclaDiscoRam(sis1, na, 0, sos, true, true, NULL, &renum);
00915
00916 delete na;
00917
00918 na = new NodoTrieS();
00919 na->inserta("LIBRE", Pos(1, 2));
00920 na->inserta("LIBERTAD", Pos(2, 2));
00921 stringstream sos2;
00922 llena_ss(sos2, na, MARCAIND + "\n");
00923
00924
00925 CPPUNIT_ASSERT(sos.str() == sos2.str());
00926
00927
00928 sos.clear();
00929 sos.str("");
00930 renum.clear();
00931 renum.push_back(1);
00932 sos << MARCAIND << "\n";
00933 na = new NodoTrieS();
00934 na->inserta("AHOGARON", Pos(1, 2));
00935 na->inserta("AHI", Pos(1, 4));
00936 llena_ss(sis1, na, MARCAIND + "\n");
00937 delete na;
00938
00939 na = new NodoTrieS();
00940 na->inserta("AHORA", Pos(1, 2));
00941
00942 sis1.seekg(MARCAIND.length() + 1);
00943 mezclaDiscoRam(sis1, na, 0, sos, true, true, NULL, &renum);
00944
00945 delete na;
00946
00947 na = new NodoTrieS();
00948 na->inserta("AHOGARON", Pos(1, 2));
00949 na->inserta("AHI", Pos(1, 4));
00950 na->inserta("AHORA", Pos(2, 2));
00951 sos2.clear();
00952 sos2.str("");
00953 llena_ss(sos2, na, MARCAIND + "\n");
00954
00955
00956 CPPUNIT_ASSERT(sos.str() == sos2.str());
00957
00958
00959
00960
00961 sos.clear();
00962 sos.str("");
00963 renum.clear();
00964 renum.push_back(0);
00965
00966 vector<long> renum1;
00967 renum1.clear();
00968 renum1.push_back(2);
00969 sos << MARCAIND << "\n";
00970 na = new NodoTrieS();
00971 na->inserta("JESUS", Pos(1, 1));
00972 llena_ss(sis1, na, MARCAIND + "\n");
00973 delete na;
00974
00975
00976
00977 na = new NodoTrieS();
00978 na->inserta("AMADO", Pos(1, 1));
00979 na->inserta("MIO", Pos(2, 2));
00980
00981 renum.clear();
00982 renum.push_back(0);
00983 renum.push_back(1);
00984
00985
00986 sis1.seekg(MARCAIND.length() + 1);
00987
00988 mezclaDiscoRam(sis1, na, 0, sos, true, true, &renum1, &renum);
00989 delete na;
00990
00991
00992 sos.seekg(MARCAIND.length() + 1);
00993 NodoTrieS *l1 = leePlanoStream(sos);
00994
00995 set<Pos> cr = l1->busca("JESUS");
00996 CPPUNIT_ASSERT(cr.size() == 1);
00997 set<Pos>::iterator i = cr.begin();
00998 CPPUNIT_ASSERT((*i).numd == 3);
00999 cr = l1->busca("AMADO");
01000 CPPUNIT_ASSERT(cr.size() == 1);
01001 i = cr.begin();
01002 CPPUNIT_ASSERT((*i).numd == 1);
01003
01004
01005 delete l1;
01006 } catch (std::string s) {
01007 cerr << s << endl;
01008 exit(1);
01009 }
01010 #if 0
01011 #endif
01012
01013 }
01014
01015
01016 void RamDiscoCasoPrueba::setUp()
01017 {
01018 return;
01019 }