Fix the struct weak ordering used by independent set ordering, tests for it

This commit is contained in:
Sameer Agarwal
2012-05-06 15:33:47 -07:00
parent 887b156b91
commit 4f21c68409
2 changed files with 25 additions and 1 deletions
+1 -1
View File
@@ -50,7 +50,7 @@ class VertexDegreeLessThan {
bool operator()(const Vertex& lhs, const Vertex& rhs) const {
if (graph_.Neighbors(lhs).size() == graph_.Neighbors(rhs).size()) {
return lhs->user_state() < rhs->user_state();
return (lhs < rhs);
}
return (graph_.Neighbors(lhs).size() < graph_.Neighbors(rhs).size());
}
+24
View File
@@ -165,5 +165,29 @@ TEST(Degree2MaximumSpanningForest, StarGraph) {
}
}
TEST(VertexDegreeLessThan, TotalOrdering) {
Graph<int> graph;
graph.AddVertex(0);
graph.AddVertex(1);
graph.AddVertex(2);
graph.AddVertex(3);
// 0-1 2-3
// All vertices have degree 1.
graph.AddEdge(0, 1, 1.0);
graph.AddEdge(2, 3, 1.0);
VertexDegreeLessThan<int> less_than(graph);
for (int i = 0; i < 4; ++i) {
EXPECT_FALSE(less_than(i,i))
<< "Failing vertex: " << i;
for (int j = 0; j < 4; ++j) {
if (i != j) {
EXPECT_TRUE(less_than(i,j) ^ less_than(j,i))
<< "Failing vertex pair: " << i << " " << j;
}
}
}
}
} // namespace internal
} // namespace ceres