From 3e10adb178be8bf49510eb95297834057a0461d1 Mon Sep 17 00:00:00 2001 From: Frank Dellaert Date: Wed, 3 Apr 2019 23:42:36 -0400 Subject: [PATCH] Cleaned up tests, testing size() as well. --- gtsam/symbolic/tests/testVariableIndex.cpp | 75 ++++++++++------------ 1 file changed, 33 insertions(+), 42 deletions(-) diff --git a/gtsam/symbolic/tests/testVariableIndex.cpp b/gtsam/symbolic/tests/testVariableIndex.cpp index 56ce1f9a5..580f5a1a4 100644 --- a/gtsam/symbolic/tests/testVariableIndex.cpp +++ b/gtsam/symbolic/tests/testVariableIndex.cpp @@ -11,60 +11,66 @@ /** * @file testVariableIndex.cpp - * @brief + * @brief Unit tests for VariableIndex class * @author Richard Roberts - * @date Sep 26, 2010 + * @date Sep 26, 2010 */ +#include +#include +#include + +#include + #include #include using namespace boost::assign; -#include -#include - -#include -#include - using namespace std; using namespace gtsam; /* ************************************************************************* */ -TEST(VariableIndex, augment) { +// 2 small symbolic graphs shared by all tests - SymbolicFactorGraph fg1, fg2; +SymbolicFactorGraph testGraph1() { + SymbolicFactorGraph fg1; fg1.push_factor(0, 1); fg1.push_factor(0, 2); fg1.push_factor(5, 9); fg1.push_factor(2, 3); + return fg1; +} + +SymbolicFactorGraph testGraph2() { + SymbolicFactorGraph fg2; fg2.push_factor(1, 3); fg2.push_factor(2, 4); fg2.push_factor(3, 5); fg2.push_factor(5, 6); + return fg2; +} - SymbolicFactorGraph fgCombined; fgCombined.push_back(fg1); fgCombined.push_back(fg2); +/* ************************************************************************* */ +TEST(VariableIndex, augment) { + auto fg1 = testGraph1(), fg2 = testGraph2(); + SymbolicFactorGraph fgCombined; + fgCombined.push_back(fg1); + fgCombined.push_back(fg2); VariableIndex expected(fgCombined); VariableIndex actual(fg1); actual.augment(fg2); - LONGS_EQUAL(16, (long)actual.nEntries()); - LONGS_EQUAL(8, (long)actual.nFactors()); + LONGS_EQUAL(8, actual.size()); + LONGS_EQUAL(16, actual.nEntries()); + LONGS_EQUAL(8, actual.nFactors()); EXPECT(assert_equal(expected, actual)); } /* ************************************************************************* */ TEST(VariableIndex, augment2) { - SymbolicFactorGraph fg1, fg2; - fg1.push_factor(0, 1); - fg1.push_factor(0, 2); - fg1.push_factor(5, 9); - fg1.push_factor(2, 3); - fg2.push_factor(1, 3); - fg2.push_factor(2, 4); - fg2.push_factor(3, 5); - fg2.push_factor(5, 6); + auto fg1 = testGraph1(), fg2 = testGraph2(); SymbolicFactorGraph fgCombined; fgCombined.push_back(fg1); @@ -77,23 +83,16 @@ TEST(VariableIndex, augment2) { VariableIndex actual(fg1); actual.augment(fg2, newIndices); - LONGS_EQUAL(16, (long) actual.nEntries()); - LONGS_EQUAL(9, (long) actual.nFactors()); + LONGS_EQUAL(8, actual.size()); + LONGS_EQUAL(16, actual.nEntries()); + LONGS_EQUAL(9, actual.nFactors()); EXPECT(assert_equal(expected, actual)); } /* ************************************************************************* */ TEST(VariableIndex, remove) { - SymbolicFactorGraph fg1, fg2; - fg1.push_factor(0, 1); - fg1.push_factor(0, 2); - fg1.push_factor(5, 9); - fg1.push_factor(2, 3); - fg2.push_factor(1, 3); - fg2.push_factor(2, 4); - fg2.push_factor(3, 5); - fg2.push_factor(5, 6); + auto fg1 = testGraph1(), fg2 = testGraph2(); SymbolicFactorGraph fgCombined; fgCombined.push_back(fg1); fgCombined.push_back(fg2); @@ -118,15 +117,7 @@ TEST(VariableIndex, remove) { /* ************************************************************************* */ TEST(VariableIndex, deep_copy) { - SymbolicFactorGraph fg1, fg2; - fg1.push_factor(0, 1); - fg1.push_factor(0, 2); - fg1.push_factor(5, 9); - fg1.push_factor(2, 3); - fg2.push_factor(1, 3); - fg2.push_factor(2, 4); - fg2.push_factor(3, 5); - fg2.push_factor(5, 6); + auto fg1 = testGraph1(), fg2 = testGraph2(); // Create original graph and VariableIndex SymbolicFactorGraph fgOriginal; fgOriginal.push_back(fg1); fgOriginal.push_back(fg2);