src/work/klao/path_test.cc
author deba
Wed, 08 Sep 2004 12:06:45 +0000 (2004-09-08)
changeset 822 88226d9fe821
parent 369 dc9c19f4ca9a
permissions -rw-r--r--
The MapFactories have been removed from the code because
if we use macros then they increases only the complexity.

The pair iterators of the maps are separeted from the maps.

Some macros and comments has been changed.
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@493
    19
#ifdef DEBUG
klao@493
    20
const bool debug = true;
klao@493
    21
#else
klao@493
    22
const bool debug = false;
klao@493
    23
#endif
klao@493
    24
klao@493
    25
klao@225
    26
int main() {
klao@225
    27
klao@493
    28
  try {
klao@225
    29
klao@493
    30
    typedef ListGraph::Node Node;
klao@493
    31
    typedef ListGraph::Edge Edge;
klao@225
    32
klao@493
    33
    ListGraph G;
klao@493
    34
klao@493
    35
    Node s=G.addNode();
klao@493
    36
    Node v1=G.addNode();
klao@493
    37
    Node v2=G.addNode();
klao@493
    38
    Node v3=G.addNode();
klao@493
    39
    Node v4=G.addNode();
klao@493
    40
    Node t=G.addNode();
klao@225
    41
  
klao@493
    42
    Edge e1 = G.addEdge(s, v1);
klao@493
    43
    Edge e2 = G.addEdge(s, v2);
klao@493
    44
    Edge e3 = G.addEdge(v1, v2);
klao@493
    45
    Edge e4 = G.addEdge(v2, v1);
klao@493
    46
    Edge e5 = G.addEdge(v1, v3);
klao@493
    47
    Edge e6 = G.addEdge(v3, v2);
klao@493
    48
    Edge e7 = G.addEdge(v2, v4);
klao@493
    49
    Edge e8 = G.addEdge(v4, v3);
klao@493
    50
    Edge e9 = G.addEdge(v3, t);
klao@493
    51
    Edge e10 = G.addEdge(v4, t);
klao@225
    52
klao@493
    53
    bool rc;
klao@225
    54
klao@493
    55
    {
klao@493
    56
      cout << "\n\n\nDirPath tesztelese...\n";
klao@225
    57
klao@225
    58
klao@493
    59
      cout << "Ures path letrehozasa" << endl;
klao@493
    60
      typedef DirPath<ListGraph> DPath;
klao@493
    61
      DPath P(G);
klao@225
    62
klao@493
    63
      cout << "P.length() == " << P.length() << endl;
klao@493
    64
      check(P.length() == 0);
klao@225
    65
klao@493
    66
      cout << "P.from() valid? " << G.valid(P.from()) << endl;
klao@493
    67
      check(! G.valid(P.from()));
klao@369
    68
klao@493
    69
      {
klao@493
    70
	cout << "Builder objektum letrehozasa" << endl;
klao@493
    71
	DPath::Builder B(P);
klao@225
    72
klao@493
    73
	cout << "Hozzaadunk az elejehez ket elet..." << endl;
klao@493
    74
	B.pushFront(e6);
klao@493
    75
	B.pushFront(e5);
klao@493
    76
	cout << "P.length() == " << P.length() << endl;
klao@493
    77
	check(P.length() == 0);
klao@493
    78
      
klao@493
    79
	cout << "Commitolunk..." << endl;
klao@493
    80
	B.commit();
klao@225
    81
klao@493
    82
	cout << "P.length() == " << P.length() << endl;
klao@493
    83
	check(P.length() == 2);
klao@493
    84
	cout << "P.from() valid? " << G.valid(P.from()) << endl;
klao@493
    85
	check(G.valid(P.from()));
klao@493
    86
	cout << "P.from()==v1 ? " << (P.from()==v1) << endl;
klao@493
    87
	check(P.from() == v1);
klao@225
    88
klao@493
    89
	// Na ja, ez igy nem igazi, mindket esetet le kene tesztelni,
klao@493
    90
	// de legalabb valami:
klao@493
    91
#ifdef DEBUG
klao@493
    92
	cout << "Hozzaadunk az elejehez egy nem illeszkedo elet..." << endl;
klao@493
    93
	rc = false;
klao@493
    94
	try {
klao@493
    95
	  B.pushFront(e3);
klao@493
    96
	}
klao@493
    97
	catch(const Exception &e) {
klao@493
    98
	  cout << "E: " << e.what() << endl;
klao@493
    99
	  rc = true;
klao@493
   100
	}
klao@493
   101
	check(rc);
klao@493
   102
#endif
klao@225
   103
klao@493
   104
	cout << "Hozzaadunk a vegehez ket elet..." << endl;
klao@493
   105
	B.pushBack(e7);
klao@493
   106
	B.pushBack(e8);
klao@493
   107
	cout << "P.length() == " << P.length() << endl;
klao@493
   108
	check(P.length() == 2);
klao@493
   109
      
klao@493
   110
	cout << "Es commitolunk...\n";
klao@493
   111
	B.commit();
klao@493
   112
      }
klao@493
   113
      cout << "P.length() == " << P.length() << endl;
klao@493
   114
      check(P.length() == 4);
klao@493
   115
      cout << "P.to()==v3 ? " << (P.to()==v3) << endl;
klao@493
   116
      check(P.to() == v3);
klao@225
   117
klao@493
   118
      cout << "Vegigiteralunk az eleken." << endl;
klao@493
   119
      typedef DPath::NodeIt NodeIt;
klao@493
   120
      typedef DPath::EdgeIt EdgeIt;
klao@493
   121
      EdgeIt e;
klao@493
   122
      int i=1;
klao@493
   123
      for(P.first(e); P.valid(e); P.next(e), ++i) {
klao@493
   124
	cout << i << ". el: " << e << endl;
klao@493
   125
      }
klao@225
   126
klao@225
   127
klao@493
   128
      // Na ja, ez igy nem igazi, mindket esetet le kene tesztelni,
klao@493
   129
      // de legalabb valami:
klao@493
   130
      rc = false;
klao@493
   131
      try {
klao@493
   132
	cout << "Setting an edgeiter to a nonexistant edge." << endl;
klao@493
   133
	P.nth(e,134);
klao@493
   134
	rc = !debug;
klao@493
   135
      }
klao@493
   136
      catch(const Exception &e) {
klao@493
   137
	cout << "E: " << e.what() << endl;
klao@493
   138
	rc = debug;
klao@493
   139
      }
klao@493
   140
      check(rc);
klao@369
   141
    }
klao@369
   142
klao@369
   143
klao@225
   144
  }
klao@493
   145
  catch(const std::exception &e) {
klao@493
   146
    cout << "Uncaught exception: " << e.what() << endl;
klao@493
   147
    return 1;
klao@493
   148
  }
klao@493
   149
  catch(...) {
klao@493
   150
    cout << "Something horrible happened: an exception which isn't "
klao@493
   151
	 << "std::exception" << endl;
klao@493
   152
    return 2;
klao@493
   153
  }
klao@225
   154
klao@225
   155
klao@225
   156
  cout << (passed ? "All tests passed." : "Some of the tests failed!!!")
klao@225
   157
       << endl;
klao@225
   158
klao@225
   159
  return passed ? 0 : 1;
klao@225
   160
}