src/work/klao/path_test.cc
author marci
Tue, 27 Apr 2004 14:10:19 +0000
changeset 446 77ef5c7a57d9
parent 227 cea88d0854a9
child 493 bbd1db03f0fe
permissions -rw-r--r--
comparison for matchings with leda
klao@225
     1
#include <string>
klao@225
     2
#include <iostream>
klao@225
     3
klao@225
     4
#include <path.h>
klao@225
     5
#include <list_graph.h>
klao@225
     6
klao@225
     7
using namespace std;
klao@225
     8
using namespace hugo;
klao@225
     9
klao@225
    10
bool passed = true;
klao@225
    11
klao@225
    12
void check(bool rc) {
klao@225
    13
  passed = passed && rc;
klao@225
    14
  if(!rc) {
klao@225
    15
    cout << "Test failed!" << endl;
klao@225
    16
  }
klao@225
    17
}
klao@225
    18
klao@225
    19
int main() {
klao@225
    20
klao@225
    21
  typedef ListGraph::Node Node;
klao@225
    22
  typedef ListGraph::Edge Edge;
klao@225
    23
klao@225
    24
  ListGraph G;
klao@225
    25
klao@225
    26
  Node s=G.addNode();
klao@225
    27
  Node v1=G.addNode();
klao@225
    28
  Node v2=G.addNode();
klao@225
    29
  Node v3=G.addNode();
klao@225
    30
  Node v4=G.addNode();
klao@225
    31
  Node t=G.addNode();
klao@225
    32
  
klao@225
    33
  Edge e1 = G.addEdge(s, v1);
klao@225
    34
  Edge e2 = G.addEdge(s, v2);
klao@225
    35
  Edge e3 = G.addEdge(v1, v2);
klao@225
    36
  Edge e4 = G.addEdge(v2, v1);
klao@225
    37
  Edge e5 = G.addEdge(v1, v3);
klao@225
    38
  Edge e6 = G.addEdge(v3, v2);
klao@225
    39
  Edge e7 = G.addEdge(v2, v4);
klao@225
    40
  Edge e8 = G.addEdge(v4, v3);
klao@225
    41
  Edge e9 = G.addEdge(v3, t);
klao@225
    42
  Edge e10 = G.addEdge(v4, t);
klao@225
    43
klao@225
    44
  bool rc;
klao@225
    45
klao@369
    46
  {
klao@369
    47
    cout << "DynamicPath tesztelese...\n";
klao@225
    48
klao@369
    49
    cout << "Ures path letrehozasa" << endl;
klao@369
    50
    typedef DynamicPath<ListGraph> LPath;
klao@369
    51
    LPath P(G);
klao@225
    52
klao@369
    53
    cout << "P.length() == " << P.length() << endl;
klao@369
    54
    check(P.length() == 0);
klao@225
    55
klao@369
    56
    cout << "P.from() valid? " << G.valid(P.from()) << endl;
klao@369
    57
    check(! G.valid(P.from()));
klao@225
    58
klao@369
    59
    cout << "Hozzaadunk ket elet..." << endl;
klao@369
    60
    check(P.pushBack(e1));
klao@369
    61
    check(P.pushBack(e3));
klao@369
    62
    cout << "P.length() == " << P.length() << endl;
klao@369
    63
    check(P.length() == 2);
klao@369
    64
klao@369
    65
    cout << "P.from() valid? " << G.valid(P.from()) << endl;
klao@369
    66
    check(G.valid(P.from()));
klao@225
    67
  
klao@369
    68
    cout << "P.from()==s ? " << (P.from()==s) << endl;
klao@369
    69
    check(P.from() == s);
klao@225
    70
klao@369
    71
    cout << "Hozzaadunk egy nem illeszkedo elt." << endl;
klao@369
    72
    rc = P.pushBack(e8);
klao@369
    73
    cout << "Sukerult: " << rc << endl;
klao@369
    74
    check(!rc);
klao@225
    75
klao@369
    76
    cout << "Meg 3 el hozzaadasa, nem mind elore iranyu..." << endl;
klao@369
    77
    check(P.pushBack(e6));
klao@369
    78
    check(P.pushBack(e8));
klao@369
    79
    check(P.pushBack(e10));
klao@225
    80
klao@369
    81
    cout << "P.length() == " << P.length() << endl;
klao@369
    82
    check(P.length() == 5);
klao@225
    83
klao@369
    84
    cout << "P.from()==s ? " << (P.from()==s) << endl;
klao@369
    85
    check(P.from() == s);
klao@369
    86
    cout << "P.to()==t ? " << (P.to()==t) << endl;
klao@369
    87
    check(P.to() == t);
klao@225
    88
klao@369
    89
    cout << "Vegpont bellitasa: " << endl;
klao@369
    90
    rc = P.setTo(v2);
klao@369
    91
    cout << "Hibasra: " << rc << endl;
klao@369
    92
    check(!rc);
klao@369
    93
    rc = P.setTo(t);
klao@369
    94
    cout << "Helyesre: " << rc << endl;
klao@369
    95
    check(rc);
klao@225
    96
klao@369
    97
    cout << "Elek iranyitasanak ellenorzese." << endl;
klao@369
    98
    cout << "El: " << e1 << ", G.tail(el): " << G.head(e1) << endl;
klao@369
    99
    check(G.tail(e1)==s);
klao@225
   100
klao@369
   101
    cout << "Vegigiteralunk az eleken." << endl;
klao@369
   102
    typedef LPath::NodeIt NodeIt;
klao@369
   103
    typedef LPath::EdgeIt EdgeIt;
klao@369
   104
    EdgeIt e = P.first<EdgeIt>();
klao@369
   105
    int i=1;
klao@369
   106
    for(; P.valid(e); P.next(e), ++i) {
klao@369
   107
      cout << i << ". el: " << P.graphEdge(e)
klao@369
   108
	   << ", elore el? " << P.isForward(e) << endl;
klao@369
   109
      if(i>=3 && i<5) 
klao@369
   110
	check(!P.isForward(e));
klao@369
   111
      else
klao@369
   112
	check(P.isForward(e));
klao@369
   113
    }
klao@369
   114
klao@369
   115
    {
klao@369
   116
      cout << "Reszut letrehozasa: [2. el, 4. el)..." << endl;
klao@369
   117
      LPath P2(P, P.nth<EdgeIt>(1), P.nth<EdgeIt>(3));
klao@369
   118
klao@369
   119
      cout << "P2.length() == " << P2.length() << endl;
klao@369
   120
      check(P2.length() == 2);
klao@369
   121
    
klao@369
   122
      cout << "P2.from()==v1 ? " << (P2.from()==v1) << endl;
klao@369
   123
      check(P2.from() == v1);
klao@369
   124
      cout << "P2.to()==v3 ? " << (P2.to()==v3) << endl;
klao@369
   125
      check(P2.to() == v3);
klao@369
   126
    }
klao@369
   127
    {
klao@369
   128
      cout << "Reszut letrehozasa: [1. el, 6. el)..." << endl;
klao@369
   129
      LPath P2(P, P.nth<EdgeIt>(0), P.nth<EdgeIt>(5));
klao@369
   130
klao@369
   131
      cout << "P2.length() == " << P2.length() << endl;
klao@369
   132
      check(P2.length() == 5);
klao@369
   133
    
klao@369
   134
      cout << "P2.from()==s ? " << (P2.from()==s) << endl;
klao@369
   135
      check(P2.from() == s);
klao@369
   136
      cout << "P2.to()==t ? " << (P2.to()==t) << endl;
klao@369
   137
      check(P2.to() == t);
klao@369
   138
    }
klao@369
   139
klao@369
   140
    {
klao@369
   141
      cout << "Ket pont altal megadott reszut letrehozasa: [2. pont, 4. pont]..."
klao@369
   142
	   << endl;
klao@369
   143
      LPath P2(P, P.nth<NodeIt>(1), P.nth<NodeIt>(3));
klao@369
   144
klao@369
   145
      cout << "P2.length() == " << P2.length() << endl;
klao@369
   146
      check(P2.length() == 2);
klao@369
   147
    
klao@369
   148
      cout << "P2.from()==v1 ? " << (P2.from()==v1) << endl;
klao@369
   149
      check(P2.from() == v1);
klao@369
   150
      cout << "P2.to()==v3 ? " << (P2.to()==v3) << endl;
klao@369
   151
      check(P2.to() == v3);
klao@369
   152
    }
klao@369
   153
    {
klao@369
   154
      cout << "Egy pontu reszut letrehozasa: [4. pont, 4. pont]..."
klao@369
   155
	   << endl;
klao@369
   156
      LPath P2(P, P.nth<NodeIt>(3), P.nth<NodeIt>(3));
klao@369
   157
klao@369
   158
      cout << "P2.length() == " << P2.length() << endl;
klao@369
   159
      check(P2.length() == 0);
klao@369
   160
    
klao@369
   161
      cout << "P2.from()==v3 ? " << (P2.from()==v3) << endl;
klao@369
   162
      check(P2.from() == v3);
klao@369
   163
      cout << "P2.to()==v3 ? " << (P2.to()==v3) << endl;
klao@369
   164
      check(P2.to() == v3);
klao@369
   165
    }
klao@369
   166
    {
klao@369
   167
      cout << "Forditott ut letrehozasa: [6. pont, 1. pont]..."
klao@369
   168
	   << endl;
klao@369
   169
      LPath P2(P, P.nth<NodeIt>(5), P.nth<NodeIt>(0));
klao@369
   170
klao@369
   171
      cout << "P2.length() == " << P2.length() << endl;
klao@369
   172
      check(P2.length() == 5);
klao@369
   173
    
klao@369
   174
      cout << "P2.from()==t ? " << (P2.from()==t) << endl;
klao@369
   175
      check(P2.from() == t);
klao@369
   176
      cout << "P2.to()==s ? " << (P2.to()==s) << endl;
klao@369
   177
      check(P2.to() == s);
klao@369
   178
    }
klao@369
   179
klao@225
   180
  }
klao@225
   181
klao@226
   182
  {
klao@369
   183
    cout << "\n\n\nDirPath tesztelese...\n";
klao@226
   184
klao@369
   185
klao@369
   186
    cout << "Ures path letrehozasa" << endl;
klao@369
   187
    typedef DirPath<ListGraph> DPath;
klao@369
   188
    DPath P(G);
klao@369
   189
klao@369
   190
    cout << "P.length() == " << P.length() << endl;
klao@369
   191
    check(P.length() == 0);
klao@369
   192
klao@369
   193
    cout << "P.from() valid? " << G.valid(P.from()) << endl;
klao@369
   194
    check(! G.valid(P.from()));
klao@369
   195
klao@369
   196
    {
klao@369
   197
      cout << "Builder objektum letrehozasa" << endl;
klao@369
   198
      DPath::Builder B(P);
klao@369
   199
klao@369
   200
      cout << "Hozzaadunk az elejehez ket elet..." << endl;
klao@369
   201
      check(B.pushFront(e6));
klao@369
   202
      check(B.pushFront(e5));
klao@369
   203
      cout << "P.length() == " << P.length() << endl;
klao@369
   204
      check(P.length() == 0);
klao@369
   205
      
klao@369
   206
      cout << "Commitolunk..." << endl;
klao@369
   207
      B.commit();
klao@369
   208
klao@369
   209
      cout << "P.length() == " << P.length() << endl;
klao@369
   210
      check(P.length() == 2);
klao@369
   211
      cout << "P.from() valid? " << G.valid(P.from()) << endl;
klao@369
   212
      check(G.valid(P.from()));
klao@369
   213
      cout << "P.from()==v1 ? " << (P.from()==v1) << endl;
klao@369
   214
      check(P.from() == v1);
klao@369
   215
klao@369
   216
      cout << "Hozzaadunk az elejehez egy nem illeszkedo elet..." << endl;
klao@369
   217
      check(!B.pushFront(e3));
klao@226
   218
    
klao@369
   219
      cout << "Hozzaadunk a vegehez ket elet..." << endl;
klao@369
   220
      check(B.pushBack(e7));
klao@369
   221
      check(B.pushBack(e8));
klao@369
   222
      cout << "P.length() == " << P.length() << endl;
klao@369
   223
      check(P.length() == 4);
klao@369
   224
klao@369
   225
      cout << "Hozzaadunk az elejehez meg egy elet..." << endl;
klao@369
   226
      check(B.pushFront(e4));
klao@369
   227
      cout << "P.length() == " << P.length() << endl;
klao@369
   228
      check(P.length() == 4);
klao@369
   229
      
klao@369
   230
      cout << "Es megvarjuk, amig megszunik a Builder...\n";
klao@369
   231
    }
klao@369
   232
    cout << "P.length() == " << P.length() << endl;
klao@369
   233
    check(P.length() == 5);
klao@369
   234
    cout << "P.from()==v2 ? " << (P.from()==v2) << endl;
klao@369
   235
    check(P.from() == v2);
klao@369
   236
klao@369
   237
    cout << "Vegigiteralunk az eleken." << endl;
klao@369
   238
    typedef DPath::NodeIt NodeIt;
klao@369
   239
    typedef DPath::EdgeIt EdgeIt;
klao@369
   240
    EdgeIt e;
klao@369
   241
    int i=1;
klao@369
   242
    for(P.first(e); P.valid(e); P.next(e), ++i) {
klao@369
   243
      cout << i << ". el: " << e << endl;
klao@369
   244
    }
klao@226
   245
  }
klao@225
   246
klao@225
   247
  cout << (passed ? "All tests passed." : "Some of the tests failed!!!")
klao@225
   248
       << endl;
klao@225
   249
klao@225
   250
  return passed ? 0 : 1;
klao@225
   251
}