File: HashGraphTest.cpp

package info (click to toggle)
abyss 2.3.10-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,284 kB
  • sloc: cpp: 78,182; ansic: 6,512; makefile: 2,252; perl: 672; sh: 509; haskell: 412; python: 4
file content (88 lines) | stat: -rw-r--r-- 2,018 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include "Graph/HashGraph.h"
#include <string>
#include <gtest/gtest.h>

using namespace std;

namespace {

class HashGraphTest : public ::testing::Test {

protected:

	typedef HashGraph<string> Graph;
	typedef boost::graph_traits<Graph>::edge_descriptor edge_descriptor;
	typedef boost::graph_traits<Graph>::out_edge_iterator out_edge_iterator;
	typedef boost::graph_traits<Graph>::in_edge_iterator in_edge_iterator;
	typedef boost::graph_traits<Graph>::vertex_descriptor vertex_descriptor;
	typedef boost::graph_traits<Graph>::vertex_iterator vertex_iterator;

	Graph simpleCyclicGraph;
	
	string a;
	string b;
	string c;
	string d;

	unordered_set<string> vertexSet;

	HashGraphTest() : a("a"), b("b"), c("c"), d("d") {

		add_edge(a, b, simpleCyclicGraph);
		add_edge(a, c, simpleCyclicGraph);
		add_edge(b, d, simpleCyclicGraph);
		add_edge(c, d, simpleCyclicGraph);

		vertexSet.insert(a);
		vertexSet.insert(b);
		vertexSet.insert(c);
		vertexSet.insert(d);

	}
};

TEST_F(HashGraphTest, out_edge_iterator)
{
	edge_descriptor expectedEdge1(a, b);
	edge_descriptor expectedEdge2(a, c);
	
	out_edge_iterator ei, ei_end;
	boost::tie(ei, ei_end) = out_edges(a, simpleCyclicGraph);

	ASSERT_TRUE(ei != ei_end);
	edge_descriptor edge1 = *ei;
	EXPECT_TRUE(edge1 == expectedEdge1 || edge1 == expectedEdge2);

	ei++;
	ASSERT_TRUE(ei != ei_end);
	edge_descriptor edge2 = *ei;
	EXPECT_TRUE(edge2 != edge1);
	EXPECT_TRUE(edge2 == expectedEdge1 || edge2 == expectedEdge2);
	
	ei++;
	EXPECT_TRUE(ei == ei_end);
}

TEST_F(HashGraphTest, vertex_iterator)
{
	vertex_iterator vi, vi_begin, vi_end;
	boost::tie(vi_begin, vi_end) = vertices(simpleCyclicGraph);
	ASSERT_TRUE(vi_begin != vi_end);

	unsigned count = 0;
	vertex_descriptor v;
	vi = vi_begin;
	for(; vi != vi_end; vi++, count++) {
		// check that current vertex is different from
		// previous vertex
		if (vi != vi_begin) {
			EXPECT_TRUE(*vi != v);
		}
		vertex_descriptor v = *vi;
		EXPECT_TRUE(vertexSet.find(v) != vertexSet.end());
	}

	EXPECT_EQ(4U, count);
}

}