src/work/klao/path_test.cc
author marci
Mon, 22 Mar 2004 15:53:05 +0000
changeset 232 cb87fb9d4c94
parent 226 616bc397c83a
child 369 dc9c19f4ca9a
permissions -rw-r--r--
.
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@225
    46
  cout << "Ures path letrehozasa" << endl;
klao@225
    47
  typedef Path<ListGraph> LPath;
klao@225
    48
  LPath P(G);
klao@225
    49
klao@225
    50
  cout << "P.length() == " << P.length() << endl;
klao@225
    51
  check(P.length() == 0);
klao@225
    52
klao@225
    53
  cout << "P.from() valid? " << G.valid(P.from()) << endl;
klao@225
    54
  check(! G.valid(P.from()));
klao@225
    55
klao@225
    56
  cout << "Hozzaadunk ket elet..." << endl;
klao@225
    57
  check(P.pushBack(e1));
klao@225
    58
  check(P.pushBack(e3));
klao@225
    59
  cout << "P.length() == " << P.length() << endl;
klao@225
    60
  check(P.length() == 2);
klao@225
    61
klao@225
    62
  cout << "P.from() valid? " << G.valid(P.from()) << endl;
klao@225
    63
  check(G.valid(P.from()));
klao@225
    64
  
klao@225
    65
  cout << "P.from()==s ? " << (P.from()==s) << endl;
klao@225
    66
  check(P.from() == s);
klao@225
    67
klao@225
    68
  cout << "Hozzaadunk egy nem illeszkedo elt." << endl;
klao@225
    69
  rc = P.pushBack(e8);
klao@225
    70
  cout << "Sukerult: " << rc << endl;
klao@225
    71
  check(!rc);
klao@225
    72
klao@227
    73
  cout << "Meg 3 el hozzaadasa, nem mind elore iranyu..." << endl;
klao@225
    74
  check(P.pushBack(e6));
klao@225
    75
  check(P.pushBack(e8));
klao@225
    76
  check(P.pushBack(e10));
klao@225
    77
klao@225
    78
  cout << "P.length() == " << P.length() << endl;
klao@225
    79
  check(P.length() == 5);
klao@225
    80
klao@225
    81
  cout << "P.from()==s ? " << (P.from()==s) << endl;
klao@225
    82
  check(P.from() == s);
klao@225
    83
  cout << "P.to()==t ? " << (P.to()==t) << endl;
klao@225
    84
  check(P.to() == t);
klao@225
    85
klao@225
    86
  cout << "Vegpont bellitasa: " << endl;
klao@225
    87
  rc = P.setTo(v2);
klao@225
    88
  cout << "Hibasra: " << rc << endl;
klao@225
    89
  check(!rc);
klao@225
    90
  rc = P.setTo(t);
klao@225
    91
  cout << "Helyesre: " << rc << endl;
klao@225
    92
  check(rc);
klao@225
    93
klao@225
    94
  cout << "Elek iranyitasanak ellenorzese." << endl;
klao@225
    95
  cout << "El: " << e1 << ", G.tail(el): " << G.head(e1) << endl;
klao@225
    96
  check(G.tail(e1)==s);
klao@225
    97
klao@225
    98
  cout << "Vegigiteralunk az eleken." << endl;
klao@225
    99
  typedef LPath::NodeIt NodeIt;
klao@225
   100
  typedef LPath::EdgeIt EdgeIt;
klao@225
   101
  EdgeIt e = P.first<EdgeIt>();
klao@225
   102
  int i=1;
klao@225
   103
  for(; P.valid(e); P.next(e), ++i) {
klao@225
   104
    cout << i << ". el: " << P.graphEdge(e)
klao@225
   105
	 << ", elore el? " << P.isForward(e) << endl;
klao@225
   106
    if(i>=3 && i<5) 
klao@225
   107
      check(!P.isForward(e));
klao@225
   108
    else
klao@225
   109
      check(P.isForward(e));
klao@225
   110
  }
klao@225
   111
