00001
00012 #include <sstream>
00013
00014 #include "TrieSDiscoCasoPrueba.hpp"
00015 #include "TrieSDisco.hpp"
00016 #include "NodoTrieS.hpp"
00017 #include "RamDisco.hpp"
00018
00019 CPPUNIT_TEST_SUITE_REGISTRATION(TrieSDiscoCasoPrueba);
00020
00021 #include "CasosPrueba.hpp"
00022
00023 void TrieSDiscoCasoPrueba::prueba_escribeNodo()
00024 {
00025 set<Pos> *cp = new set<Pos>();
00026 CPPUNIT_ASSERT(precalcula_escribe_actual(1, cp) == 13);
00027 CPPUNIT_ASSERT(precalcula_escribe_actual(2, cp) == 14);
00028 cp->insert(Pos(1,1));
00029 CPPUNIT_ASSERT(precalcula_escribe_actual(1, cp) == 15);
00030
00031
00032 std::stringstream ss;
00033 ss.clear();
00034 ss.str("");
00035 CPPUNIT_ASSERT_THROW(escribeNodo(ss, "", NULL, 0), std::string);
00036 ss.clear();
00037 ss.str("");
00038 long r = escribeNodo(ss, "a", NULL, 0);
00039
00040 CPPUNIT_ASSERT(r == 7 && ss.str() == ps1);
00041 set<Pos> p;
00042 p.insert(Pos(2,2));
00043 ss.clear();
00044 ss.str("");
00045 r = escribeNodo(ss, "a", &p, 0);
00046
00047
00048 CPPUNIT_ASSERT(r== 7 && ss.str() == ps2);
00049
00050 p.insert(Pos(2,4));
00051 ss.clear();
00052 ss.str("");
00053 r = escribeNodo(ss, "a", &p, 0);
00054
00055 CPPUNIT_ASSERT(r == 7 &&
00056 ss.str() == ps3);
00057
00058
00059 }
00060
00061 void TrieSDiscoCasoPrueba::prueba_escribeCopiaNodo()
00062 {
00063 long r, h;
00064 std::stringstream sos;
00065 std::stringstream sis;
00066
00067 sos.clear();
00068 sos.str("");
00069 sis.clear();
00070 sis.str("");
00071 r = escribeCopiaNodo(sos, sis, h, NULL);
00072 CPPUNIT_ASSERT(sos.str()==sis.str() );
00073 CPPUNIT_ASSERT(r == 0);
00074
00075 sos.clear();
00076 sos.str("");
00077 sis.clear();
00078 sis.str("x");
00079 CPPUNIT_ASSERT_THROW(escribeCopiaNodo(sos, sis, h, NULL), std::string);
00080
00081 sos.clear();
00082 sos.str("");
00083 sis.clear();
00084 sis.str(ps1);
00085 r = escribeCopiaNodo(sos, sis, h, NULL);
00086
00087
00088
00089 CPPUNIT_ASSERT(sos.str() == sis.str());
00090 CPPUNIT_ASSERT(h == 0);
00091 CPPUNIT_ASSERT(r == 7);
00092
00093 sos.clear();
00094 sos.str("");
00095 sis.clear();
00096 sis << ps2;
00097 sis.clear();
00098 sis.seekg(0);
00099 sis.seekp(0);
00100
00101 r = escribeCopiaNodo(sos, sis, h, NULL);
00102
00103
00104 CPPUNIT_ASSERT(sos.str() == sis.str());
00105 CPPUNIT_ASSERT(h == 0);
00106 CPPUNIT_ASSERT(r == 7);
00107
00108 sos.clear();
00109 sos.str("");
00110 sis.clear();
00111 sis << ps3;
00112 sis.clear();
00113 sis.seekg(0);
00114 sis.seekp(0);
00115
00116 r = escribeCopiaNodo(sos, sis, h, NULL);
00117
00118
00119 CPPUNIT_ASSERT(sos.str()==sis.str());
00120 CPPUNIT_ASSERT(h == 0);
00121 CPPUNIT_ASSERT(r == 7);
00122
00123 sos.clear();
00124 sos.str("");
00125 sis.clear();
00126 sis.str(ps4);
00127 r = escribeCopiaNodo(sos, sis, h, NULL);
00128
00129 CPPUNIT_ASSERT(sos.str() == "a{0000=0000>}" );
00130 CPPUNIT_ASSERT(r == 7);
00131 CPPUNIT_ASSERT(h == 14);
00132
00133 }
00134
00135
00136 extern stringstream *depuraos;
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213 void TrieSDiscoCasoPrueba::prueba_escribeCopiaSubarbol()
00214 {
00215 long r;
00216 std::stringstream sos;
00217 std::stringstream sis;
00218
00219 sos.clear();
00220 sos.str("");
00221 sis.clear();
00222 sis.str("");
00223 escribeCopiaSubarbol(sos, sis, false, NULL);
00224 CPPUNIT_ASSERT(sos.str()==sis.str() );
00225 sos.clear();
00226 sos.str("");
00227 sis.clear();
00228 sis.str("x");
00229 CPPUNIT_ASSERT_THROW(escribeCopiaSubarbol(sos, sis,
00230 false, NULL), std::string);
00231 sos.clear();
00232 sos.str("");
00233 sis.clear();
00234 sis.clear();
00235 sis.str(ps3 + "\n");
00236
00237 sis.clear();
00238 sis.seekg(0);
00239 sis.seekp(0);
00240
00241 r = escribeCopiaSubarbol(sos, sis, false, NULL);
00242
00243 CPPUNIT_ASSERT(sos.str() == sis.str() );
00244
00245 sos.clear();
00246 sos.str("");
00247 sis.clear();
00248 sis.str(ps4);
00249
00250 r = escribeCopiaSubarbol(sos, sis, true, NULL);
00251
00252 CPPUNIT_ASSERT(sos.str()==sis.str() );
00253
00254
00255 NodoTrieS *nr = new NodoTrieS("r", NULL, NULL, set<Pos>());
00256 NodoTrieS *no = new NodoTrieS("o", nr, NULL, set<Pos>());
00257 NodoTrieS *nm = new NodoTrieS("m", no, NULL, set<Pos>());
00258 NodoTrieS *na = new NodoTrieS("a", nm, NULL, set<Pos>());
00259
00260 llena_ss(sis, na);
00261 delete na;
00262 na = NULL;
00263
00264 ASSERT(sis.str() == ps14);
00265 sis.seekg(0);
00266 sos.clear();
00267 sos.str("");
00268 r = escribeCopiaSubarbol(sos, sis, true, NULL);
00269
00270
00271 CPPUNIT_ASSERT(sos.str()==sis.str() );
00272
00273 NodoTrieS *ns = new NodoTrieS("s", NULL, NULL, set<Pos>());
00274 nr = new NodoTrieS("r", ns, NULL, set<Pos>());
00275 no = new NodoTrieS("o", nr, NULL, set<Pos>());
00276 nm = new NodoTrieS("m", no, NULL, set<Pos>());
00277 na = new NodoTrieS("a", nm, NULL, set<Pos>());
00278
00279
00280 sis.clear();
00281 sis.str("");
00282 llena_ss(sis, na);
00283 sos.clear();
00284 sos.str("");
00285 r = escribeCopiaSubarbol(sos, sis, true, NULL);
00286
00287
00288 CPPUNIT_ASSERT(sos.str()==sis.str() );
00289
00290 delete na;
00291 na = NULL;
00292
00293 NodoTrieS *nb = new NodoTrieS("b", NULL, NULL, set<Pos>());
00294 ns = new NodoTrieS("s", NULL, NULL, set<Pos>());
00295 nr = new NodoTrieS("r", ns, NULL, set<Pos>());
00296 no = new NodoTrieS("o", nr, NULL, set<Pos>());
00297 nm = new NodoTrieS("m", no, NULL, set<Pos>());
00298 na = new NodoTrieS("a", nm, nb, set<Pos>());
00299
00300
00301 sos.clear();
00302 sos.str("");
00303 sis.clear();
00304 sis.str("");
00305 llena_ss(sis, na);
00306 delete na;
00307 na = NULL;
00308
00309 sis.seekg(0);
00310 r = escribeCopiaSubarbol(sos, sis, true, NULL);
00311
00312
00313 CPPUNIT_ASSERT(sos.str()==sis.str() );
00314
00315
00316 na = new NodoTrieS();
00317 na->inserta("CONOCEREIS", Pos(1,1));
00318 na->inserta("LA", Pos(1,2));
00319 na->inserta("VERDAD", Pos(1,3));
00320 na->inserta("Y", Pos(1,4));
00321 na->inserta("LA", Pos(1,5));
00322 na->inserta("VERDAD", Pos(1,6));
00323 na->inserta("OS", Pos(1,7));
00324 na->inserta("HARA", Pos(1,8));
00325 na->inserta("LIBRES", Pos(1,9));
00326
00327 sos.clear();
00328 sos.str("");
00329 llena_ss(sis, na);
00330 delete na;
00331 na = NULL;
00332
00333 sis.seekg(0);
00334 r = escribeCopiaSubarbol(sos, sis, true, NULL);
00335
00336 CPPUNIT_ASSERT(sos.str()==sis.str() );
00337
00338
00339 sos.clear();
00340 sos.str("");
00341 sis.clear();
00342 sis.str(ps5);
00343 r = escribeCopiaSubarbol(sos, sis, false, NULL);
00344
00345 CPPUNIT_ASSERT(sos.str() == ps1 + "\n" );
00346
00347 sos.clear();
00348 sos.str("");
00349 sis.clear();
00350 sis.str(ps6);
00351 r = escribeCopiaSubarbol(sos, sis, false, NULL);
00352
00353 CPPUNIT_ASSERT(sos.str() == ps1 + "\n" );
00354
00355
00356 sos.clear();
00357 sos.str("");
00358 sis.clear();
00359 sis.str(ps7);
00360 r = escribeCopiaSubarbol(sos, sis, false, NULL);
00361
00362 CPPUNIT_ASSERT(sos.str() == ps4 );
00363
00364
00365 sos.clear();
00366 sos.str("");
00367 ;
00368 sos << ps1;
00369 sis.clear();
00370 sis.str("b{0000=00000}\n");
00371 r = escribeCopiaSubarbol(sos, sis, true, NULL);
00372 CPPUNIT_ASSERT(sos.str() == ps5 );
00373
00374 sos.clear();
00375 sos.str("");
00376 ;
00377 sos << ps1;
00378 sis.clear();
00379 sis.str(ps4_1);
00380 r = escribeCopiaSubarbol(sos, sis, true, NULL);
00381
00382 CPPUNIT_ASSERT(sos.str() == ps6);
00383
00384
00385 vector<long> renum;
00386 renum.push_back(-1);
00387 renum.push_back(-1);
00388
00389 sos.clear();
00390 sos.str("");
00391 sis.clear();
00392 sis.str(ps5);
00393 r = escribeCopiaSubarbol(sos, sis, true, &renum);
00394
00395 CPPUNIT_ASSERT(sos.str() == ps5 );
00396
00397 sos.clear();
00398 sos.str("");
00399 sis.clear();
00400 sis.str(ps8);
00401 r = escribeCopiaSubarbol(sos, sis, true, &renum);
00402
00403 CPPUNIT_ASSERT(sos.str() == ps5 );
00404
00405
00406 sos.clear();
00407 sos.str("");
00408 sis.clear();
00409 sis.str(ps15);
00410 renum[1]=0;
00411 renum.push_back(0);
00412
00413 r = escribeCopiaSubarbol(sos, sis, true, &renum);
00414
00415
00416
00417
00418
00419
00420
00421
00422 sos.seekg(MARCAIND.length() + 1);
00423 NodoTrieS *l2 = leePlanoStream(sos);
00424
00425
00426 CPPUNIT_ASSERT(l2->preorden() == "JESUSORAMTAM" );
00427 set<Pos> cr=l2->busca("JESUS");
00428
00429 CPPUNIT_ASSERT(cr.size() == 1);
00430
00431 cr.clear();
00432 delete l2;
00433
00434 na = new NodoTrieS();
00435 na->inserta("CONOCEREIS", Pos(1,1));
00436 na->inserta("Y", Pos(1,4));
00437 na->inserta("LA", Pos(1,5));
00438 na->inserta("LA", Pos(2,2));
00439 na->inserta("LIBRES", Pos(2,9));
00440
00441 cr=na->busca("LA");
00442
00443 CPPUNIT_ASSERT(cr.size() == 2);
00444 cr.clear();
00445 cr=na->busca("Y");
00446
00447 CPPUNIT_ASSERT(cr.size() == 1);
00448
00449 cr.clear();
00450
00451 sos.clear();
00452 sos.str("");
00453 llena_ss(sis, na);
00454 delete na;
00455 na = NULL;
00456
00457 sis.seekg(0);
00458 r = escribeCopiaSubarbol(sos, sis, true, &renum);
00459
00460 l2 = leePlanoStream(sos);
00461
00462
00463 CPPUNIT_ASSERT(l2->preorden() == "CONOCEREISLAIBRESY" );
00464 cr=l2->busca("LA");
00465
00466 CPPUNIT_ASSERT(cr.size() == 1);
00467 cr.clear();
00468 cr=l2->busca("Y");
00469 CPPUNIT_ASSERT(cr.size() == 0);
00470
00471 cr.clear();
00472 delete l2;
00473 l2 = NULL;
00474
00475 }
00476
00477
00478 void TrieSDiscoCasoPrueba::prueba_mezclarec()
00479 {
00480 std::stringstream sos;
00481 std::stringstream sis1;
00482 std::stringstream sis2;
00483
00484 sos.clear();
00485 sos.str("");
00486 sis1.clear();
00487 sis1.str("");
00488 sis2.clear();
00489 sis2.str("");
00490 mezclaRec(sis1, sis2, sos, false, false, NULL, NULL);
00491 CPPUNIT_ASSERT(sos.str() == "\n" );
00492
00493 sos.clear();
00494 sos.str("");
00495 sis1.clear();
00496 sis1.str("\n");
00497 sis2.clear();
00498 sis2.str("\n");
00499 mezclaRec(sis1, sis2, sos, false, false, NULL, NULL);
00500 CPPUNIT_ASSERT(sos.str() == "\n" );
00501
00502 sos.clear();
00503 sos.str("");
00504 sis1.clear();
00505 sis1.str("\n");
00506 sis2.clear();
00507 sis2.str("\n");
00508 mezclaRec(sis1, sis2, sos, true, true, NULL, NULL);
00509 CPPUNIT_ASSERT(sos.str() == "\n" );
00510
00511 sos.clear();
00512 sos.str("");
00513 sis1.clear();
00514 sis1.str("x");
00515 sis2.clear();
00516 sis2.str("\n");
00517 CPPUNIT_ASSERT_THROW(mezclaRec(sis1, sis2, sos, false, false, NULL, NULL),
00518 std::string);
00519
00520 sos.clear();
00521 sos.str("");
00522 sis1.clear();
00523 sis1.str(ps1 + "\n");
00524 sis2.clear();
00525 sis2.str("\n");
00526 mezclaRec(sis1, sis2, sos, true, true, NULL, NULL);
00527
00528 CPPUNIT_ASSERT(sos.str() == (ps1 + "\n") );
00529
00530
00531 sos.clear();
00532 sos.str("");
00533 sis1.clear();
00534 sis1.str(ps4);
00535 sis2.clear();
00536 sis2.str("\n");
00537 mezclaRec(sis1, sis2, sos, true, true, NULL, NULL);
00538
00539 CPPUNIT_ASSERT(sos.str() == ps4 );
00540
00541 sos.clear();
00542 sos.str("");
00543 sis1.clear();
00544 sis1.str("\n");
00545 sis2.clear();
00546 sis2.str(ps1 + "\n");
00547 mezclaRec(sis1, sis2, sos, true, true, NULL, NULL);
00548 CPPUNIT_ASSERT(sos.str() == (ps1 + "\n") );
00549
00550 sos.clear();
00551 sos.str("");
00552 sis1.clear();
00553 sis1.str("\n");
00554 sis2.clear();
00555 sis2.str(ps4);
00556 mezclaRec(sis1, sis2, sos, true, true, NULL, NULL);
00557
00558 CPPUNIT_ASSERT(sos.str() == ps4);
00559
00560
00561 sos.clear();
00562 sos.str("");
00563 sis1.clear();
00564 sis1.str(ps2 + "\n");
00565 sis2.clear();
00566 sis2.str("\n");
00567 mezclaRec(sis1, sis2, sos, true, true, NULL, NULL);
00568 CPPUNIT_ASSERT(sos.str() == (ps2 + "\n") );
00569
00570 sos.clear();
00571 sos.str("");
00572 sis1.clear();
00573 sis1.str(ps1 + "\n");
00574 sis2.clear();
00575 sis2.str(ps1 + "\n");
00576 mezclaRec(sis1, sis2, sos, true, true, NULL, NULL);
00577 CPPUNIT_ASSERT(sos.str() == (ps1 + "\n") );
00578
00579 sos.clear();
00580 sos.str("");
00581 sis1.clear();
00582 sis1.str(ps4);
00583 sis2.clear();
00584 sis2.str(ps4);
00585 mezclaRec(sis1, sis2, sos, true, true, NULL, NULL);
00586 CPPUNIT_ASSERT(sos.str() == ps4 );
00587
00588
00589 sos.clear();
00590 sos.str("");
00591 sis1.clear();
00592 sis1.str(ps2 + "\n");
00593 sis2.clear();
00594 sis2.str(ps2 + "\n");
00595 mezclaRec(sis1, sis2, sos, true, true, NULL, NULL);
00596 CPPUNIT_ASSERT(sos.str() == (ps2 + "\n") );
00597
00598 sos.clear();
00599 sos.str("");
00600 sis1.clear();
00601 sis1.str(ps2 + "\n");
00602 sis2.clear();
00603 sis2.str(ps3 + "\n");
00604 mezclaRec(sis1, sis2, sos, true, true, NULL, NULL);
00605 CPPUNIT_ASSERT(sos.str() == (ps3 + "\n") );
00606
00607 sos.clear();
00608 sos.str("");
00609 sis1.clear();
00610 sis1.str(ps5);
00611 sis2.clear();
00612 sis2.str(ps5);
00613 mezclaRec(sis1, sis2, sos, false, false, NULL, NULL);
00614
00615 CPPUNIT_ASSERT(sos.str() == (ps1 + "\n") );
00616
00617 sos.clear();
00618 sos.str("");
00619 sis1.clear();
00620 sis1.str(ps8);
00621 sis2.clear();
00622 sis2.str(ps9);
00623 mezclaRec(sis1, sis2, sos, true, false, NULL, NULL);
00624 CPPUNIT_ASSERT(sos.str() == ps8 );
00625
00626 sos.clear();
00627 sos.str("");
00628 sis1.clear();
00629 sis1.str(ps8);
00630 sis2.clear();
00631 sis2.str(ps9);
00632 mezclaRec(sis1, sis2, sos, false, true, NULL, NULL);
00633 CPPUNIT_ASSERT(sos.str() == ps9);
00634
00635 sos.clear();
00636 sos.str("");
00637 sis1.clear();
00638 sis1.str(ps8);
00639 sis2.clear();
00640 sis2.str(ps9);
00641 mezclaRec(sis1, sis2, sos, true, true, NULL, NULL);
00642
00643 CPPUNIT_ASSERT(sos.str() == ps10);
00644
00645 sos.clear();
00646 sos.str("");
00647 sis1.clear();
00648 sis1.str(ps9);
00649 sis2.clear();
00650 sis2.str(ps8);
00651 mezclaRec(sis1, sis2, sos, true, true, NULL, NULL);
00652 CPPUNIT_ASSERT(sos.str() == ps10);
00653
00654 sos.clear();
00655 sos.str("");
00656 sis1.clear();
00657 sis1.str(ps1 + "\n");
00658 sis2.clear();
00659 sis2.str(ps11);
00660 mezclaRec(sis1, sis2, sos, true, true, NULL, NULL);
00661
00662 CPPUNIT_ASSERT(sos.str() == ps4 );
00663
00664 sos.clear();
00665 sos.str("");
00666 sis1.clear();
00667 sis1.str(ps11);
00668 sis2.clear();
00669 sis2.str(ps1 + "\n");
00670 mezclaRec(sis1, sis2, sos, true, true, NULL, NULL);
00671
00672 CPPUNIT_ASSERT(sos.str() == ps4 );
00673
00674
00675 sos.clear();
00676 sos.str("");
00677 sis1.clear();
00678 sis1.str(ps12);
00679 sis2.clear();
00680 sis2.str(ps11);
00681 mezclaRec(sis1, sis2, sos, true, true, NULL, NULL);
00682
00683 CPPUNIT_ASSERT(sos.str() == ps13 );
00684
00685 sos.clear();
00686 sos.str("");
00687 sis1.clear();
00688 sis1.str(ps11);
00689 sis2.clear();
00690 sis2.str(ps12);
00691 mezclaRec(sis1, sis2, sos, true, true, NULL, NULL);
00692
00693 CPPUNIT_ASSERT(sos.str() == ps13 );
00694
00695
00696 NodoTrieS *nam = new NodoTrieS("am", NULL, NULL, set<Pos>());
00697 NodoTrieS *na = new NodoTrieS();
00698 na->inserta("a", Pos(1,1));
00699
00700
00701 sos.clear();
00702 sos.str("");
00703 llena_ss(sis1, nam);
00704 llena_ss(sis2, na);
00705 mezclaRec(sis1, sis2, sos, true, true, NULL, NULL);
00706
00707 NodoTrieS *nm = new NodoTrieS("m", NULL, NULL, set<Pos>());
00708 na->hijo_menor = nm;
00709 std::stringstream sist;
00710 llena_ss(sist, na);
00711
00712
00713 CPPUNIT_ASSERT(sos.str() == sist.str());
00714 delete na;
00715 delete nam;
00716
00717
00718 sos.clear();
00719 sos.str("");
00720 nam = new NodoTrieS("am", NULL, NULL, set<Pos>());
00721 llena_ss(sis1, nam);
00722 NodoTrieS *no = new NodoTrieS("o", NULL, NULL, set<Pos>());
00723 na = new NodoTrieS("a", no, NULL, set<Pos>());
00724 llena_ss(sis2, na);
00725
00726 mezclaRec(sis1, sis2, sos, true, true, NULL, NULL);
00727 delete na;
00728 delete nam;
00729
00730 no = new NodoTrieS("o", NULL, NULL, set<Pos>());
00731 nm = new NodoTrieS("m", NULL, no , set<Pos>());
00732 na = new NodoTrieS("a", nm, NULL, set<Pos>());
00733 llena_ss(sist, na);
00734
00735 CPPUNIT_ASSERT(sos.str() == sist.str() );
00736
00737 delete na;
00738
00739
00740 NodoTrieS *naa = new NodoTrieS("aa", NULL, NULL, set<Pos>());
00741 NodoTrieS *nab = new NodoTrieS();
00742 nab->inserta("ab", Pos(1,1));
00743 llena_ss(sis1, naa);
00744 llena_ss(sis2, nab);
00745 sos.clear();
00746 sos.str("");
00747 mezclaRec(sis1, sis2, sos, true, true, NULL, NULL);
00748 delete naa;
00749 delete nab;
00750 NodoTrieS *nb = new NodoTrieS();
00751 nb->inserta("b", Pos(1,1));
00752 NodoTrieS *na2 = new NodoTrieS("a", NULL, nb, set<Pos>());
00753 na = new NodoTrieS("a", na2, NULL, set<Pos>());
00754 llena_ss(sist,na);
00755
00756 CPPUNIT_ASSERT(sos.str() == sist.str() );
00757 delete na;
00758
00759
00760 sos.clear();
00761 sos.str("");
00762 nm = new NodoTrieS("m", NULL, NULL, set<Pos>());
00763 naa = new NodoTrieS("aa", nm, NULL, set<Pos>());
00764 llena_ss(sis1, naa);
00765 delete naa;
00766 nm = new NodoTrieS("m", NULL, NULL, set<Pos>());
00767 nab = new NodoTrieS("ab", nm, NULL, set<Pos>());
00768 llena_ss(sis2, nab);
00769 delete nab;
00770 mezclaRec(sis1, sis2, sos, true, true, NULL, NULL);
00771 NodoTrieS *nm2 = new NodoTrieS("m", NULL, NULL, set<Pos>());
00772 nm = new NodoTrieS("m", NULL, NULL, set<Pos>());
00773 nab = new NodoTrieS("b", nm, NULL, set<Pos>());
00774 naa = new NodoTrieS("a", nm2, nab, set<Pos>());
00775 na = new NodoTrieS("a", naa, NULL, set<Pos>());
00776 llena_ss(sist, na);
00777 delete na;
00778
00779 CPPUNIT_ASSERT(sos.str() == sist.str() );
00780
00781
00782 sos.clear();
00783 sos.str("");
00784 nab = new NodoTrieS("ab", NULL, NULL, set<Pos>());
00785 llena_ss(sis1, nab);
00786 delete nab;
00787 naa = new NodoTrieS();
00788 naa->inserta("aa", Pos(1,1));
00789 llena_ss(sis2, naa);
00790 delete naa;
00791 mezclaRec(sis1, sis2, sos, true, true, NULL, NULL);
00792 nb = new NodoTrieS("b");
00793 naa = new NodoTrieS("a",NULL, nb, Pos(1,1));
00794 na = new NodoTrieS("a", naa, NULL);
00795 llena_ss(sist, na);
00796 delete na;
00797
00798 CPPUNIT_ASSERT(sos.str() == sist.str() );
00799
00800 sos.clear();
00801 sos.str("");
00802 nm = new NodoTrieS("m");
00803 nab = new NodoTrieS("ab", nm, NULL);
00804 llena_ss(sis1, nab);
00805 delete nab;
00806 nm = new NodoTrieS("m");
00807 naa = new NodoTrieS("aa", nm, NULL);
00808 llena_ss(sis2, naa);
00809 delete naa;
00810 mezclaRec(sis1, sis2, sos, true, true, NULL, NULL);
00811
00812 nm = new NodoTrieS("m");
00813 nab = new NodoTrieS("b", nm);
00814 nm2 = new NodoTrieS("m");
00815 naa = new NodoTrieS("a", nm2, nab);
00816 na = new NodoTrieS("a", naa);
00817 llena_ss(sist, na);
00818 delete na;
00819
00820 CPPUNIT_ASSERT(sos.str() == sist.str());
00821
00822 sos.clear();
00823 sos.str("");
00824 na = new NodoTrieS("a");
00825 llena_ss(sis1, na);
00826 delete na;
00827 nb = new NodoTrieS("b", NULL, NULL, Pos(1,1));
00828 llena_ss(sis2, nb);
00829 delete nb;
00830 mezclaRec(sis1, sis2, sos, true, true, NULL, NULL);
00831 nb = new NodoTrieS("b", NULL, NULL, Pos(1,1));
00832 na = new NodoTrieS("a", NULL, nb);
00833 llena_ss(sist, na);
00834 delete na;
00835
00836 CPPUNIT_ASSERT(sos.str() == sist.str() );
00837
00838 sos.clear();
00839 sos.str("");
00840 NodoTrieS *nr = new NodoTrieS("r");
00841 no = new NodoTrieS("o", nr);
00842 nm = new NodoTrieS("m", no);
00843 na = new NodoTrieS("a", nm);
00844 llena_ss(sis1, na);
00845 delete na;
00846 na = new NodoTrieS();
00847 na->inserta("a", Pos(1,1));
00848 llena_ss(sis2, na);
00849 delete na;
00850 mezclaRec(sis1, sis2, sos, true, true, NULL, NULL);
00851 nr = new NodoTrieS("r");
00852 no = new NodoTrieS("o", nr);
00853 nm = new NodoTrieS("m", no);
00854 na = new NodoTrieS("a", nm);
00855 na->inserta("a", Pos(1,1));
00856 llena_ss(sist, na);
00857 delete na;
00858
00859 CPPUNIT_ASSERT(sos.str() == sist.str());
00860
00861 sos.clear();
00862 sos.str("");
00863 na = new NodoTrieS();
00864 na->inserta("a", Pos(1,1));
00865 llena_ss(sis1, na);
00866 delete na;
00867 nr = new NodoTrieS("r");
00868 no = new NodoTrieS("o", nr);
00869 nm = new NodoTrieS("m", no);
00870 na = new NodoTrieS("a", nm);
00871 llena_ss(sis2, na);
00872 delete na;
00873 mezclaRec(sis1, sis2, sos, true, true, NULL, NULL);
00874 nr = new NodoTrieS("r");
00875 no = new NodoTrieS("o", nr);
00876 nm = new NodoTrieS("m", no);
00877 na = new NodoTrieS("a", nm);
00878 na->inserta("a", Pos(1,1));
00879 llena_ss(sist, na);
00880 delete na;
00881
00882 CPPUNIT_ASSERT(sos.str() == sist.str());
00883
00884
00885 sos.clear();
00886 sos.str("");
00887 nb = new NodoTrieS("b");
00888 na = new NodoTrieS("a", NULL, nb);
00889 llena_ss(sis1, na);
00890 delete na;
00891 na = new NodoTrieS("a");
00892 llena_ss(sis2, na);
00893 delete na;
00894 mezclaRec(sis1, sis2, sos, false, true, NULL, NULL);
00895 CPPUNIT_ASSERT(sos.str() == sis2.str() );
00896
00897 sos.clear();
00898 sos.str("");
00899 na = new NodoTrieS("a");
00900 llena_ss(sis1, na);
00901 delete na;
00902 nb = new NodoTrieS("b");
00903 na = new NodoTrieS("a", NULL, nb);
00904 llena_ss(sis2, na);
00905 delete na;
00906 mezclaRec(sis1, sis2, sos, true, false, NULL, NULL);
00907
00908 CPPUNIT_ASSERT(sos.str() == sis1.str() );
00909
00910
00911
00912
00913
00914
00915 sos.clear();
00916 sos.str("");
00917 na = new NodoTrieS("a");
00918 llena_ss(sis1, na);
00919 delete na;
00920 nr = new NodoTrieS("r");
00921 no = new NodoTrieS("o", nr);
00922 nm = new NodoTrieS("m", no);
00923 na = new NodoTrieS("a", nm);
00924 na->inserta("a", Pos(1,1));
00925 llena_ss(sis2, na);
00926 delete na;
00927 mezclaRec(sis1, sis2, sos, true, false, NULL, NULL);
00928
00929 CPPUNIT_ASSERT(sos.str()== sis2.str());
00930
00931 sos.clear();
00932 sos.str("");
00933
00934 nr = new NodoTrieS("r");
00935 no = new NodoTrieS("o", nr);
00936 nm = new NodoTrieS("m", no);
00937 na = new NodoTrieS("a", nm);
00938 na->inserta("a", Pos(1,1));
00939 llena_ss(sis1, na);
00940 delete na;
00941 na = new NodoTrieS("a");
00942 llena_ss(sis2, na);
00943 delete na;
00944 mezclaRec(sis1, sis2, sos, false, false, NULL, NULL);
00945
00946 CPPUNIT_ASSERT(sos.str() == sis1.str());
00947
00948
00949
00950
00951 sos.clear();
00952 sos.str("");
00953 sos << "a{0000=00000}";
00954 NodoTrieS *nc = new NodoTrieS("c");
00955 nb = new NodoTrieS("b", NULL, nc);
00956 llena_ss(sis1, nb);
00957 delete nb;
00958 nb = new NodoTrieS("b");
00959 llena_ss(sis2, nb);
00960 delete nb;
00961 mezclaRec(sis1, sis2, sos, true, true, NULL, NULL);
00962 nc = new NodoTrieS("c");
00963 nb = new NodoTrieS("b", NULL, nc);
00964 na = new NodoTrieS("a", NULL, nb);
00965 llena_ss(sist, na);
00966 delete na;
00967 CPPUNIT_ASSERT(sos.str() == sist.str());
00968
00969 sos.clear();
00970 sos.str("");
00971 sos << "a{0000=00000}";
00972 nc = new NodoTrieS("c");
00973 nb = new NodoTrieS("b", nc);
00974 llena_ss(sis1, nb);
00975 delete nb;
00976 nb = new NodoTrieS("b");
00977 llena_ss(sis2, nb);
00978 delete nb;
00979 mezclaRec(sis1, sis2, sos, true, true, NULL, NULL);
00980 nc = new NodoTrieS("c");
00981 nb = new NodoTrieS("b", nc);
00982 na = new NodoTrieS("a", NULL, nb);
00983 llena_ss(sist, na);
00984 delete na;
00985 CPPUNIT_ASSERT(sos.str() == sist.str() );
00986
00987 sos.clear();
00988 sos.str("");
00989 na = new NodoTrieS();
00990 na->inserta("a", Pos(1,1));
00991 llena_ss(sis1, na);
00992 delete na;
00993 nr = new NodoTrieS("r");
00994 no = new NodoTrieS("o", nr);
00995 nm = new NodoTrieS("m", no);
00996 na = new NodoTrieS("a", nm);
00997 llena_ss(sis2, na);
00998 delete na;
00999 vector<long> renum;
01000 renum.push_back(0);
01001 mezclaRec(sis1, sis2, sos, true, true, NULL, &renum);
01002
01003 nr = new NodoTrieS("r");
01004 no = new NodoTrieS("o", nr);
01005 nm = new NodoTrieS("m", no);
01006 na = new NodoTrieS("a", nm);
01007 na->inserta("a", Pos(1,1));
01008 llena_ss(sist, na);
01009 delete na;
01010 CPPUNIT_ASSERT(sos.str() == sist.str());
01011
01012 sos.clear();
01013 sos.str("");
01014 renum.clear();
01015 renum.push_back(1);
01016 nr = new NodoTrieS("r");
01017 no = new NodoTrieS("o", nr);
01018 nm = new NodoTrieS("m", no);
01019 na = new NodoTrieS("a", nm);
01020 llena_ss(sis1, na);
01021 delete na;
01022 na = new NodoTrieS();
01023 na->inserta("a", Pos(1,1));
01024 llena_ss(sis2, na);
01025 delete na;
01026
01027 mezclaRec(sis1, sis2, sos, true, true, NULL, &renum);
01028 nr = new NodoTrieS("r");
01029 no = new NodoTrieS("o", nr);
01030 nm = new NodoTrieS("m", no);
01031 na = new NodoTrieS("a", nm);
01032 na->inserta("a", Pos(2,1));
01033 llena_ss(sist, na);
01034 delete na;
01035
01036
01037 CPPUNIT_ASSERT(sos.str() == sist.str());
01038
01039 sos.clear();
01040 sos.str("");
01041 renum.clear();
01042 renum.push_back(0);
01043 nr = new NodoTrieS("r");
01044 no = new NodoTrieS("o", nr);
01045 nm = new NodoTrieS("m", no);
01046 na = new NodoTrieS("a", nm);
01047 llena_ss(sis1, na);
01048 delete na;
01049 nm = new NodoTrieS();
01050 nm->inserta("m", Pos(1, 1));
01051 NodoTrieS *nl = new NodoTrieS("l", NULL, nm);
01052 na = new NodoTrieS("a", nl);
01053 llena_ss(sis2, na);
01054 delete na;
01055 mezclaRec(sis1, sis2, sos, true, true, NULL, &renum);
01056 nr = new NodoTrieS("r");
01057 no = new NodoTrieS("o", nr);
01058 nm = new NodoTrieS("m", no);
01059 nm->inserta("m", Pos(1, 1));
01060 nl = new NodoTrieS("l", NULL, nm);
01061 na = new NodoTrieS("a", nl);
01062 llena_ss(sist, na);
01063 delete na;
01064
01065
01066 CPPUNIT_ASSERT(sos.str() == sist.str());
01067
01068
01069 na = new NodoTrieS();
01070 na->inserta("CINTURA", Pos(1, 1));
01071 na->inserta("CONTABAN", Pos(1, 15));
01072 na->inserta("COMFESABAN", Pos(1, 11));
01073 na->inserta("COMIA", Pos(1, 8));
01074 sos.clear();
01075 sos.str(MARCAIND + "\n");
01076 sos.seekp(MARCAIND.length() +1);
01077 sos.seekg(MARCAIND.length() +1);
01078 sos.clear();
01079 escribePlanoStream(na, sos);
01080 sos.seekg(0);
01081
01082 sos.seekg(0);
01083 CPPUNIT_ASSERT(sos.str().length() == 134);
01084 delete na;
01085
01086
01087 sos.clear();
01088 sos.str("");
01089 renum.clear();
01090 renum.push_back(1);
01091 sos << MARCAIND << "\n";
01092 na = new NodoTrieS();
01093 na->inserta("EM", Pos(1, 1));
01094 llena_ss(sis1, na);
01095 delete na;
01096 na = new NodoTrieS();
01097 na->inserta("CINTURA", Pos(1, 1));
01098 na->inserta("CONTABAN", Pos(1, 15));
01099 na->inserta("COMFESABAN", Pos(1, 11));
01100 na->inserta("COMIA", Pos(1, 8));
01101 sis2.clear();
01102 sis2.str("");
01103
01104
01105
01106
01107 escribePlanoStream(na, sis2);
01108
01109 sis2.seekg(0);
01110 delete na;
01111
01112 mezclaRec(sis1, sis2, sos, true, true, NULL, &renum);
01113 na = new NodoTrieS();
01114 na->inserta("CINTURA", Pos(2, 1));
01115 na->inserta("CONTABAN", Pos(2, 15));
01116 na->inserta("COMFESABAN", Pos(2, 11));
01117 na->inserta("COMIA", Pos(2, 8));
01118 na->inserta("EM", Pos(1, 1));
01119
01120 sist.clear();
01121 sist.str("");
01122 sist.seekp(-1);
01123 sist.seekg(0);
01124 sist.clear();
01125 escribePlanoStream(na, sist, MARCAIND.length() + 1);
01126 sist.seekg(0);
01127 delete na;
01128
01129
01130
01131
01132
01133
01134
01135
01136
01137
01138
01139
01140
01141 CPPUNIT_ASSERT(sos.str() == (MARCAIND + "\n" + sist.str()));
01142 CPPUNIT_ASSERT((long)sos.tellp() == (long)sos.str().size() );
01143
01144 sos.clear();
01145 sos.str("");
01146 renum.clear();
01147 renum.push_back(1);
01148 renum.push_back(1);
01149 renum.push_back(2);
01150 sos << MARCAIND << "\n";
01151 na = new NodoTrieS();
01152 na->inserta("JESUS", Pos(2, 2));
01153 llena_ss(sis1, na, MARCAIND + "\n");
01154 delete na;
01155
01156 na = new NodoTrieS();
01157 na->inserta("JORAM", Pos(3, 2));
01158 na->inserta("JOTAM", Pos(2, 2));
01159 llena_ss(sis2, na, MARCAIND + "\n");
01160 delete na;
01161
01162 try {
01163 sis1.seekg(MARCAIND.length() + 1);
01164 sis2.seekg(MARCAIND.length() + 1);
01165 mezclaRec(sis1, sis2, sos, true, true, NULL, &renum);
01166
01167 CPPUNIT_ASSERT(sos.str() == ps15);
01168 CPPUNIT_ASSERT((long)sos.tellp() == (long)sos.str().size() );
01169
01170
01171
01172 sos.clear();
01173 sos.str("");
01174 renum.clear();
01175 renum.push_back(0);
01176
01177 vector<long> renum1;
01178 renum1.clear();
01179 renum1.push_back(2);
01180 sos << MARCAIND << "\n";
01181 na = new NodoTrieS();
01182 na->inserta("JESUS", Pos(1, 1));
01183 llena_ss(sis1, na, MARCAIND + "\n");
01184 delete na;
01185
01186
01187
01188 na = new NodoTrieS();
01189 na->inserta("AMADO", Pos(1, 1));
01190 na->inserta("MIO", Pos(2, 2));
01191 llena_ss(sis2, na, MARCAIND + "\n");
01192 delete na;
01193 renum.clear();
01194 renum.push_back(0);
01195 renum.push_back(1);
01196
01197
01198 sis1.seekg(MARCAIND.length() + 1);
01199 sis2.seekg(MARCAIND.length() + 1);
01200 mezclaRec(sis1, sis2, sos, true, true, &renum1, &renum);
01201
01202
01203 sos.seekg(MARCAIND.length() + 1);
01204 NodoTrieS *l1 = leePlanoStream(sos);
01205
01206 set<Pos> cr = l1->busca("JESUS");
01207 CPPUNIT_ASSERT(cr.size() == 1);
01208 set<Pos>::iterator i = cr.begin();
01209 CPPUNIT_ASSERT((*i).numd == 3);
01210 cr = l1->busca("AMADO");
01211 CPPUNIT_ASSERT(cr.size() == 1);
01212 i = cr.begin();
01213 CPPUNIT_ASSERT((*i).numd == 1);
01214
01215
01216 delete l1;
01217 } catch (std::string s) {
01218 cerr << s << endl;
01219 exit(1);
01220 }
01221
01222 }
01223
01224 void TrieSDiscoCasoPrueba::prueba_leeRelacion()
01225 {
01226 vector<Doc> docs;
01227
01228 {
01229 fstream os("/tmp/z", ios_base::out);
01230 os << "";
01231 os.close();
01232 }
01233 docs.clear();
01234 CPPUNIT_ASSERT_THROW(leeRelacion("/tmp/z", docs), std::string);
01235
01236
01237 {
01238 fstream os("/tmp/z", ios_base::out);
01239 os << "0fffffff";
01240 os.close();
01241 }
01242 docs.clear();
01243 CPPUNIT_ASSERT_THROW(leeRelacion("/tmp/z", docs), std::string);
01244
01245
01246 {
01247 fstream os("/tmp/z", ios_base::out);
01248 os << MARCAREL << "\n" ;
01249 os << "a1 12345678901234567890123456789012 2009-01-01" << endl;
01250 os << "b2 abcdefabcdefabcdefabcdefabcdefab 2009-01-01" << endl;
01251 os << "c3 00000000000000000000000000000000 2009-01-01" << endl;
01252 os.close();
01253 }
01254 docs.clear();
01255 leeRelacion("/tmp/z", docs);
01256
01257 CPPUNIT_ASSERT(docs.size() == 3);
01258 CPPUNIT_ASSERT(docs[0].URL == "a1");
01259 CPPUNIT_ASSERT(docs[1].URL == "b2");
01260 CPPUNIT_ASSERT(docs[2].URL == "c3");
01261 CPPUNIT_ASSERT(docs[0].cond == "12345678901234567890123456789012");
01262 CPPUNIT_ASSERT(docs[1].cond == "abcdefabcdefabcdefabcdefabcdefab");
01263 CPPUNIT_ASSERT(docs[2].cond == "00000000000000000000000000000000");
01264
01265 {
01266 fstream os("/tmp/z", ios_base::out);
01267 os.seekg(0);
01268 os << MARCAREL << "\n" ;
01269 for (unsigned int i = 0; i < MAXLURL+2; i++) {
01270 os << "x";
01271 }
01272 os.close();
01273 }
01274 docs.clear();
01275 CPPUNIT_ASSERT_THROW(leeRelacion("/tmp/z", docs), std::string);
01276
01277 }
01278
01279
01280 void TrieSDiscoCasoPrueba::prueba_escribeRelacion()
01281 {
01282 vector<Doc> docs;
01283 docs.clear();
01284 escribeRelacion("/tmp/z", docs);
01285 docs.push_back(Doc("a","b","2009-10-14"));
01286 escribeRelacion("/tmp/z", docs);
01287 docs.push_back(Doc("c","d","2009-10-13"));
01288 escribeRelacion("/tmp/z", docs);
01289 vector<long> reord;
01290 reord.push_back(1);
01291 reord.push_back(0);
01292 escribeRelacion("/tmp/z1", docs, &reord);
01293
01294 }
01295
01296
01297 void TrieSDiscoCasoPrueba::prueba_buscaPlano()
01298 {
01299 fstream os1("ej.indice", ios_base::out);
01300 os1 << "";
01301 os1.close();
01302
01303 vector<Doc> docs;
01304 docs.push_back(Doc("ej.txt","m","2010-01-05"));
01305 escribeRelacion("ej.relacion", docs, NULL);
01306
01307 CPPUNIT_ASSERT_THROW(buscaPlano("ej.indice", "ej.relacion", "JESUS",
01308 docs), std::string);
01309
01310 fstream os("ej.indice", ios_base::out);
01311 os << ps15;
01312 os.close();
01313
01314 set<Pos> *b = buscaPlano("ej.indice", "ej.relacion",
01315 "JESUS", docs);
01316 CPPUNIT_ASSERT(b->size() == 1);
01317 }
01318
01319
01320 void TrieSDiscoCasoPrueba::prueba_buscaPlanoStream()
01321 {
01322 stringstream sis;
01323 sis.clear();
01324 sis.str(ps15);
01325 sis.seekg(MARCAIND.length() + 1);
01326 set<Pos> *b = buscaPlanoStream(sis, "P");
01327 CPPUNIT_ASSERT(b == NULL);
01328 delete b;
01329
01330
01331
01332 NodoTrieS *na = new NodoTrieS();
01333 na->inserta("CINTURA", Pos(2, 1));
01334 na->inserta("CONTABAN", Pos(2, 15));
01335 na->inserta("COMFESABAN", Pos(2, 11));
01336 na->inserta("COMIA", Pos(2, 8));
01337 na->inserta("EM", Pos(1, 1));
01338 llena_ss(sis, na);
01339 b = buscaPlanoStream(sis, "CINTURA");
01340 CPPUNIT_ASSERT(b->size() == 1);
01341 delete na;
01342
01343
01344
01345
01346
01347
01348
01349
01350
01351
01352
01353
01354 }
01355
01356 void TrieSDiscoCasoPrueba::setUp()
01357 {
01358 return;
01359 }