From 1ea39ba1760b039ab4edcdba816762b071951201 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=99=93=E8=88=AA?= <1210603696@qq.com> Date: Wed, 11 Feb 2015 14:37:30 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=B8=A4=E4=B8=AA=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TinySTL/Test/GraphTest.cpp | 33 +++++++++++++++++++++++++++++++++ TinySTL/Test/GraphTest.h | 2 ++ 2 files changed, 35 insertions(+) diff --git a/TinySTL/Test/GraphTest.cpp b/TinySTL/Test/GraphTest.cpp index 23a78c3..ed26904 100644 --- a/TinySTL/Test/GraphTest.cpp +++ b/TinySTL/Test/GraphTest.cpp @@ -51,10 +51,43 @@ namespace TinySTL{ g.delete_node(dGraph::node_type(7, 77)); std::cout << g.to_string(); } + void testCase3(){ + dGraph g; + dGraph::nodes_set_type set1, set2; + set1.push_back(g.make_node(1, 11)); + set1.push_back(g.make_node(2, 22)); + set1.push_back(g.make_node(3, 33)); + g.add_node(g.make_node(0, 0), set1); + + auto nodes = g.adjacent_nodes(0); + std::reverse(set1.begin(), set1.end()); + assert(TinySTL::Test::container_equal(nodes, set1)); + + for (auto it = g.begin(0); it != g.end(0); ++it){ + set2.push_back(*it); + } + assert(TinySTL::Test::container_equal(nodes, set2)); + } + void testCase4(){ + dGraph g; + dGraph::nodes_set_type set; + for (auto i = 0; i != 10; ++i){ + auto node = g.make_node(i, i); + g.add_node(node, g.empty_node_set()); + set.push_back(node); + } + std::reverse(set.begin(), set.end()); + auto it2 = set.begin(); + for (auto it1 = g.begin(); it1 != g.end() && it2 != set.end(); ++it1, ++it2){ + assert(*it1 == *it2); + } + } void testAllCases(){ testCase1(); testCase2(); + testCase3(); + testCase4(); } } } \ No newline at end of file diff --git a/TinySTL/Test/GraphTest.h b/TinySTL/Test/GraphTest.h index bd5a974..1f12a3c 100644 --- a/TinySTL/Test/GraphTest.h +++ b/TinySTL/Test/GraphTest.h @@ -14,6 +14,8 @@ namespace TinySTL{ void testCase1(); void testCase2(); + void testCase3(); + void testCase4(); void testAllCases(); } -- GitLab