src/work/klao/path_test.cc
author klao
Sun, 21 Mar 2004 16:16:08 +0000
changeset 225 b72b36a25170
child 226 616bc397c83a
permissions -rw-r--r--
Ut struktura. Elso valtozat.
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@225
    73
  cout << "Meg 3 el hozzaadasa, nem mind sorrendben..." << 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@225
   112
klao@225
   113
klao@225
   114
  cout << (passed ? "All tests passed." : "Some of the tests failed!!!")
klao@225
   115
       << endl;
klao@225
   116
klao@225
   117
  return passed ? 0 : 1;
klao@225
   118
}