COIN-OR::LEMON - Graph Library

Changeset 774:4297098d9677 in lemon-0.x for src/test/unionfind_test.cc


Ignore:
Timestamp:
08/30/04 14:01:47 (17 years ago)
Author:
Alpar Juttner
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1066
Message:

Merge back the whole branches/hugo++ to trunk.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/test/unionfind_test.cc

    r542 r774  
    33#include <hugo/maps.h>
    44#include <hugo/unionfind.h>
     5#include "test_tools.h"
    56
    67using namespace hugo;
    78using namespace std;
    8 
    9 bool passed = true;
    10 
    11 void check(bool rc) {
    12   passed = passed && rc;
    13   if(!rc) {
    14     cout << "Test failed!" << endl;
    15   }
    16 }
    179
    1810template <typename T>
     
    2315void print(UFE const &ufe) {
    2416  UFE::ClassIt cit;
    25   cout << "printing the classes of the structure:" << endl;
     17  cout << "Print the classes of the structure:" << endl;
    2618  int i = 1;
    2719  for (ufe.first(cit); ufe.valid(cit); ufe.next(cit)) {
     
    4234  UFE U(base);
    4335
    44   print(U);
     36//   print(U);
    4537
    46   cout << "Inserting 1..." << endl;
     38  cout << "Insert 1..." << endl;
    4739  U.insert(1);
    48   print(U);
     40//   print(U);
    4941 
    50   cout << "Inserting 2..." << endl;
     42  cout << "Insert 2..." << endl;
    5143  U.insert(2);
    52   print(U);
     44//   print(U);
    5345 
    54   cout << "Joining 1 and 2..." << endl;
    55   check(U.join(1,2));
    56   print(U);
     46  cout << "Join 1 and 2..." << endl;
     47  check(U.join(1,2),"Test failed.");
     48//   print(U);
    5749
    58   cout << "Inserting 3, 4, 5, 6, 7..." << endl;
     50  cout << "Insert 3, 4, 5, 6, 7..." << endl;
    5951  U.insert(3);
    6052  U.insert(4);
     
    6254  U.insert(6);
    6355  U.insert(7);
    64   print (U);
     56//   print (U);
    6557
    66   cout << "Joining 1 - 4, 2 - 4 and 3 - 5 ..." << endl;
    67   check(U.join(1,4));
    68   check(!U.join(2,4));
    69   check(U.join(3,5));
    70   print(U);
     58  cout << "Join 1 - 4, 2 - 4 and 3 - 5 ..." << endl;
     59  check(U.join(1,4),"Test failed.");
     60  check(!U.join(2,4),"Test failed.");
     61  check(U.join(3,5),"Test failed.");
     62//   print(U);
    7163
    72   cout << "Inserting 8 to the component of 5 ..." << endl;
     64  cout << "Insert 8 to the component of 5 ..." << endl;
    7365  U.insert(8,5);
    74   print(U);
     66//   print(U);
    7567
    76   cout << "size of the class of 4: " << U.size(4) << endl;
    77   check(U.size(4) == 3);
    78   cout << "size of the class of 5: " << U.size(5) << endl;
    79   check(U.size(5) == 3);
    80   cout << "size of the class of 6: " << U.size(6) << endl;
    81   check(U.size(6) == 1);
    82   cout << "size of the class of 2: " << U.size(2) << endl;
    83   check(U.size(2) == 3);
     68  cout << "Size of the class of 4: " << U.size(4) << endl;
     69  check(U.size(4) == 3,"Test failed.");
     70  cout << "Size of the class of 5: " << U.size(5) << endl;
     71  check(U.size(5) == 3,"Test failed.");
     72  cout << "Size of the class of 6: " << U.size(6) << endl;
     73  check(U.size(6) == 1,"Test failed.");
     74  cout << "Size of the class of 2: " << U.size(2) << endl;
     75  check(U.size(2) == 3,"Test failed.");
    8476
    85   cout << "Inserting 9 ..." << endl;
     77  cout << "Insert 9 ..." << endl;
    8678  U.insert(9);
    87   print(U);
    88   cout << "Inserting 10 to the component of 9 ..." << endl;
     79//   print(U);
     80  cout << "Insert 10 to the component of 9 ..." << endl;
    8981  U.insert(10,9);
    90   print(U);
     82//   print(U);
    9183
    92   cout << "Joining 8 and 10..." << endl;
    93   check(U.join(8,10));
    94   print(U);
     84  cout << "Join 8 and 10..." << endl;
     85  check(U.join(8,10),"Test failed.");
     86//   print(U);
    9587
    9688  cout << "Move 9 to the class of 4 ..." << endl;
    97   check(U.move(9,4));
    98   print(U);
     89  check(U.move(9,4),"Test failed.");
     90//   print(U);
    9991
    10092  cout << "Move 9 to the class of 2 ..." << endl;
    101   check(!U.move(9,2));
    102   print(U);
     93  check(!U.move(9,2),"Test failed.");
     94//   print(U);
    10395
    104   cout << "size of the class of 4: " << U.size(4) << endl;
    105   check(U.size(4) == 4);
    106   cout << "size of the class of 9: " << U.size(9) << endl;
    107   check(U.size(9) == 4);
     96  cout << "Size of the class of 4: " << U.size(4) << endl;
     97  check(U.size(4) == 4,"Test failed.");
     98  cout << "Size of the class of 9: " << U.size(9) << endl;
     99  check(U.size(9) == 4,"Test failed.");
    108100 
    109101  cout << "Move 5 to the class of 6 ..." << endl;
    110   check(U.move(5,6));
    111   print(U);
     102  check(U.move(5,6),"Test failed.");
     103//   print(U);
    112104
    113   cout << "size of the class of 5: " << U.size(5) << endl;
    114   check(U.size(5) == 2);
    115   cout << "size of the class of 8: " << U.size(8) << endl;
    116   check(U.size(8) == 3);
     105  cout << "Size of the class of 5: " << U.size(5) << endl;
     106  check(U.size(5) == 2,"Test failed.");
     107  cout << "Size of the class of 8: " << U.size(8) << endl;
     108  check(U.size(8) == 3,"Test failed.");
    117109
    118110  cout << "Move 7 to the class of 10 ..." << endl;
    119   check(U.move(7,10));
    120   print(U);
     111  check(U.move(7,10),"Test failed.");
     112//   print(U);
    121113
    122   cout << "size of the class of 7: " << U.size(7) << endl;
    123   check(U.size(7) == 4);
     114  cout << "Size of the class of 7: " << U.size(7) << endl;
     115  check(U.size(7) == 4,"Test failed.");
    124116
    125   cout <<"erase 9: " << endl;
     117  cout <<"Erase 9... " << endl;
    126118  U.erase(9);
    127   print(U);
     119//   print(U);
    128120
    129   cout <<"erase 1: " << endl;
     121  cout <<"Erase 1... " << endl;
    130122  U.erase(1);
    131   print(U);
     123//   print(U);
    132124
    133   cout << "size of the class of 4: " << U.size(4) << endl;
    134   check(U.size(4) == 2);
    135   cout << "size of the class of 2: " << U.size(2) << endl;
    136   check(U.size(2) == 2);
     125  cout << "Size of the class of 4: " << U.size(4) << endl;
     126  check(U.size(4) == 2,"Test failed.");
     127  cout << "Size of the class of 2: " << U.size(2) << endl;
     128  check(U.size(2) == 2,"Test failed.");
    137129
    138130
    139   cout <<"erase 1: " << endl;
     131  cout <<"Erase 1... " << endl;
    140132  U.erase(1);
    141   print(U);
     133//   print(U);
    142134
    143   cout <<"erase 6: " << endl;
     135  cout <<"Erase 6... " << endl;
    144136  U.erase(6);
    145   print(U);
     137//   print(U);
    146138
    147   cout << "split the class of 8: " << endl;
     139  cout << "Split the class of 8... " << endl;
    148140  U.split(8);
    149   print(U);
     141//   print(U);
    150142
    151143
    152   cout << "size of the class of 4: " << U.size(4) << endl;
    153   check(U.size(4) == 2);
    154   cout << "size of the class of 3: " << U.size(3) << endl;
    155   check(U.size(3) == 1);
    156   cout << "size of the class of 2: " << U.size(2) << endl;
    157   check(U.size(2) == 2);
     144  cout << "Size of the class of 4: " << U.size(4) << endl;
     145  check(U.size(4) == 2,"Test failed.");
     146  cout << "Size of the class of 3: " << U.size(3) << endl;
     147  check(U.size(3) == 1,"Test failed.");
     148  cout << "Size of the class of 2: " << U.size(2) << endl;
     149  check(U.size(2) == 2,"Test failed.");
    158150
    159151
    160   cout << "Joining 3 - 4 and 2 - 4 ..." << endl;
    161   check(U.join(3,4));
    162   check(!U.join(2,4));
    163   print(U);
     152  cout << "Join 3 - 4 and 2 - 4 ..." << endl;
     153  check(U.join(3,4),"Test failed.");
     154  check(!U.join(2,4),"Test failed.");
     155//   print(U);
    164156
    165157
    166   cout << "size of the class of 4: " << U.size(4) << endl;
    167   check(U.size(4) == 3);
    168   cout << "size of the class of 3: " << U.size(3) << endl;
    169   check(U.size(3) == 3);
    170   cout << "size of the class of 2: " << U.size(2) << endl;
    171   check(U.size(2) == 3);
     158  cout << "Size of the class of 4: " << U.size(4) << endl;
     159  check(U.size(4) == 3,"Test failed.");
     160  cout << "Size of the class of 3: " << U.size(3) << endl;
     161  check(U.size(3) == 3,"Test failed.");
     162  cout << "Size of the class of 2: " << U.size(2) << endl;
     163  check(U.size(2) == 3,"Test failed.");
    172164
    173   cout << "makeRep(4)" << endl;
     165  cout << "makeRep(4)..." << endl;
    174166  U.makeRep(4);
    175   print(U);
    176   cout << "makeRep(3)" << endl;
     167//   print(U);
     168  cout << "makeRep(3)..." << endl;
    177169  U.makeRep(3);
    178   print(U);
    179   cout << "makeRep(2)" << endl;
     170//   print(U);
     171  cout << "makeRep(2)..." << endl;
    180172  U.makeRep(2);
    181   print(U);
     173//   print(U);
    182174
    183   cout << "size of the class of 4: " << U.size(4) << endl;
    184   check(U.size(4) == 3);
    185   cout << "size of the class of 3: " << U.size(3) << endl;
    186   check(U.size(3) == 3);
    187   cout << "size of the class of 2: " << U.size(2) << endl;
    188   check(U.size(2) == 3);
     175  cout << "Size of the class of 4: " << U.size(4) << endl;
     176  check(U.size(4) == 3,"Test failed.");
     177  cout << "Size of the class of 3: " << U.size(3) << endl;
     178  check(U.size(3) == 3,"Test failed.");
     179  cout << "Size of the class of 2: " << U.size(2) << endl;
     180  check(U.size(2) == 3,"Test failed.");
    189181
    190182
    191183  cout << "eraseClass 4 ..." << endl;
    192184  U.eraseClass(4);
    193   print(U);
     185//   print(U);
    194186
    195187  cout << "eraseClass 7 ..." << endl;
    196188  U.eraseClass(7);
    197   print(U);
     189//   print(U);
    198190
    199   cout << "done" << endl;
    200 
    201   cout << (passed ? "All tests passed." : "Some of the tests failed!!!")
    202        << endl;
    203 
    204   return passed ? 0 : 1;
     191  cout << "done." << endl;
    205192}
Note: See TracChangeset for help on using the changeset viewer.