📄 ugraphdiagnose.h
字号:
__FILE__, __LINE__); } // retrieve the second arc // my_arc = my_vertex->getNext(); if ((my_arc->getVertex() != graph_03->getTerm()) && (!my_arc->getEpsilon())) { return Error::handle(name(), L"insertArc", Error::TEST, __FILE__, __LINE__); } } } more_nodes = graph_03->gotoNext(); } // clean up // delete T; delete W; graph_03->clear(Integral::FREE); delete graph_03; { // ------------------------------------------------- // START -(epi)- T // T -(0.3)- W // W -(epi)- TERM // ------------------------------------------------- // test insert arc methods in USER-allocation mode // UGraph<Char>* graph_03 = new UGraph<Char>(USER); // create some vertices // Char* T = new Char('T'); Char* W = new Char('W'); GraphVertex<Char>* VT = graph_03->insertVertex(T); GraphVertex<Char>* VW = graph_03->insertVertex(W); // insert an arc for the start vertex to 'T' // graph_03->insertArc(graph_03->getStart(), VT, true); // insert an arc from 'T' to 'W' with a weight of -0.3 // graph_03->insertArc(VT, VW, false, -0.3); // insert an arc from 'W' to the term vertex // graph_03->insertArc(VW, graph_03->getTerm(), true); // the start vertex should have an epsilon transition to VT // GraphArc<TObject>* my_arc = graph_03->getStart()->getFirst(); if ((my_arc->getVertex()) != VT && (!my_arc->getEpsilon())) { return Error::handle(name(), L"insertArc", Error::TEST, __FILE__, __LINE__); } // the vertex VT should have two arcs one to the start vertex and // the other to the terminal vertex // boolean more_nodes = graph_03->gotoFirst(); while (more_nodes) { // VT should have a weighted arc to the term vertex // GraphVertex<TObject>* my_vertex = graph_03->getCurr(); my_vertex->gotoFirst(); if (my_vertex == VT) { // there must be two out-going arcs from the vertex // if (my_vertex->length() != (long)2) { return Error::handle(name(), L"insertArc", Error::TEST, __FILE__, __LINE__); } // retrieve the first arc // GraphArc<TObject>* my_arc = my_vertex->getCurr(); // if the arc is to the start vertex // if (my_arc->getVertex() == graph_03->getStart()) { if (!my_arc->getEpsilon()) { return Error::handle(name(), L"insertArc", Error::TEST, __FILE__, __LINE__); } // retrieve the second arc // my_arc = my_vertex->getNext(); if ((my_arc->getVertex() != VW) && (!Integral::almostEqual(my_arc->getWeight(), -0.3))) { return Error::handle(name(), L"insertArc", Error::TEST, __FILE__, __LINE__); } } // the arc must be to the VW vertex // else { if ((my_arc->getVertex() != VW) && (!Integral::almostEqual(my_arc->getWeight(), -0.3))) { return Error::handle(name(), L"insertArc", Error::TEST, __FILE__, __LINE__); } // retrieve the second arc // my_arc = my_vertex->getNext(); if ((my_arc->getVertex() != graph_03->getStart()) && (!my_arc->getEpsilon())) { return Error::handle(name(), L"insertArc", Error::TEST, __FILE__, __LINE__); } } } if (my_vertex == VW) { // there must be two out-going arcs from the vertex // if (my_vertex->length() != (long)2) { return Error::handle(name(), L"insertArc", Error::TEST, __FILE__, __LINE__); } // retrieve the first arc // GraphArc<TObject>* my_arc = my_vertex->getCurr(); // if the arc is to the term vertex // if (my_arc->getVertex() == graph_03->getTerm()) { if (!my_arc->getEpsilon()) { return Error::handle(name(), L"insertArc", Error::TEST, __FILE__, __LINE__); } // retrieve the second arc // my_arc = my_vertex->getNext(); if ((my_arc->getVertex() != VT) && (!Integral::almostEqual(my_arc->getWeight(), -0.3))) { return Error::handle(name(), L"insertArc", Error::TEST, __FILE__, __LINE__); } } // the arc must be to the VT vertex // else { if ((my_arc->getVertex() != VT) && (!Integral::almostEqual(my_arc->getWeight(), -0.3))) { return Error::handle(name(), L"insertArc", Error::TEST, __FILE__, __LINE__); } // retrieve the second arc // my_arc = my_vertex->getNext(); if ((my_arc->getVertex() != graph_03->getTerm()) && (!my_arc->getEpsilon())) { return Error::handle(name(), L"insertArc", Error::TEST, __FILE__, __LINE__); } } } more_nodes = graph_03->gotoNext(); } // clean up // graph_03->clear(Integral::FREE); delete graph_03; } // test the remove arc methods in SYSTEM-allocation mode // // ------------------------------------------------- // START - X // X -(0.5) - Y // X - TERM // ------------------------------------------------- UGraph<Char>* graph_04 = new UGraph<Char>(); // create some vertices // Char* X = new Char('X'); Char* Y = new Char('Y'); GraphVertex<Char>* VX = graph_04->insertVertex(X); GraphVertex<Char>* VY = graph_04->insertVertex(Y); // insert an arc from the start to 'X' and from 'X' to term // graph_04->insertArc(graph_04->getStart(), VX, true); graph_04->insertArc(VX, graph_04->getTerm(), true); // insert an arc from 'X' to 'Y' // graph_04->insertArc(VX, VY, false, 0.5); // 'X' should have three out going arcs to start, term and 'Y' // graph_04->gotoFirst(); // the first vertex should be 'X' // if (graph_04->getCurr() != VX) { return Error::handle(name(), L"insertArc", Error::TEST, __FILE__, __LINE__); } // the first arc should goto the start vertex with an epsilon transition // GraphArc<TObject>* test_arc; graph_04->getCurr()->gotoFirst(); test_arc = graph_04->getCurr()->getCurr(); if ((test_arc->getVertex() != graph_04->getStart()) && (!test_arc->getEpsilon())) { return Error::handle(name(), L"insertArc", Error::TEST, __FILE__, __LINE__); } // the second arc should goto the term vertex with an epsilon transition // graph_04->getCurr()->gotoNext(); test_arc = graph_04->getCurr()->getCurr(); if ((test_arc->getVertex() != graph_04->getTerm()) && (!test_arc->getEpsilon())) { return Error::handle(name(), L"insertArc", Error::TEST, __FILE__, __LINE__); } // the third arc should goto 'Y' with a weight of 0.5 // graph_04->getCurr()->gotoNext(); test_arc = graph_04->getCurr()->getCurr(); if ((test_arc->getVertex() != VY) && (!Integral::almostEqual(test_arc->getWeight(), 0.5))) { return Error::handle(name(), L"insertArc", Error::TEST, __FILE__, __LINE__); } // vertex 'Y' should have an arc to 'X' with a weight of 0.5 // graph_04->gotoNext(); graph_04->getCurr()->gotoFirst(); test_arc = graph_04->getCurr()->getCurr(); if ((test_arc->getVertex() != VX) && (!Integral::almostEqual(test_arc->getWeight(), 0.5))) { return Error::handle(name(), L"insertArc", Error::TEST, __FILE__, __LINE__); } // remove the arc from 'X' to 'Y' // graph_04->removeArc(VX, VY); // vertex 'X' should have two arcs to the start and term vertices // graph_04->gotoFirst(); if (graph_04->getCurr()->length() != 2) { return Error::handle(name(), L"removeArc", Error::TEST, __FILE__, __LINE__); } // vertex 'Y' should have no arcs // graph_04->gotoNext(); if (graph_04->getCurr()->length() != 0) { return Error::handle(name(), L"removeArc", Error::TEST, __FILE__, __LINE__); } // 'X' should only have arcs to the star and term vertices // graph_04->gotoFirst(); graph_04->getCurr()->gotoFirst(); test_arc = graph_04->getCurr()->getCurr(); if ((test_arc->getVertex() != graph_04->getStart()) && (!test_arc->getEpsilon())) { return Error::handle(name(), L"removeArc", Error::TEST, __FILE__, __LINE__); } graph_04->getCurr()->gotoNext(); test_arc = graph_04->getCurr()->getCurr(); if ((test_arc->getVertex() != graph_04->getTerm()) && (!test_arc->getEpsilon())) { return Error::handle(name(), L"removeArc", Error::TEST, __FILE__, __LINE__); } // clean up // delete X; delete Y; graph_04->clear(Integral::FREE); delete graph_04; { // test the remove arc methods in USER-allocation mode // // ------------------------------------------------- // START - X // X -(0.5) - Y // X - TERM // ------------------------------------------------- UGraph<Char>* graph_04 = new UGraph<Char>(USER); // create some vertices // Char* X = new Char('X'); Char* Y = new Char('Y'); GraphVertex<Char>* VX = graph_04->insertVertex(X); GraphVertex<Char>* VY = graph_04->insertVertex(Y); // insert an arc from the start to 'X' and from 'X' to term // graph_04->insertArc(graph_04->getStart(), VX, true); graph_04->insertArc(VX, graph_04->getTerm(), true); // insert an arc from 'X' to 'Y' // graph_04->insertArc(VX, VY, false, 0.5); // 'X' should have three out going arcs to start, term and 'Y' // graph_04->gotoFirst(); // the first vertex should be 'X' // if (graph_04->getCurr() != VX) { return Error::handle(name(), L"insertArc", Error::TEST, __FILE__, __LINE__); } // the first arc should goto the start vertex with an epsilon transition // GraphArc<TObject>* test_arc; graph_04->getCurr()->gotoFirst(); test_arc = graph_04->getCurr()->getCurr(); if ((test_arc->getVertex() != graph_04->getStart()) && (!test_arc->getEpsilon())) { return Error::handle(name(), L"insertArc", Error::TEST, __FILE__, __LINE__); } // the second arc should goto the term vertex with an epsilon transition // graph_04->getCurr()->gotoNext(); test_arc = graph_04->getCurr()->getCurr(); if ((test_arc->getVertex() != graph_04->getTerm()) && (!test_arc->getEpsilon())) { return Error::handle(name(), L"insertArc", Error::TEST, __FILE__, __LINE__); } // the third arc should goto 'Y' with a weight of 0.5 // graph_04->getCurr()->gotoNext(); test_arc = graph_04->getCurr()->getCurr(); if ((test_arc->getVertex() != VY) && (!Integral::almostEqual(test_arc->getWeight(), 0.5))) { return Error::handle(name(), L"insertArc", Error::TEST, __FILE__, __LINE__); } // vertex 'Y' should have an arc to 'X' with a weight of 0.5 // graph_04->gotoNext(); graph_04->getCurr()->gotoFirst(); test_arc = graph_04->getCurr()->getCurr(); if ((test_arc->getVertex() != VX) && (!Integral::almostEqual(test_arc->getWeight(), 0.5))) { return Error::handle(name(), L"insertArc", Error::TEST, __FILE__, __LINE__); } // remove the arc from 'X' to 'Y' // graph_04->removeArc(VX, VY); // vertex 'X' should have two arcs to the start and term vertices // graph_04->gotoFirst(); if (graph_04->getCurr()->length() != 2) { return Error::handle(name(), L"removeArc", Error::TEST, __FILE__, __LINE__); } // vertex 'Y' should have no arcs // graph_04->gotoNext(); if (graph_04->getCurr()->length() != 0) { return Error::handle(name(), L"removeArc", Error::TEST, __FILE__, __LINE__); } // 'X' should only have arcs to the star and term vertices // graph_04->gotoFirst(); graph_04->getCurr()->gotoFirst(); test_arc = graph_04->getCurr()->getCurr(); if ((test_arc->getVertex() != graph_04->getStart()) && (!test_arc->getEpsilon())) { return Error::handle(name(), L"removeArc", Error::TEST, __FILE__, __LINE__); } graph_04->getCurr()->gotoNext(); test_arc = graph_04->getCurr()->getCurr(); if ((test_arc->getVertex() != graph_04->getTerm()) && (!test_arc->getEpsilon())) { return Error::handle(name(), L"removeArc", Error::TEST, __FILE__, __LINE__); } // clean up // graph_04->clear(Integral::FREE); delete graph_04; } // reset indentation // if (level_a > Integral::NONE) { Console::decreaseIndention(); } //--------------------------------------------------------------------- // // 3. print completion message // //--------------------------------------------------------------------- // reset indentation // if (level_a > Integral::NONE) { Console::decreaseIndention(); } if (level_a > Integral::NONE) { SysString output(L"diagnostics passed for class "); output.concat(name()); output.concat(L"\n"); Console::put(output); } // exit gracefully // return true; }// end of include file//#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -