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