klao@226
   112
  {
klao@226
   113
    cout << "Reszut letrehozasa: [2. el, 4. el)..." << endl;
klao@226
   114
    LPath P2(P, P.nth<EdgeIt>(1), P.nth<EdgeIt>(3));
klao@226
   115
klao@226
   116
    cout << "P2.length() == " << P2.length() << endl;
klao@226
   117
    check(P2.length() == 2);
klao@226
   118
    
klao@226
   119
    cout << "P2.from()==v1 ? " << (P2.from()==v1) << endl;
klao@226
   120
    check(P2.from() == v1);
klao@226
   121
    cout << "P2.to()==v3 ? " << (P2.to()==v3) << endl;
klao@226
   122
    check(P2.to() == v3);
klao@226
   123
  }
klao@226
   124
  {
klao@226
   125
    cout << "Reszut letrehozasa: [1. el, 6. el)..." << endl;
klao@226
   126
    LPath P2(P, P.nth<EdgeIt>(0), P.nth<EdgeIt>(5));
klao@226
   127
klao@226
   128
    cout << "P2.length() == " << P2.length() << endl;
klao@226
   129
    check(P2.length() == 5);
klao@226
   130
    
klao@226
   131
    cout << "P2.from()==s ? " << (P2.from()==s) << endl;
klao@226
   132
    check(P2.from() == s);
klao@226
   133
    cout << "P2.to()==t ? " << (P2.to()==t) << endl;
klao@226
   134
    check(P2.to() == t);
klao@226
   135
  }
klao@226
   136
klao@226
   137
  {
klao@226
   138
    cout << "Ket pont altal megadott reszut letrehozasa: [2. pont, 4. pont]..."
klao@226
   139
	 << endl;
klao@226
   140
    LPath P2(P, P.nth<NodeIt>(1), P.nth<NodeIt>(3));
klao@226
   141
klao@226
   142
    cout << "P2.length() == " << P2.length() << endl;
klao@226
   143
    check(P2.length() == 2);
klao@226
   144
    
klao@226
   145
    cout << "P2.from()==v1 ? " << (P2.from()==v1) << endl;
klao@226
   146
    check(P2.from() == v1);
klao@226
   147
    cout << "P2.to()==v3 ? " << (P2.to()==v3) << endl;
klao@226
   148
    check(P2.to() == v3);
klao@226
   149
  }
klao@226
   150
  {
klao@226
   151
    cout << "Egy pontu reszut letrehozasa: [4. pont, 4. pont]..."
klao@226
   152
	 << endl;
klao@226
   153
    LPath P2(P, P.nth<NodeIt>(3), P.nth<NodeIt>(3));
klao@226
   154
klao@226
   155
    cout << "P2.length() == " << P2.length() << endl;
klao@226
   156
    check(P2.length() == 0);
klao@226
   157
    
klao@226
   158
    cout << "P2.from()==v3 ? " << (P2.from()==v3) << endl;
klao@226
   159
    check(P2.from() == v3);
klao@226
   160
    cout << "P2.to()==v3 ? " << (P2.to()==v3) << endl;
klao@226
   161
    check(P2.to() == v3);
klao@226
   162
  }
klao@226
   163
  {
klao@226
   164
    cout << "Forditott ut letrehozasa: [6. pont, 1. pont]..."
klao@226
   165
	 << endl;
klao@226
   166
    LPath P2(P, P.nth<NodeIt>(5), P.nth<NodeIt>(0));
klao@226
   167
klao@226
   168
    cout << "P2.length() == " << P2.length() << endl;
klao@226
   169
    check(P2.length() == 5);
klao@226
   170
    
klao@226
   171
    cout << "P2.from()==t ? " << (P2.from()==t) << endl;
klao@226
   172
    check(P2.from() == t);
klao@226
   173
    cout << "P2.to()==s ? " << (P2.to()==s) << endl;
klao@226
   174
    check(P2.to() == s);
klao@226
   175
  }
klao@225
   176
klao@225
   177
klao@225
   178
  cout << (passed ? "All tests passed." : "Some of the tests failed!!!")
klao@225
   179
       << endl;
klao@225
   180
klao@225
   181
  return passed ? 0 : 1;
klao@225
   182
}