Lines Matching refs:Graph
31 #include "ceres/graph.h"
40 TEST(Graph, EmptyGraph) {
41 Graph<int> graph;
42 EXPECT_EQ(graph.vertices().size(), 0);
45 TEST(Graph, AddVertexAndEdge) {
46 Graph<int> graph;
47 graph.AddVertex(0, 1.0);
48 graph.AddVertex(1, 2.0);
49 graph.AddEdge(0, 1, 0.5);
51 const HashSet<int>& vertices = graph.vertices();
53 EXPECT_EQ(graph.VertexWeight(0), 1.0);
54 EXPECT_EQ(graph.VertexWeight(1), 2.0);
55 EXPECT_EQ(graph.Neighbors(0).size(), 1);
56 EXPECT_EQ(graph.Neighbors(1).size(), 1);
57 EXPECT_EQ(graph.EdgeWeight(0, 1), 0.5);
58 EXPECT_EQ(graph.EdgeWeight(1, 0), 0.5);
61 TEST(Graph, AddVertexIdempotence) {
62 Graph<int> graph;
63 graph.AddVertex(0, 1.0);
64 graph.AddVertex(1, 2.0);
65 graph.AddEdge(0, 1, 0.5);
67 const HashSet<int>& vertices = graph.vertices();
72 graph.AddVertex(0, 3.0);
76 EXPECT_EQ(graph.VertexWeight(0), 3.0);
78 // Rest of the graph remains the same.
79 EXPECT_EQ(graph.VertexWeight(1), 2.0);
80 EXPECT_EQ(graph.Neighbors(0).size(), 1);
81 EXPECT_EQ(graph.Neighbors(1).size(), 1);
82 EXPECT_EQ(graph.EdgeWeight(0, 1), 0.5);
83 EXPECT_EQ(graph.EdgeWeight(1, 0), 0.5);
86 TEST(Graph, DieOnNonExistentVertex) {
87 Graph<int> graph;
88 graph.AddVertex(0, 1.0);
89 graph.AddVertex(1, 2.0);
90 graph.AddEdge(0, 1, 0.5);
92 EXPECT_DEATH_IF_SUPPORTED(graph.VertexWeight(2), "key not found");
93 EXPECT_DEATH_IF_SUPPORTED(graph.Neighbors(2), "key not found");
96 TEST(Graph, NonExistentEdge) {
97 Graph<int> graph;
98 graph.AddVertex(0, 1.0);
99 graph.AddVertex(1, 2.0);
100 graph.AddEdge(0, 1, 0.5);
103 EXPECT_EQ(graph.EdgeWeight(2, 3), 0);