📄 bigraphvertexdiagnose.h
字号:
// assign the second item // eq_vert_10.assign(eq_vert_00); // call the eq method // if (!eq_vert_00.eq(eq_vert_10)) { return Error::handle(name(), L"eq", Error::TEST, __FILE__, __LINE__); } // reset indentation // if (level_a > Integral::NONE) { Console::decreaseIndention(); } // -------------------------------------------------------------------- // // 2. class-specific public methods: // BiGraph manipulation methods // // -------------------------------------------------------------------- // set indentation // if (level_a > Integral::NONE) { Console::put(L"testing class-specific public methods: BiGraph manipulation methods...\n"); Console::increaseIndention(); } // test item, arc, and parent BiGraph manipulations // Char* chars[128]; for (long i = 0; i < 128; i++) { chars[i] = new Char((unichar)i); } // create two BiGraphs to manipulate // BiGraph<Char> bigraph1(USER); BiGraph<Char> bigraph2(USER); // create an array of vertices to test // BiGraphVertex<Char>* vertices[128]; for (long i = 0; i < 128; i++) { vertices[i] = new BiGraphVertex<Char>(); // set the item in each vertex // vertices[i]->setItem(chars[i]); } // make sure the setParentBiGraph and getParentBiGraph methods work // // assign one of the two BiGraphs to each node // for (long i = 0; i < 64; i++) { if (!vertices[i]->setParentGraph(&bigraph1)) { return Error::handle(name(), L"setParentGraph", Error::TEST, __FILE__, __LINE__); } } for (long i = 64; i < 128; i++) { if (!vertices[i]->setParentGraph(&bigraph2)) { return Error::handle(name(), L"setParentGraph", Error::TEST, __FILE__, __LINE__); } } // make sure that the proper BiGraph was assigned // for (long i = 0; i < 64; i++) { if ((vertices[i]->getParentGraph() != &bigraph1) || (vertices[128 - i - 1]->getParentGraph() != &bigraph2) || (vertices[i]->getParentGraph() == vertices[128 - i - 1]->getParentGraph())) { return Error::handle(name(), L"getParentGraph", Error::TEST, __FILE__, __LINE__); } } // start building a binary tree BiGraph 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 BiGraph characteristics // bigraph1.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 BiGraph // bigraph1.getStart()->insertArcChild(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]->insertArcChild(vertices[2 * i + 1], (float)i, false); vertices[i]->insertArcChild(vertices[2 * i + 2], (float)i, false); } vertices[63]->insertArcChild(vertices[127], (float)127, false); // reverse engineer the binary tree to make sure it is correct // bigraph1.getStart()->gotoFirstChild(); // get the first element and make sure it is the proper root vertex // if (!(bigraph1.getStart()->isAdjacentChild(vertices[0])) || (bigraph1.getStart()->getCurrChild()->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]->isEmptyChild()) { return Error::handle(name(), L"insertArc", Error::TEST, __FILE__, __LINE__); } } // handle the 63rd item that has only one child vertex // if (vertices[63]->getCurrChild()->getVertex() != vertices[2 * 63 + 1]) { return Error::handle(name(), L"insertArc", Error::TEST, __FILE__, __LINE__); } // remove the first arc // if (!vertices[63]->removeArcChild()) { 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]->gotoFirstChild(); // the first vertex should point to the (2*i + 1) element // if (vertices[i]->getCurrChild()->getVertex() != vertices[2 * i + 1]) { return Error::handle(name(), L"insertArc", Error::TEST, __FILE__, __LINE__); } // remove the first arc // if (!vertices[i]->removeArcChild()) { return Error::handle(name(), L"removeArc", Error::TEST, __FILE__, __LINE__); } // the second vertex should point to the (2*i + 2) element // if (vertices[i]->getCurrChild()->getVertex() != vertices[2 * i + 2]) { return Error::handle(name(), L"insertArc", Error::TEST, __FILE__, __LINE__); } // remove the second arc // if (!vertices[i]->removeArcChild()) { return Error::handle(name(), L"removeArc", Error::TEST, __FILE__, __LINE__); } // make sure the list is now empty // if (!vertices[i]->isEmptyChild()) { return Error::handle(name(), L"removeArc", Error::TEST, __FILE__, __LINE__); } } // the root vertex should still be attached to the start vertex of the // BiGraph // if (bigraph1.getStart()->getCurrChild()->getVertex() != vertices[0]) { return Error::handle(name(), L"insertArc/removeArc", Error::TEST, __FILE__, __LINE__); } // disconnect the root vertex // if (!bigraph1.getStart()->removeArcChild()) { return Error::handle(name(), L"removeArc", Error::TEST, __FILE__, __LINE__); } // the BiGraph start vertex should now be empty // if (!bigraph1.getStart()->isEmptyChild()) { 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 BiGraph // bigraph1.getStart()->insertArcChild(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]->insertArcChild(vertices[2 * i + 1], (float)i, false); vertices[i]->insertArcChild(vertices[2 * i + 2], (float)i, false); } vertices[63]->insertArcChild(vertices[127], (float)127, false); // reverse engineer the binary tree to make sure it is correct // bigraph1.getStart()->gotoFirstChild(); } { // attach this as the first node in the BiGraph // bigraph1.getStart()->insertArcParent(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]->insertArcParent(vertices[2 * i + 1], (float)i, false); vertices[i]->insertArcParent(vertices[2 * i + 2], (float)i, false); } vertices[63]->insertArcParent(vertices[127], (float)127, false); // reverse engineer the binary tree to make sure it is correct // bigraph1.getStart()->gotoFirstParent(); // get the first element and make sure it is the proper root vertex // if (!(bigraph1.getStart()->isAdjacentParent(vertices[0])) || (bigraph1.getStart()->getCurrParent()->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]->isEmptyParent()) { return Error::handle(name(), L"insertArc", Error::TEST, __FILE__, __LINE__); } } // handle the 63rd item that has only one child vertex // if (vertices[63]->getCurrParent()->getVertex() != vertices[2 * 63 + 1]) { return Error::handle(name(), L"insertArc", Error::TEST, __FILE__, __LINE__); } // remove the first arc // if (!vertices[63]->removeArcParent()) { 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]->gotoFirstParent(); // the first vertex should point to the (2*i + 1) element // if (vertices[i]->getCurrParent()->getVertex() != vertices[2 * i + 1]) { return Error::handle(name(), L"insertArc", Error::TEST, __FILE__, __LINE__); } // remove the first arc // if (!vertices[i]->removeArcParent()) { return Error::handle(name(), L"removeArc", Error::TEST, __FILE__, __LINE__); } // the second vertex should point to the (2*i + 2) element // if (vertices[i]->getCurrParent()->getVertex() != vertices[2 * i + 2]) { return Error::handle(name(), L"insertArc", Error::TEST, __FILE__, __LINE__); } // remove the second arc // if (!vertices[i]->removeArcParent()) { return Error::handle(name(), L"removeArc", Error::TEST, __FILE__, __LINE__); } // make sure the list is now empty // if (!vertices[i]->isEmptyParent()) { return Error::handle(name(), L"removeArc", Error::TEST, __FILE__, __LINE__); } } // the root vertex should still be attached to the start vertex of the // BiGraph // if (bigraph1.getStart()->getCurrParent()->getVertex() != vertices[0]) { return Error::handle(name(), L"insertArc/removeArc", Error::TEST, __FILE__, __LINE__); } // disconnect the root vertex // if (!bigraph1.getStart()->removeArcParent()) { return Error::handle(name(), L"removeArc", Error::TEST, __FILE__, __LINE__); } // the BiGraph start vertex should now be empty // if (!bigraph1.getStart()->isEmptyParent()) { return Error::handle(name(), L"removeArc", Error::TEST, __FILE__, __LINE__); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -