-
Notifications
You must be signed in to change notification settings - Fork 5
/
gtest_hw0.cpp
75 lines (58 loc) · 2.02 KB
/
gtest_hw0.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
67
68
69
70
71
72
73
74
#include <gtest/gtest.h>
#include <fstream>
#include "CME212/Util.hpp"
#include "Graph.hpp"
class GraphPointFixture : public ::testing::Test {
protected:
//Define types
using GraphType = Graph;
using NodeType = typename GraphType::node_type;
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 has_node function
TEST_F(GraphPointFixture, HasNode){
GraphType::node_type n0 = graph.add_node(points[0]);
EXPECT_TRUE( graph.has_node(n0) ) << "has_node did not find n0";
}
// Test num nodes/size functions
TEST_F(GraphPointFixture, Size){
EXPECT_EQ(graph.num_nodes(),graph.size()) << "num_nodes and size are different" ;
EXPECT_EQ(graph.size(), 0) << "starting size is not 0" ;
graph.add_node(points[0]);
graph.add_node(points[1]);
EXPECT_EQ(graph.num_nodes(),graph.size()) << "num_nodes and size are different";
EXPECT_EQ(graph.size(), 2) << "size is incorrect";
}
// Test edge function
TEST_F(GraphPointFixture, Edge){
NodeType n0 = graph.add_node(points[0]);
NodeType n1 = graph.add_node(points[1]);
graph.add_node(points[2]);
EdgeType e0 = graph.add_edge(n0, n1);
EXPECT_EQ(e0, graph.edge(0)) << "error in edge retreval" ;
}
// Verify only one of e0 < e1 or e1 < e0 is true
TEST_F(GraphPointFixture, Tricotomy){
NodeType n0 = graph.add_node(points[0]);
NodeType n1 = graph.add_node(points[1]);
NodeType n2 = graph.add_node(points[2]);
EdgeType e0 = graph.add_edge(n0, n1);
EdgeType e1 = graph.add_edge(n1, n2);
EXPECT_TRUE( (e0 < e1) ^ (e1 < e0) ) << "error in edge comparison";
}
// Add existing edge doesn't create another edge
TEST_F(GraphPointFixture, AddEdge){
NodeType n0 = graph.add_node(points[0]);
NodeType n1 = graph.add_node(points[1]);
graph.add_edge(n0, n1);
graph.add_edge(n0, n1);
graph.add_edge(n1, n0);
EXPECT_EQ(graph.num_edges(), 1) << " add edge creates duplicate edges " ;
}