📄 ugraphdiagnose.h
字号:
false, -0.75); UGraph<Char> assn_graph_1(USER); assn_graph_1.assign(assn_graph_0); // the assigned graph should now have an arc from its start node to the // char1 with a weight of 0.75 and an arc from the char1 to the terminal // node with a weight of -0.75 // cstr_arc = (GraphArc<Char>*)NULL; if ((cstr_arc = assn_graph_1.getStart()->getFirst()) == (GraphArc<Char>*)NULL) { return Error::handle(name(), L"assign", Error::TEST, __FILE__, __LINE__); } if ((cstr_arc->getVertex()->getItem()->ne(*char1)) || cstr_arc->getEpsilon() || !Integral::almostEqual(cstr_arc->getWeight(), 0.75)) { return Error::handle(name(), L"assign", Error::TEST, __FILE__, __LINE__); } assn_graph_1.gotoFirst(); assn_graph_1.getCurr()->gotoFirst(); if ((cstr_arc = assn_graph_1.getCurr()->getCurr()) == (GraphArc<Char>*)NULL) { return Error::handle(name(), L"assign", Error::TEST, __FILE__, __LINE__); } if ((cstr_arc->getVertex() != assn_graph_1.getStart()) || cstr_arc->getEpsilon() || !Integral::almostEqual(cstr_arc->getWeight(), 0.75)) { return Error::handle(name(), L"assign", Error::TEST, __FILE__, __LINE__); } if ((cstr_arc = assn_graph_1.getCurr()->getNext()) == (GraphArc<Char>*)NULL) { return Error::handle(name(), L"assign", Error::TEST, __FILE__, __LINE__); } if ((cstr_arc->getVertex() != assn_graph_1.getTerm()) || cstr_arc->getEpsilon() || !Integral::almostEqual(cstr_arc->getWeight(), -0.75)) { return Error::handle(name(), L"assign", Error::TEST, __FILE__, __LINE__); } if ((cstr_arc = assn_graph_1.getTerm()->getFirst()) == (GraphArc<Char>*)NULL) { return Error::handle(name(), L"assign", Error::TEST, __FILE__, __LINE__); } if ((cstr_arc->getVertex()->getItem()->ne(*char1)) || cstr_arc->getEpsilon() || !Integral::almostEqual(cstr_arc->getWeight(), -0.75)) { return Error::handle(name(), L"assign", Error::TEST, __FILE__, __LINE__); } // clean up memory // delete char1; } // test the equality method in SYSTEM-allocated mode // // ------------------------------------------------- // START - A // A -(0.3) - A // -(0.3) - R // -(epi) - B // -(epi) - C // B -(0.2) - L // C -(3.6) - K // M -(0.6) - K // M -(1.2) - A // L -(-0.7)- R // L -(0.4) - C // S -(-0.2)- K // S -(-0.6)- S // R - TERM // ------------------------------------------------- // create the graph items // Char* A = new Char('A'); Char* B = new Char('B'); Char* C = new Char('C'); Char* K = new Char('K'); Char* L = new Char('L'); Char* M = new Char('M'); Char* S = new Char('S'); Char* R = new Char('R'); // create the graph // UGraph<Char>* graph_00 = new UGraph<Char>(); // create the verteices // GraphVertex<Char>* VA = graph_00->insertVertex(A); GraphVertex<Char>* VB = graph_00->insertVertex(B); GraphVertex<Char>* VC = graph_00->insertVertex(C); GraphVertex<Char>* VK = graph_00->insertVertex(K); GraphVertex<Char>* VL = graph_00->insertVertex(L); GraphVertex<Char>* VM = graph_00->insertVertex(M); GraphVertex<Char>* VS = graph_00->insertVertex(S); GraphVertex<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 // UGraph<Char>* graph_01 = new UGraph<Char>(*graph_00); // create the graph // UGraph<Char>* graph_02 = new UGraph<Char>(); 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__); } // delete the character objects // delete A; delete B; delete C; delete K; delete L; delete M; delete S; delete R; // clean up memory // graph_00->clear(Integral::FREE); graph_01->clear(Integral::FREE); graph_02->clear(Integral::FREE); delete graph_00; delete graph_01; delete graph_02; { // test the equality method in USER-allocated mode // // ------------------------------------------------- // START - A // A -(0.3) - A // -(0.3) - R // -(epi) - B // -(epi) - C // B -(0.2) - L // C -(3.6) - K // M -(0.6) - K // M -(1.2) - A // L -(-0.7)- R // L -(0.4) - C // S -(-0.2)- K // S -(-0.6)- S // R - TERM // ------------------------------------------------- // create the graph items // Char* A = new Char('A'); Char* B = new Char('B'); Char* C = new Char('C'); Char* K = new Char('K'); Char* L = new Char('L'); Char* M = new Char('M'); Char* S = new Char('S'); Char* R = new Char('R'); // create the graph // UGraph<Char>* graph_00 = new UGraph<Char>(USER); // create the verteices // GraphVertex<Char>* VA = graph_00->insertVertex(A); GraphVertex<Char>* VB = graph_00->insertVertex(B); GraphVertex<Char>* VC = graph_00->insertVertex(C); GraphVertex<Char>* VK = graph_00->insertVertex(K); GraphVertex<Char>* VL = graph_00->insertVertex(L); GraphVertex<Char>* VM = graph_00->insertVertex(M); GraphVertex<Char>* VS = graph_00->insertVertex(S); GraphVertex<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 // UGraph<Char>* graph_01 = new UGraph<Char>(*graph_00); // create the graph // UGraph<Char>* graph_02 = new UGraph<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(); } // ------------------------------------------------- // START -(epi)- T // T -(0.3)- W // W -(epi)- TERM // ------------------------------------------------- // test insert arc methods in SYSTEM-allocation mode // UGraph<Char>* graph_03 = new UGraph<Char>(); // 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,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -