📄 graphvertexdiagnose.h
字号:
// make sure the setParentGraph and getParentGraph methods work // // assign one of the two graphs to each node // for (long i = 0; i < 64; i++) { if (!vertices[i]->setParentGraph(&graph1)) { return Error::handle(name(), L"setParentGraph", Error::TEST, __FILE__, __LINE__); } } for (long i = 64; i < 128; i++) { if (!vertices[i]->setParentGraph(&graph2)) { return Error::handle(name(), L"setParentGraph", Error::TEST, __FILE__, __LINE__); } } // make sure that the proper graph was assigned // for (long i = 0; i < 64; i++) { if ((vertices[i]->getParentGraph() != &graph1) || (vertices[128 - i - 1]->getParentGraph() != &graph2) || (vertices[i]->getParentGraph() == vertices[128 - i - 1]->getParentGraph())) { return Error::handle(name(), L"getParentGraph", Error::TEST, __FILE__, __LINE__); } } // start building a binary tree graph where the first (left) child of each // vertex is the (2*i + 1) element of the character array and the // second (right) child is the (2*i + 2) element of the character array // // create the first vertex // vertices[0]->setItem(chars[0]); // set the graph characteristics // graph1.setWeighted(); // reset indentation // if (level_a > Integral::NONE) { Console::decreaseIndention(); } // -------------------------------------------------------------------- // // 3. class-specific public methods: // vertex manipuation methods // // -------------------------------------------------------------------- // set indentation // if (level_a > Integral::NONE) { Console::put(L"testing class-specific public methods: vertex manipuation methods...\n"); Console::increaseIndention(); } // attach this as the first node in the graph // graph1.getStart()->insertArc(vertices[0], 0.0, false); // now loop over the remaining vertices - the tree will be built when we // get to 63. the 63rd vertex will only have one child (the root node // takes one vertex) // for (long i = 0; i < 63; i++) { vertices[i]->insertArc(vertices[2 * i + 1], (float)i, false); vertices[i]->insertArc(vertices[2 * i + 2], (float)i, false); } vertices[63]->insertArc(vertices[127], (float)127, false); // reverse engineer the binary tree to make sure it is correct // graph1.getStart()->gotoFirst(); // get the first element and make sure it is the proper root vertex // if (!(graph1.getStart()->isAdjacent(vertices[0])) || (graph1.getStart()->getCurr()->getVertex() != vertices[0])) { return Error::handle(name(), L"insertArc", Error::TEST, __FILE__, __LINE__); } // the leaf vertices should be empty // for (long i = 127; i >= 64; --i) { if (!vertices[i]->isEmpty()) { return Error::handle(name(), L"insertArc", Error::TEST, __FILE__, __LINE__); } } // handle the 63rd item that has only one child vertex // if (vertices[63]->getCurr()->getVertex() != vertices[2 * 63 + 1]) { return Error::handle(name(), L"insertArc", Error::TEST, __FILE__, __LINE__); } // remove the first arc // if (!vertices[63]->removeArc()) { return Error::handle(name(), L"removeArc", Error::TEST, __FILE__, __LINE__); } // the remaining vertices should have the appropriate child vertices in the // appropriate order and with the appropriate weight // for (long i = 62; i >= 0; --i) { // go to the front of the list // vertices[i]->gotoFirst(); // the first vertex should point to the (2*i + 1) element // if (vertices[i]->getCurr()->getVertex() != vertices[2 * i + 1]) { return Error::handle(name(), L"insertArc", Error::TEST, __FILE__, __LINE__); } // remove the first arc // if (!vertices[i]->removeArc()) { return Error::handle(name(), L"removeArc", Error::TEST, __FILE__, __LINE__); } // the second vertex should point to the (2*i + 2) element // if (vertices[i]->getCurr()->getVertex() != vertices[2 * i + 2]) { return Error::handle(name(), L"insertArc", Error::TEST, __FILE__, __LINE__); } // remove the second arc // if (!vertices[i]->removeArc()) { return Error::handle(name(), L"removeArc", Error::TEST, __FILE__, __LINE__); } // make sure the list is now empty // if (!vertices[i]->isEmpty()) { return Error::handle(name(), L"removeArc", Error::TEST, __FILE__, __LINE__); } } // the root vertex should still be attached to the start vertex of the // graph // if (graph1.getStart()->getCurr()->getVertex() != vertices[0]) { return Error::handle(name(), L"insertArc/removeArc", Error::TEST, __FILE__, __LINE__); } // disconnect the root vertex // if (!graph1.getStart()->removeArc()) { return Error::handle(name(), L"removeArc", Error::TEST, __FILE__, __LINE__); } // the graph start vertex should now be empty // if (!graph1.getStart()->isEmpty()) { return Error::handle(name(), L"removeArc", Error::TEST, __FILE__, __LINE__); } // now rebuild the same binary tree so we can remove arcs a different // way // // attach this as the first node in the graph // graph1.getStart()->insertArc(vertices[0], 0.0, false); // now loop over the remaining vertices - the tree will be built when we // get to 63. the 63rd vertex will only have one child (the root node // takes one vertex) // for (long i = 0; i < 63; i++) { vertices[i]->insertArc(vertices[2 * i + 1], (float)i, false); vertices[i]->insertArc(vertices[2 * i + 2], (float)i, false); } vertices[63]->insertArc(vertices[127], (float)127, false); // reverse engineer the binary tree to make sure it is correct // graph1.getStart()->gotoFirst(); // reset indentation // if (level_a > Integral::NONE) { Console::decreaseIndention(); } // -------------------------------------------------------------------- // // 4. class-specific public methods: // item manipulation methods // // -------------------------------------------------------------------- // set indentation // if (level_a > Integral::NONE) { Console::put(L"testing class-specific public methods: item manupulation methods...\n"); Console::increaseIndention(); } // get the first element and make sure it is the proper root vertex // if (!(graph1.getStart()->isAdjacent(vertices[0])) || (graph1.getStart()->getCurr()->getVertex() != vertices[0]) || (graph1.getStart()->getCurr()-> getVertex()->getItem()->ne(*chars[0]))) { return Error::handle(name(), L"insertArc", Error::TEST, __FILE__, __LINE__); } // test whether the start vertex is start // if (!(graph1.getStart()->isStart())) { return Error::handle(name(), L"isStart", Error::TEST, __FILE__, __LINE__); } // test whether the terminal vertex is terminal // if (!(graph1.getTerm()->isTerm())) { return Error::handle(name(), L"isTerm", Error::TEST, __FILE__, __LINE__); } // test whether all other vertices are not start or terminal // for (long i = 0; i < 128; i++) { if (vertices[i]->isStart() || vertices[i]->isTerm()) { return Error::handle(name(), L"isStart or isTerm", Error::TEST, __FILE__, __LINE__); } } // the leaf vertices should be empty // for (long i = 127; i >= 64; --i) { if (!vertices[i]->isEmpty()) { return Error::handle(name(), L"insertArc", Error::TEST, __FILE__, __LINE__); } } // handle the 63rd item that has only one child vertex // if (vertices[63]->getCurr()->getVertex() != vertices[2 * 63 + 1]) { return Error::handle(name(), L"insertArc", Error::TEST, __FILE__, __LINE__); } // remove the first arc // if (!vertices[63]->removeArc()) { return Error::handle(name(), L"removeArc", Error::TEST, __FILE__, __LINE__); } // the remaining vertices should have the appropriate child vertices in the // appropriate order and with the appropriate weight // for (long i = 62; i >= 32; --i) { // go to the front of the list // vertices[i]->gotoFirst(); // the first vertex should point to the (2*i + 1) element // if (vertices[i]->getCurr()->getVertex() != vertices[2 * i + 1]) { return Error::handle(name(), L"insertArc", Error::TEST, __FILE__, __LINE__); } // move to the next arc // vertices[i]->gotoNext(); // the second vertex should point to the (2*i + 2) element // if (vertices[i]->getCurr()->getVertex() != vertices[2 * i + 2]) { return Error::handle(name(), L"insertArc", Error::TEST, __FILE__, __LINE__); } // remove all arcs from this vertex // if (!vertices[i]->removeAllArcs()) { return Error::handle(name(), L"removeAllArcs", Error::TEST, __FILE__, __LINE__); } if (!vertices[i]->isEmpty()) { return Error::handle(name(), L"removeAllArcs", Error::TEST, __FILE__, __LINE__); } } // the remaining vertices should have the appropriate child vertices in the // appropriate order and with the appropriate weight // for (long i = 31; i >= 0; --i) { // go to the front of the list // vertices[i]->gotoFirst(); // the first vertex should point to the (2*i + 1) element // if (vertices[i]->getCurr()->getVertex() != vertices[2 * i + 1]) { return Error::handle(name(), L"insertArc", Error::TEST, __FILE__, __LINE__); } // move to the next vertex // vertices[i]->gotoNext(); // the second vertex should point to the (2*i + 2) element // if (vertices[i]->getCurr()->getVertex() != vertices[2 * i + 2]) { return Error::handle(name(), L"insertArc", Error::TEST, __FILE__, __LINE__); } // remove the arcs in turn // if (!vertices[i]->removeArc(vertices[2 * i + 2])) { return Error::handle(name(), L"removeArc", Error::TEST, __FILE__, __LINE__); } if (!vertices[i]->removeArc(vertices[2 * i + 1])) { return Error::handle(name(), L"removeArc", Error::TEST, __FILE__, __LINE__); } // make sure the list is now empty // if (!vertices[i]->isEmpty()) { return Error::handle(name(), L"removeArc", Error::TEST, __FILE__, __LINE__); } } // the root vertex should still be attached to the start vertex of the // graph // if (graph1.getStart()->getCurr()->getVertex() != vertices[0]) { return Error::handle(name(), L"insertArc/removeArc", Error::TEST, __FILE__, __LINE__); } // disconnect the root vertex // if (!graph1.getStart()->removeArc()) { return Error::handle(name(), L"removeArc", Error::TEST, __FILE__, __LINE__); } // the graph start vertex should now be empty // if (!graph1.getStart()->isEmpty()) { return Error::handle(name(), L"removeArc", Error::TEST, __FILE__, __LINE__); } // clean up the memory // for (long i = 0; i < 128; i++) { delete chars[i]; delete vertices[i]; } // reset indentation // if (level_a > Integral::NONE) { Console::decreaseIndention(); } //--------------------------------------------------------------------- // // 7. 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 + -