📄 bigraphdiagnose.h
字号:
// create the verteices // BiGraphVertex<Char>* VA = graph_00->insertVertex(A); BiGraphVertex<Char>* VB = graph_00->insertVertex(B); BiGraphVertex<Char>* VC = graph_00->insertVertex(C); BiGraphVertex<Char>* VK = graph_00->insertVertex(K); BiGraphVertex<Char>* VL = graph_00->insertVertex(L); BiGraphVertex<Char>* VM = graph_00->insertVertex(M); BiGraphVertex<Char>* VS = graph_00->insertVertex(S); BiGraphVertex<Char>* VR = graph_00->insertVertex(R); // connect the graph // graph_00->insertArc(graph_00->getStart(), VA, true); graph_00->insertArc(VA, VA, false, 0.3); graph_00->insertArc(VA, VR, false, 0.3); graph_00->insertArc(VA, VB, true); graph_00->insertArc(VA, VC, true); graph_00->insertArc(VB, VL, false, 0.2); graph_00->insertArc(VC, VK, false, 3.6); graph_00->insertArc(VM, VK, false, 0.6); graph_00->insertArc(VM, VA, false, 1.2); graph_00->insertArc(VL, VR, false, -0.7); graph_00->insertArc(VL, VC, false, 0.4); graph_00->insertArc(VS, VK, false, -0.2); graph_00->insertArc(VS, VS, false, -0.6); graph_00->insertArc(VR, graph_00->getTerm(), true); // create the graph // BiGraph<Char>* graph_01 = new BiGraph<Char>(*graph_00); // create the graph // BiGraph<Char>* graph_02 = new BiGraph<Char>(USER); VA = graph_02->insertVertex(A); VB = graph_02->insertVertex(B); VC = graph_02->insertVertex(C); VK = graph_02->insertVertex(K); VL = graph_02->insertVertex(L); VM = graph_02->insertVertex(M); VS = graph_02->insertVertex(S); VR = graph_02->insertVertex(R); // connect the graph // graph_02->insertArc(graph_02->getStart(), VA, true); graph_02->insertArc(VA, VA, false, 0.3); graph_02->insertArc(VA, VR, false, 0.3); graph_02->insertArc(VA, VB, true); graph_02->insertArc(VA, VC, true); graph_02->insertArc(VB, VL, false, 0.2); graph_02->insertArc(VC, VK, false, 3.6); graph_02->insertArc(VM, VK, false, 0.6); graph_02->insertArc(VM, VA, false, -1.2); graph_02->insertArc(VL, VR, false, -0.7); graph_02->insertArc(VL, VC, false, 0.4); graph_02->insertArc(VS, VK, false, -0.2); graph_02->insertArc(VS, VS, false, -0.6); graph_02->insertArc(VR, graph_02->getTerm(), true); // graph_00 and graph_01 should be equal // if (!graph_00->eq(*graph_01)) { return Error::handle(name(), L"eq", Error::TEST, __FILE__, __LINE__); } // graph_00 and graph_01 should not be equal // if (graph_00->eq(*graph_02)) { return Error::handle(name(), L"eq", Error::TEST, __FILE__, __LINE__); } // clean up memory // graph_00->clear(Integral::FREE); graph_01->clear(); graph_02->clear(); delete graph_00; delete graph_01; delete graph_02; } // reset indentation // if (level_a > Integral::NONE) { Console::decreaseIndention(); } // -------------------------------------------------------------------- // // 2. class-specific public methods: // graph manipulation methods // // -------------------------------------------------------------------- // set indentation // if (level_a > Integral::NONE) { Console::put(L"testing class-specific public methods: graph manipulation methods...\n"); Console::increaseIndention(); } // test insert vetrex methods in SYSTEM-allocation mode // BiGraph<Char>* graph_03 = new BiGraph<Char>(); // create some vertices // A = new Char('A'); B = new Char('B'); C = new Char('C'); K = new Char('K'); VA = graph_03->insertVertex(A); VB = graph_03->insertVertex(B); VC = graph_03->insertVertex(C); VK = graph_03->insertVertex(K); L = new Char('L'); VL = new BiGraphVertex<TObject>(); // the graph should contain VA, VB, VC and VK // if ((!graph_03->contains(VA)) || (!graph_03->contains(VB)) || (!graph_03->contains(VC)) || (!graph_03->contains(VK))) { return Error::handle(name(), L"insertVertex", Error::TEST, __FILE__, __LINE__); } // the graph should not contain VL // if (graph_03->contains(VL)) { return Error::handle(name(), L"insertVertex", Error::TEST, __FILE__, __LINE__); } // test the find and contains methods in SYSTEM-allocation mode // graph_03->setMark(); if (!graph_03->contains(VC)) { return Error::handle(name(), L"contains", Error::TEST, __FILE__, __LINE__); } if (graph_03->contains(VL)) { return Error::handle(name(), L"contains", Error::TEST, __FILE__, __LINE__); } if (!graph_03->contains(K)) { return Error::handle(name(), L"contains", Error::TEST, __FILE__, __LINE__); } if (graph_03->contains(L)) { return Error::handle(name(), L"contains", Error::TEST, __FILE__, __LINE__); } if (!graph_03->find(VA)) { return Error::handle(name(), L"find", Error::TEST, __FILE__, __LINE__); } if (graph_03->getCurr() != VA) { return Error::handle(name(), L"find", Error::TEST, __FILE__, __LINE__); } if (!graph_03->find(K)) { return Error::handle(name(), L"find", Error::TEST, __FILE__, __LINE__); } if (graph_03->getCurr() != VK) { return Error::handle(name(), L"find", Error::TEST, __FILE__, __LINE__); } graph_03->gotoMark(); // test remove vetrex methods in SYSTEM-allocation mode // graph_03->find(VC); graph_03->removeVertex(); if (graph_03->contains(VC)) { return Error::handle(name(), L"remove", Error::TEST, __FILE__, __LINE__); } TObject* item = new TObject(); graph_03->find(VK); graph_03->removeVertex(item); if ((graph_03->contains(VK)) || (!item->eq(*K))) { return Error::handle(name(), L"remove", Error::TEST, __FILE__, __LINE__); } // test insert arc methods in SYSTEM-allocation mode // graph_03->insertArc(graph_03->getStart(), VB, true); graph_03->insertArc(VB, graph_03->getTerm(), false, 0.3); // the start vertex should have an epsilon transition to VB // BiGraphArc<TObject>* my_arc = graph_03->getStart()->getFirstChild(); if ((my_arc->getVertex()) != VB && (!my_arc->getEpsilon())) { return Error::handle(name(), L"insertArc", Error::TEST, __FILE__, __LINE__); } // the VB should have an epsilon transition to the start // ver_test = my_arc->getVertex(); my_arc = ver_test->getFirstParent(); if ((my_arc->getVertex()) != graph_03->getStart() && (!my_arc->getEpsilon())) { return Error::handle(name(), L"insertArc", Error::TEST, __FILE__, __LINE__); } boolean more_nodes = graph_03->gotoFirst(); while (more_nodes) { // VB should a weighted arc to the term vertex // BiGraphVertex<TObject>* my_vertex = (BiGraphVertex<TObject>*)graph_03->getCurr(); BiGraphArc<TObject>* my_arc = my_vertex->getFirstChild(); if (my_vertex == VB) { if ((my_arc->getVertex() != graph_03->getTerm()) && (!Integral::almostEqual((double)my_arc->getWeight(), 0.3))) { return Error::handle(name(), L"insertArc", Error::TEST, __FILE__, __LINE__); } } // the start should a weighted arc to VB // my_vertex = graph_03->getTerm(); my_arc = my_vertex->getFirstParent(); if (my_vertex == graph_03->getTerm()) { if ((my_arc->getVertex() != VB) && (!Integral::almostEqual((double)my_arc->getWeight(), 0.3))) { return Error::handle(name(), L"insertArc", Error::TEST, __FILE__, __LINE__); } } more_nodes = graph_03->gotoNext(); } // test remove arc methods in SYSTEM-allocation mode // graph_03->removeArc(VB, graph_03->getTerm()); more_nodes = graph_03->gotoFirst(); while (more_nodes) { // VB should not have a weighted arc to the term vertex // BiGraphVertex<TObject>* my_vertex = (BiGraphVertex<TObject>*)graph_03->getCurr(); BiGraphArc<TObject>* my_arc = my_vertex->getFirstChild(); if (my_vertex == VB) { if (my_arc != (BiGraphArc<TObject>*)NULL) { return Error::handle(name(), L"removeArc", Error::TEST, __FILE__, __LINE__); } } // term vertex should not have a weighted arc to VB // my_vertex = graph_03->getTerm(); my_arc = my_vertex->getFirstParent(); if (my_vertex == graph_03->getTerm()) { if (my_arc != (BiGraphArc<TObject>*)NULL) { return Error::handle(name(), L"removeArc", Error::TEST, __FILE__, __LINE__); } } more_nodes = graph_03->gotoNext(); } // clean up memory // delete item; delete L; delete VL; graph_03->clear(Integral::FREE); delete A; delete B; delete C; delete K; delete graph_03; { // test insert vetrex methods in USER-allocation mode // BiGraph<Char>* graph_03 = new BiGraph<Char>(USER); // create some vertices // A = new Char('A'); B = new Char('B'); C = new Char('C'); K = new Char('K'); VA = graph_03->insertVertex(A); VB = graph_03->insertVertex(B); VC = graph_03->insertVertex(C); VK = graph_03->insertVertex(K); L = new Char('L'); VL = new BiGraphVertex<TObject>(); // the graph should contain VA, VB, VC and VK // if ((!graph_03->contains(VA)) || (!graph_03->contains(VB)) || (!graph_03->contains(VC)) || (!graph_03->contains(VK))) { return Error::handle(name(), L"insertVertex", Error::TEST, __FILE__, __LINE__); } // the graph should not contain VL // if (graph_03->contains(VL)) { return Error::handle(name(), L"insertVertex", Error::TEST, __FILE__, __LINE__); } // test the find and contains methods in USER-allocation mode // graph_03->setMark(); if (!graph_03->contains(VC)) { return Error::handle(name(), L"contains", Error::TEST, __FILE__, __LINE__); } if (graph_03->contains(VL)) { return Error::handle(name(), L"contains", Error::TEST, __FILE__, __LINE__); } if (!graph_03->contains(K)) { return Error::handle(name(), L"contains", Error::TEST, __FILE__, __LINE__); } if (graph_03->contains(L)) { return Error::handle(name(), L"contains", Error::TEST, __FILE__, __LINE__); } if (!graph_03->find(VA)) { return Error::handle(name(), L"find", Error::TEST, __FILE__, __LINE__); } if (graph_03->getCurr() != VA) { return Error::handle(name(), L"find", Error::TEST, __FILE__, __LINE__); } if (!graph_03->find(K)) { return Error::handle(name(), L"find", Error::TEST, __FILE__, __LINE__); } if (graph_03->getCurr() != VK) { return Error::handle(name(), L"find", Error::TEST, __FILE__, __LINE__); } graph_03->gotoMark(); // test remove vetrex methods in USER-allocation mode // TObject* item = (TObject*)NULL; graph_03->find(VC); graph_03->removeVertex(item); if ((graph_03->contains(VC)) || (!item->eq(*C))) { return Error::handle(name(), L"remove", Error::TEST, __FILE__, __LINE__); } item = (TObject*)NULL; delete C; graph_03->find(VK); graph_03->removeVertex(item); if ((graph_03->contains(VK)) || (!item->eq(*K))) { return Error::handle(name(), L"remove", Error::TEST, __FILE__, __LINE__); } delete K; // test insert arc methods in USER-allocation mode // graph_03->insertArc(graph_03->getStart(), VB, true); graph_03->insertArc(VB, graph_03->getTerm(), false, 0.3); // the start vertex should have an epsilon transition to VB // BiGraphArc<TObject>* my_arc = graph_03->getStart()->getFirstChild(); if ((my_arc->getVertex() != VB) && (!my_arc->getEpsilon())) { return Error::handle(name(), L"insertArc", Error::TEST, __FILE__, __LINE__); } // the VB should have an epsilon transition to the start // ver_test = my_arc->getVertex(); my_arc = ver_test->getFirstParent(); if ((my_arc->getVertex()) != graph_03->getStart() && (!my_arc->getEpsilon())) { return Error::handle(name(), L"insertArc", Error::TEST, __FILE__, __LINE__); } boolean more_nodes = graph_03->gotoFirst(); while (more_nodes) { // VB should not have weighted arc to the term vertex // BiGraphVertex<TObject>* my_vertex = (BiGraphVertex<TObject>*)graph_03->getCurr(); BiGraphArc<TObject>* my_arc = my_vertex->getFirstChild(); if (my_vertex == VB) { if ((my_arc->getVertex() != graph_03->getTerm()) && (!Integral::almostEqual((double)my_arc->getWeight(), 0.3))) { return Error::handle(name(), L"insertArc", Error::TEST, __FILE__, __LINE__); } } // the start should a weighted arc to VB // my_vertex = graph_03->getTerm(); my_arc = my_vertex->getFirstParent(); if (my_vertex == graph_03->getTerm()) { if ((my_arc->getVertex() != VB) && (!Integral::almostEqual((double)my_arc->getWeight(), 0.3))) { return Error::handle(name(), L"insertArc", Error::TEST, __FILE__, __LINE__); } } more_nodes = graph_03->gotoNext();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -