Changeset 831:b6ae3446098a in lemon-0.x for src/test
- Timestamp:
- 09/12/04 23:46:26 (20 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1129
- Location:
- src/test
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/test/path_test.cc
r823 r831 1 1 #include <string> 2 2 #include <iostream> 3 //#include <hugo/path.h>4 3 #include <hugo/skeletons/path.h> 4 #include <hugo/path.h> 5 5 #include <hugo/list_graph.h> 6 6 7 7 using namespace std; 8 8 using namespace hugo; 9 #ifdef SKELETON10 9 using namespace skeleton; 11 #endif12 10 13 bool passed = true; 11 template<class Path> void checkCompilePath(Path &P) 12 { 13 typedef typename Path::EdgeIt EdgeIt; 14 typedef typename Path::NodeIt NodeIt; 15 typedef typename Path::GraphNode GraphNode; 16 typedef typename Path::GraphEdge GraphEdge; 17 //typedef typename Path::Builder Builder; 18 //??? ha csinalok ilyet es siman Builderrel peldanyositok, akkor warningol. Talan friend miatt? De ki az? 14 19 15 void check(bool rc) { 16 passed = passed && rc; 17 if(!rc) { 18 cout << "Test failed!" << endl; 19 } 20 EdgeIt ei; 21 NodeIt ni; 22 GraphNode gn; 23 GraphEdge ge; 24 25 size_t st; 26 bool b; 27 28 //Path(const Graph &_G) {} //the constructor has been already called 29 30 st=P.length(); //size_t length() const {return 0;} 31 b=P.empty(); //bool empty() const {} 32 P.clear(); //void clear() {} 33 34 gn=P.head(); //GraphNode/*It*/ head() const {return INVALID;} 35 gn=P.tail(); //GraphNode/*It*/ tail() const {return INVALID;} 36 37 ei=P.first(ei); //It& first(It &i) const { return i=It(*this); } 38 39 ni=P.head(ei); //NodeIt head(const EdgeIt& e) const {} 40 ni=P.tail(ei); //NodeIt tail(const EdgeIt& e) const {} 41 42 43 ListGraph lg; 44 Path p(lg); 45 46 EdgeIt i; //EdgeIt() {} 47 EdgeIt j(INVALID); //EdgeIt(Invalid) {} 48 EdgeIt k(p); //EdgeIt(const Path &_p) {} 49 50 //??? operator GraphEdge () const {} 51 52 //INVALIDra megy a ++???? 53 i=++j; //EdgeIt& operator++() {} 54 b=(i==j); //bool operator==(const EdgeIt& e) const {return true;} 55 b=(i!=j); //bool operator!=(const EdgeIt& e) const {return true;} 56 57 58 NodeIt l; //NodeIt() {} 59 NodeIt m(INVALID); //NodeIt(Invalid) {} 60 NodeIt n(p); //NodeIt(const Path &_p) {} 61 62 //operator const GraphNode& () const {} 63 64 l=++m; //NodeIt& operator++() {} 65 b=(m==n); //bool operator==(const NodeIt& e) const {} 66 b=(m!=n); //bool operator!=(const NodeIt& e) const {} 67 68 typename Path::Builder builder(p); //Builder(Path &_P) : P(_P) {} 69 builder.setStartNode(gn); //void setStartNode(const GraphNode &) {} 70 builder.pushFront(ge); //void pushFront(const GraphEdge& e) {} 71 builder.pushBack(ge); //void pushBack(const GraphEdge& e) {} 72 builder.commit(); //void commit() {} 73 builder.reserveFront(st); //void reserveFront(size_t r) {} 74 builder.reserveBack(st); //void reserveBack(size_t r) {} 75 20 76 } 21 77 22 #ifdef DEBUG 23 const bool debug = true; 24 #else 25 const bool debug = false; 26 #endif 78 template void checkCompilePath< skeleton::Path<ListGraph> >(skeleton::Path<ListGraph> &); 79 template void checkCompilePath< DirPath<ListGraph> >(DirPath<ListGraph> &); 80 template void checkCompilePath< UndirPath<ListGraph> >(UndirPath<ListGraph> &); 27 81 28 29 int main() { 30 31 try { 32 33 typedef ListGraph::Node Node; 34 typedef ListGraph::Edge Edge; 35 36 ListGraph G; 37 38 Node s=G.addNode(); 39 Node v1=G.addNode(); 40 Node v2=G.addNode(); 41 Node v3=G.addNode(); 42 Node v4=G.addNode(); 43 Node t=G.addNode(); 44 45 Edge e1 = G.addEdge(s, v1); 46 Edge e2 = G.addEdge(s, v2); 47 Edge e3 = G.addEdge(v1, v2); 48 Edge e4 = G.addEdge(v2, v1); 49 Edge e5 = G.addEdge(v1, v3); 50 Edge e6 = G.addEdge(v3, v2); 51 Edge e7 = G.addEdge(v2, v4); 52 Edge e8 = G.addEdge(v4, v3); 53 Edge e9 = G.addEdge(v3, t); 54 Edge e10 = G.addEdge(v4, t); 55 56 #ifdef DEBUG 57 bool rc; 58 #endif 59 60 { 61 cout << "\n\n\nDirPath tesztelese...\n"; 62 63 64 cout << "Ures path letrehozasa" << endl; 65 #ifdef SKELETON 66 typedef Path <ListGraph> DPath; 67 #else 68 typedef DirPath<ListGraph> DPath; 69 #endif 70 DPath P(G); 71 72 cout << "P.length() == " << P.length() << endl; 73 check(P.length() == 0); 74 75 #ifdef SKELETON 76 cout << "P.tail() valid? " << (P.tail()!=INVALID) << endl; 77 check(! (P.tail()!=INVALID)); 78 #else 79 cout << "P.tail() valid? " << (P.from()!=INVALID) << endl; 80 check(! (P.to()!=INVALID)); 81 #endif 82 { 83 cout << "Builder objektum letrehozasa" << endl; 84 DPath::Builder B(P); 85 86 cout << "Hozzaadunk az elejehez ket elet..." << endl; 87 B.pushFront(e6); 88 B.pushFront(e5); 89 cout << "P.length() == " << P.length() << endl; 90 check(P.length() == 0); 91 92 cout << "Commitolunk..." << endl; 93 B.commit(); 94 95 cout << "P.length() == " << P.length() << endl; 96 check(P.length() == 2); 97 98 #ifdef SKELETON 99 cout << "P.tail() valid? " << (P.tail()!=INVALID) << endl; 100 check(P.tail()!=INVALID); 101 cout << "P.tail()==v1 ? " << (P.tail()==v1) << endl; 102 check(P.tail() == v1); 103 #else 104 cout << "P.tail() valid? " << (P.from()!=INVALID) << endl; 105 check(P.from()!=INVALID); 106 cout << "P.tail()==v1 ? " << (P.from()==v1) << endl; 107 check(P.from() == v1); 108 #endif 109 110 // Na ja, ez igy nem igazi, mindket esetet le kene tesztelni, 111 // de legalabb valami: 112 #ifdef DEBUG 113 cout << "Hozzaadunk az elejehez egy nem illeszkedo elet..." << endl; 114 rc = false; 115 try { 116 B.pushFront(e3); 117 } 118 catch(const Exception &e) { 119 cout << "E: " << e.what() << endl; 120 rc = true; 121 } 122 check(rc); 123 #endif 124 125 cout << "Hozzaadunk a vegehez ket elet..." << endl; 126 B.pushBack(e7); 127 B.pushBack(e8); 128 cout << "P.length() == " << P.length() << endl; 129 check(P.length() == 2); 130 131 cout << "Es commitolunk...\n"; 132 B.commit(); 133 } 134 cout << "P.length() == " << P.length() << endl; 135 check(P.length() == 4); 136 137 #ifdef SKELETON 138 cout << "P.head()==v3 ? " << (P.head()==v3) << endl; 139 check(P.head() == v3); 140 #else 141 cout << "P.head()==v3 ? " << (P.to()==v3) << endl; 142 check(P.to() == v3); 143 #endif 144 145 #ifndef SKELETON 146 cout << "Vegigiteralunk az eleken." << endl; 147 typedef DPath::NodeIt NodeIt; 148 typedef DPath::EdgeIt EdgeIt; 149 EdgeIt e; 150 int i=1; 151 for(P.first(e); e!=INVALID; ++e, ++i) { 152 cout << i << ". el: " <</* e << */endl; 153 } 154 #endif 155 156 // Na ja, ez igy nem igazi, mindket esetet le kene tesztelni, 157 // de legalabb valami: 158 159 #ifdef DEBUG 160 rc = false; 161 try { 162 cout << "Setting an edgeiter to a nonexistant edge." << endl; 163 //P.nth(e,134); 164 rc = !debug; 165 } 166 catch(const Exception &e) { 167 cout << "E: " << e.what() << endl; 168 rc = debug; 169 } 170 check(rc); 171 #endif 172 } 173 174 } 175 catch(const std::exception &e) { 176 cout << "Uncaught exception: " << e.what() << endl; 177 return 1; 178 } 179 catch(...) { 180 cout << "Something horrible happened: an exception which isn't " 181 << "std::exception" << endl; 182 return 2; 183 } 184 185 186 cout << (passed ? "All tests passed." : "Some of the tests failed!!!") 187 << endl; 188 189 return passed ? 0 : 1; 82 int main() 83 { 190 84 }
Note: See TracChangeset
for help on using the changeset viewer.