-
Notifications
You must be signed in to change notification settings - Fork 5
/
gtest_hw1.cpp
66 lines (54 loc) · 1.68 KB
/
gtest_hw1.cpp
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
#include <gtest/gtest.h>
#include <fstream>
#include "CME212/Util.hpp"
#include "Graph.hpp"
#include "shortest_path.hpp"
#include "subgraph.hpp"
class GraphPointFixture : public ::testing::Test {
protected:
//Define types
using GraphType = Graph<int>;
using NodeType = typename GraphType::node_type;
using NodeIter = typename GraphType::node_iterator;
using EdgeType = typename GraphType::edge_type;
//Set up Graph and Points
GraphType graph;
std::vector<Point> points;
virtual void SetUp() {
for(int i = 0; i < 10; i++)
points.push_back(Point(i));
}
};
// Test adding node with default value
TEST_F(GraphPointFixture, DefaultNodeVal){
graph.add_node(points[0]);
EXPECT_EQ( graph.node(0).value(), 0 ) << "add_node does not intalize node vale with a default 0 value";
}
// Test degree function
TEST_F(GraphPointFixture, Degree){
NodeType n0 = graph.add_node(points[0]);
NodeType n1 = graph.add_node(points[1]);
NodeType n2 = graph.add_node(points[2]);
graph.add_edge(n0, n1);
EXPECT_EQ(n2.degree(),0) << "n2 degree is 0";
EXPECT_EQ(n1.degree(), 1) << "n1 degree is 1";
}
// Test node iterator
TEST_F(GraphPointFixture, NodeIter){
graph.add_node(points[0]);
graph.add_node(points[1]);
graph.add_node(points[2]);
int iter = 0;
for(auto ni = graph.node_begin(); ni != graph.node_end(); ++ni){
++iter;
}
EXPECT_EQ(iter, 3) << " error in node iteration " ;
}
//Test nearest node
TEST_F(GraphPointFixture, ShortestPath){
graph.add_node(points[0]);
graph.add_node(points[1]);
graph.add_node(points[2]);
NodeIter nearest = nearest_node(graph, Point(0));
EXPECT_EQ( *nearest, graph.node(0)) << " error finding nearest node " ;
}