File: ConstrainedBFSVisitorTest.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 (144 lines) | stat: -rw-r--r-- 3,832 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include "Graph/Path.h"
#include "Graph/BreadthFirstSearch.h"
#include "Graph/ConstrainedBFSVisitor.h"
#include "Graph/DefaultColorMap.h"
#include <boost/graph/adjacency_list.hpp>
#include <boost/property_map/property_map.hpp>
#include <gtest/gtest.h>

using namespace std;
using namespace boost;

typedef adjacency_list<vecS, vecS, bidirectionalS> Graph;
typedef graph_traits<Graph>::vertex_descriptor V;
typedef std::vector< Path<V> > PathList;

namespace {

class ConstrainedBFSVisitorTest : public ::testing::Test {

protected:

	Graph simpleAcyclicGraph;
	Graph simpleCyclicGraph;

	ConstrainedBFSVisitorTest() {

		add_edge(0, 1, simpleAcyclicGraph);
		add_edge(0, 2, simpleAcyclicGraph);
		add_edge(2, 3, simpleAcyclicGraph);

		add_edge(0, 1, simpleCyclicGraph);
		add_edge(1, 3, simpleCyclicGraph);
		add_edge(0, 2, simpleCyclicGraph);
		add_edge(2, 3, simpleCyclicGraph);

	}
};

TEST_F(ConstrainedBFSVisitorTest, IdentifyUniquePath)
{
	int start = 0;
	int goal = 3;
	int minDepth = 0;
	int maxDepth = 2;
	int maxBranches = 3;

	DefaultColorMap<Graph> colorMap;
	ConstrainedBFSVisitor<Graph> visitor(start, goal, minDepth, maxDepth, maxBranches, colorMap);
	breadthFirstSearch(start, simpleAcyclicGraph, colorMap, visitor);

	AllPathsSearchResult<V> result = visitor.uniquePathToGoal();

	ASSERT_EQ(result.resultCode, FOUND_PATH);
	ASSERT_EQ(result.paths.size(), 1u);
	ASSERT_EQ(result.paths.at(0).str(), "0,2,3");
}

TEST_F(ConstrainedBFSVisitorTest, RespectMaxDepthLimit)
{
	int start = 0;
	int goal = 3;
	int minDepth = 0;
	int maxDepth = 1;
	int maxBranches = 3;

	DefaultColorMap<Graph> colorMap;
	ConstrainedBFSVisitor<Graph> visitor(start, goal, minDepth, maxDepth, maxBranches, colorMap);
	breadthFirstSearch(start, simpleAcyclicGraph, colorMap, visitor);

	EXPECT_EQ(visitor.getMaxDepthVisited(), 1);
	EXPECT_EQ(visitor.uniquePathToGoal().resultCode, NO_PATH);
}

TEST_F(ConstrainedBFSVisitorTest, RespectMinDepthLimit)
{
	int start = 0;
	int goal = 3;
	int minDepth = 3;
	int maxDepth = 10;
	int maxBranches = 3;

	DefaultColorMap<Graph> colorMap;
	ConstrainedBFSVisitor<Graph> visitor(start, goal, minDepth, maxDepth, maxBranches, colorMap);
	breadthFirstSearch(start, simpleAcyclicGraph, colorMap, visitor);

	EXPECT_EQ(visitor.uniquePathToGoal().resultCode, NO_PATH);
}

TEST_F(ConstrainedBFSVisitorTest, IdentifyMultiplePaths)
{
	int start = 0;
	int goal = 3;
	int minDepth = 0;
	int maxDepth = 3;
	int maxBranches = 3;

	DefaultColorMap<Graph> colorMap;
	ConstrainedBFSVisitor<Graph> visitor(start, goal, minDepth, maxDepth, maxBranches, colorMap);
	breadthFirstSearch(start, simpleCyclicGraph, colorMap, visitor);

	EXPECT_EQ(visitor.uniquePathToGoal().resultCode, TOO_MANY_PATHS);
}

TEST_F(ConstrainedBFSVisitorTest, ReturnMultiplePaths)
{
	int start = 0;
	int goal = 3;
	int minDepth = 0;
	int maxDepth = 3;
	int maxBranches = 3;

	DefaultColorMap<Graph> colorMap;
	ConstrainedBFSVisitor<Graph> visitor(start, goal, minDepth, maxDepth, maxBranches, colorMap);
	breadthFirstSearch(start, simpleCyclicGraph, colorMap, visitor);

	AllPathsSearchResult<V> result = visitor.pathsToGoal(2);

	EXPECT_EQ(result.resultCode, FOUND_PATH);
	ASSERT_EQ(result.paths.size(), 2u);

	string path1 = result.paths[0].str();
	string path2 = result.paths[1].str();

	EXPECT_TRUE(path1 != path2);
	ASSERT_TRUE(path1 == "0,1,3" || path1 == "0,2,3");
	ASSERT_TRUE(path2 == "0,1,3" || path2 == "0,2,3");
}

TEST_F(ConstrainedBFSVisitorTest, RespectBranchLimit)
{
	int start = 0;
	int goal = 3;
	int minDepth = 0;
	int maxDepth = 3;
	int maxBranches = 1;

	DefaultColorMap<Graph> colorMap;
	ConstrainedBFSVisitor<Graph> visitor(start, goal, minDepth, maxDepth, maxBranches, colorMap);
	breadthFirstSearch(start, simpleAcyclicGraph, colorMap, visitor);

	EXPECT_EQ(visitor.uniquePathToGoal().resultCode, TOO_MANY_BRANCHES);
}

}