aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-03-20 19:35:49 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-03-20 19:35:49 +0000
commit97ba277d35ca16d32ac4a85ce1cd2e3ffee1dbde (patch)
treedc92bbf6f7db7661da0a419ed5b47e4e4a4f00d9
parentb139d148182be100c25d5b04baa9611ebd4abd87 (diff)
downloadpaludis-97ba277d35ca16d32ac4a85ce1cd2e3ffee1dbde.tar.gz
paludis-97ba277d35ca16d32ac4a85ce1cd2e3ffee1dbde.tar.xz
gtest more
-rw-r--r--paludis/util/files.m42
-rw-r--r--paludis/util/graph_TEST.cc148
2 files changed, 70 insertions, 80 deletions
diff --git a/paludis/util/files.m4 b/paludis/util/files.m4
index 9f87c35..498cd00 100644
--- a/paludis/util/files.m4
+++ b/paludis/util/files.m4
@@ -41,7 +41,7 @@ add(`fs_iterator', `hh', `cc', `fwd', `se', `test', `tests
add(`fs_error', `hh', `cc')
add(`fs_path', `hh', `cc', `fwd', `se', `test', `testscript')
add(`fs_stat', `hh', `cc', `fwd', `test', `testscript')
-add(`graph', `hh', `cc', `fwd', `impl', `test')
+add(`graph', `hh', `cc', `fwd', `impl', `gtest')
add(`hashes', `hh', `cc', `gtest')
add(`iterator_funcs', `hh', `test')
add(`indirect_iterator', `hh', `fwd', `impl', `gtest')
diff --git a/paludis/util/graph_TEST.cc b/paludis/util/graph_TEST.cc
index 2e6f686..0faaa48 100644
--- a/paludis/util/graph_TEST.cc
+++ b/paludis/util/graph_TEST.cc
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2007 Ciaran McCreesh
+ * Copyright (c) 2007, 2011 Ciaran McCreesh
*
* This file is part of the Paludis package manager. Paludis is free software;
* you can redistribute it and/or modify it under the terms of the GNU General
@@ -17,9 +17,6 @@
* Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include <test/test_framework.hh>
-#include <test/test_runner.hh>
-
#include <paludis/util/graph.hh>
#include <paludis/util/graph-impl.hh>
#include <paludis/util/join.hh>
@@ -27,87 +24,80 @@
#include <list>
-using namespace test;
+#include <gtest/gtest.h>
+
using namespace paludis;
-namespace test_cases
+TEST(Graph, Directed)
{
- struct TestDirectedGraph : TestCase
- {
- TestDirectedGraph() : TestCase("directed graph") { }
-
- void run()
+ DirectedGraph<std::string, int> g;
+
+ EXPECT_TRUE(! g.has_node("a"));
+ EXPECT_TRUE(! g.has_node("b"));
+ EXPECT_TRUE(! g.has_node("c"));
+ EXPECT_TRUE(! g.has_node("d"));
+ EXPECT_TRUE(! g.has_node("e"));
+ EXPECT_TRUE(! g.has_node("f"));
+ EXPECT_TRUE(! g.has_node("x"));
+
+ g.add_node("a");
+ g.add_node("b");
+ g.add_node("c");
+ g.add_node("d");
+ g.add_node("e");
+ g.add_node("f");
+
+ EXPECT_TRUE(g.has_node("a"));
+ EXPECT_TRUE(g.has_node("b"));
+ EXPECT_TRUE(g.has_node("c"));
+ EXPECT_TRUE(g.has_node("d"));
+ EXPECT_TRUE(g.has_node("e"));
+ EXPECT_TRUE(g.has_node("f"));
+ EXPECT_TRUE(! g.has_node("x"));
+
+ g.add_node("y");
+ EXPECT_TRUE(g.has_node("y"));
+ g.delete_node("y");
+ EXPECT_TRUE(! g.has_node("y"));
+
+ g.add_edge("a", "b", 1);
+ g.add_edge("b", "c", 2);
+ g.add_edge("c", "e", 3);
+ g.add_edge("b", "d", 4);
+ g.add_edge("d", "e", 5);
+ g.add_edge("d", "f", 6);
+
+ for (char mc('a') ; mc < 'g' ; ++mc)
+ for (char nc('a') ; nc < 'g' ; ++nc)
{
- DirectedGraph<std::string, int> g;
-
- TEST_CHECK(! g.has_node("a"));
- TEST_CHECK(! g.has_node("b"));
- TEST_CHECK(! g.has_node("c"));
- TEST_CHECK(! g.has_node("d"));
- TEST_CHECK(! g.has_node("e"));
- TEST_CHECK(! g.has_node("f"));
- TEST_CHECK(! g.has_node("x"));
-
- g.add_node("a");
- g.add_node("b");
- g.add_node("c");
- g.add_node("d");
- g.add_node("e");
- g.add_node("f");
-
- TEST_CHECK(g.has_node("a"));
- TEST_CHECK(g.has_node("b"));
- TEST_CHECK(g.has_node("c"));
- TEST_CHECK(g.has_node("d"));
- TEST_CHECK(g.has_node("e"));
- TEST_CHECK(g.has_node("f"));
- TEST_CHECK(! g.has_node("x"));
-
- g.add_node("y");
- TEST_CHECK(g.has_node("y"));
- g.delete_node("y");
- TEST_CHECK(! g.has_node("y"));
-
- g.add_edge("a", "b", 1);
- g.add_edge("b", "c", 2);
- g.add_edge("c", "e", 3);
- g.add_edge("b", "d", 4);
- g.add_edge("d", "e", 5);
- g.add_edge("d", "f", 6);
-
- for (char mc('a') ; mc < 'g' ; ++mc)
- for (char nc('a') ; nc < 'g' ; ++nc)
- {
- std::string m(stringify(mc)), n(stringify(nc));
-
- if (g.has_edge(m, n))
- {
- TEST_CHECK(! g.has_edge(n, m));
- TEST_CHECK(g.has_outgoing_edges(m));
- TEST_CHECK(0 != g.fetch_edge(m, n));
- }
- else
- TEST_CHECK_THROWS(g.fetch_edge(m, n), NoSuchGraphEdgeError);
- }
-
- std::list<std::string> t;
- g.topological_sort(std::back_inserter(t));
-
- TEST_CHECK_EQUAL(join(t.begin(), t.end(), " "), "e c f d b a");
-
- g.add_edge("e", "b", 7);
- TEST_CHECK_THROWS(g.topological_sort(std::back_inserter(t)), NoGraphTopologicalOrderExistsError);
-
- try
- {
- g.topological_sort(std::back_inserter(t));
- TEST_CHECK(false);
- }
- catch (const NoGraphTopologicalOrderExistsError & e)
+ std::string m(stringify(mc)), n(stringify(nc));
+
+ if (g.has_edge(m, n))
{
- TEST_CHECK_EQUAL(join(e.remaining_nodes()->begin(), e.remaining_nodes()->end(), " "), "a b c d e");
+ EXPECT_TRUE(! g.has_edge(n, m));
+ EXPECT_TRUE(g.has_outgoing_edges(m));
+ EXPECT_TRUE(0 != g.fetch_edge(m, n));
}
+ else
+ EXPECT_THROW(g.fetch_edge(m, n), NoSuchGraphEdgeError);
}
- } test_directed_graph;
+
+ std::list<std::string> t;
+ g.topological_sort(std::back_inserter(t));
+
+ EXPECT_EQ("e c f d b a", join(t.begin(), t.end(), " "));
+
+ g.add_edge("e", "b", 7);
+ EXPECT_THROW(g.topological_sort(std::back_inserter(t)), NoGraphTopologicalOrderExistsError);
+
+ try
+ {
+ g.topological_sort(std::back_inserter(t));
+ FAIL();
+ }
+ catch (const NoGraphTopologicalOrderExistsError & e)
+ {
+ EXPECT_EQ("a b c d e", join(e.remaining_nodes()->begin(), e.remaining_nodes()->end(), " "));
+ }
}