Got rid of boost::assign in many tests

release/4.3a0
Frank Dellaert 2023-01-07 15:43:17 -08:00
parent d2f0cf5cc7
commit 017cd8f8a2
15 changed files with 102 additions and 159 deletions

View File

@ -16,17 +16,14 @@
* @brief unit tests for DSFMap * @brief unit tests for DSFMap
*/ */
#include <CppUnitLite/TestHarness.h>
#include <gtsam/base/DSFMap.h> #include <gtsam/base/DSFMap.h>
#include <boost/assign/std/list.hpp>
#include <boost/assign/std/set.hpp>
using namespace boost::assign;
#include <CppUnitLite/TestHarness.h>
#include <iostream> #include <iostream>
#include <list>
#include <map>
#include <set>
using namespace std;
using namespace gtsam; using namespace gtsam;
/* ************************************************************************* */ /* ************************************************************************* */
@ -65,9 +62,8 @@ TEST(DSFMap, merge3) {
TEST(DSFMap, mergePairwiseMatches) { TEST(DSFMap, mergePairwiseMatches) {
// Create some "matches" // Create some "matches"
typedef pair<size_t,size_t> Match; typedef std::pair<size_t, size_t> Match;
list<Match> matches; const std::list<Match> matches{{1, 2}, {2, 3}, {4, 5}, {4, 6}};
matches += Match(1,2), Match(2,3), Match(4,5), Match(4,6);
// Merge matches // Merge matches
DSFMap<size_t> dsf; DSFMap<size_t> dsf;
@ -86,18 +82,17 @@ TEST(DSFMap, mergePairwiseMatches) {
TEST(DSFMap, mergePairwiseMatches2) { TEST(DSFMap, mergePairwiseMatches2) {
// Create some measurements with image index and feature index // Create some measurements with image index and feature index
typedef pair<size_t,size_t> Measurement; typedef std::pair<size_t,size_t> Measurement;
Measurement m11(1,1),m12(1,2),m14(1,4); // in image 1 Measurement m11(1,1),m12(1,2),m14(1,4); // in image 1
Measurement m22(2,2),m23(2,3),m25(2,5),m26(2,6); // in image 2 Measurement m22(2,2),m23(2,3),m25(2,5),m26(2,6); // in image 2
// Add them all // Add them all
list<Measurement> measurements; const std::list<Measurement> measurements{m11, m12, m14, m22, m23, m25, m26};
measurements += m11,m12,m14, m22,m23,m25,m26;
// Create some "matches" // Create some "matches"
typedef pair<Measurement,Measurement> Match; typedef std::pair<Measurement, Measurement> Match;
list<Match> matches; const std::list<Match> matches{
matches += Match(m11,m22), Match(m12,m23), Match(m14,m25), Match(m14,m26); {m11, m22}, {m12, m23}, {m14, m25}, {m14, m26}};
// Merge matches // Merge matches
DSFMap<Measurement> dsf; DSFMap<Measurement> dsf;
@ -114,26 +109,16 @@ TEST(DSFMap, mergePairwiseMatches2) {
/* ************************************************************************* */ /* ************************************************************************* */
TEST(DSFMap, sets){ TEST(DSFMap, sets){
// Create some "matches" // Create some "matches"
typedef pair<size_t,size_t> Match; typedef const std::pair<size_t,size_t> Match;
list<Match> matches; const std::list<Match> matches{{1, 2}, {2, 3}, {4, 5}, {4, 6}};
matches += Match(1,2), Match(2,3), Match(4,5), Match(4,6);
// Merge matches // Merge matches
DSFMap<size_t> dsf; DSFMap<size_t> dsf;
for(const Match& m: matches) for(const Match& m: matches)
dsf.merge(m.first,m.second); dsf.merge(m.first,m.second);
map<size_t, set<size_t> > sets = dsf.sets(); std::map<size_t, std::set<size_t> > sets = dsf.sets();
set<size_t> s1, s2; const std::set<size_t> s1{1, 2, 3}, s2{4, 5, 6};
s1 += 1,2,3;
s2 += 4,5,6;
/*for(key_pair st: sets){
cout << "Set " << st.first << " :{";
for(const size_t s: st.second)
cout << s << ", ";
cout << "}" << endl;
}*/
EXPECT(s1 == sets[1]); EXPECT(s1 == sets[1]);
EXPECT(s2 == sets[4]); EXPECT(s2 == sets[4]);

View File

@ -21,14 +21,15 @@
#include <CppUnitLite/TestHarness.h> #include <CppUnitLite/TestHarness.h>
#include <boost/make_shared.hpp> #include <boost/make_shared.hpp>
#include <boost/assign/std/list.hpp>
#include <boost/assign/std/set.hpp>
#include <boost/assign/std/vector.hpp>
using namespace boost::assign;
#include <iostream> #include <iostream>
#include <set>
#include <list>
#include <utility>
using namespace std; using std::pair;
using std::map;
using std::vector;
using namespace gtsam; using namespace gtsam;
/* ************************************************************************* */ /* ************************************************************************* */
@ -64,8 +65,8 @@ TEST(DSFBase, mergePairwiseMatches) {
// Create some "matches" // Create some "matches"
typedef pair<size_t,size_t> Match; typedef pair<size_t,size_t> Match;
vector<Match> matches; const vector<Match> matches{Match(1, 2), Match(2, 3), Match(4, 5),
matches += Match(1,2), Match(2,3), Match(4,5), Match(4,6); Match(4, 6)};
// Merge matches // Merge matches
DSFBase dsf(7); // We allow for keys 0..6 DSFBase dsf(7); // We allow for keys 0..6
@ -85,7 +86,7 @@ TEST(DSFBase, mergePairwiseMatches) {
/* ************************************************************************* */ /* ************************************************************************* */
TEST(DSFVector, merge2) { TEST(DSFVector, merge2) {
boost::shared_ptr<DSFBase::V> v = boost::make_shared<DSFBase::V>(5); boost::shared_ptr<DSFBase::V> v = boost::make_shared<DSFBase::V>(5);
std::vector<size_t> keys; keys += 1, 3; const std::vector<size_t> keys {1, 3};
DSFVector dsf(v, keys); DSFVector dsf(v, keys);
dsf.merge(1,3); dsf.merge(1,3);
EXPECT(dsf.find(1) == dsf.find(3)); EXPECT(dsf.find(1) == dsf.find(3));
@ -95,10 +96,10 @@ TEST(DSFVector, merge2) {
TEST(DSFVector, sets) { TEST(DSFVector, sets) {
DSFVector dsf(2); DSFVector dsf(2);
dsf.merge(0,1); dsf.merge(0,1);
map<size_t, set<size_t> > sets = dsf.sets(); map<size_t, std::set<size_t> > sets = dsf.sets();
LONGS_EQUAL(1, sets.size()); LONGS_EQUAL(1, sets.size());
set<size_t> expected; expected += 0, 1; const std::set<size_t> expected{0, 1};
EXPECT(expected == sets[dsf.find(0)]); EXPECT(expected == sets[dsf.find(0)]);
} }
@ -109,7 +110,7 @@ TEST(DSFVector, arrays) {
map<size_t, vector<size_t> > arrays = dsf.arrays(); map<size_t, vector<size_t> > arrays = dsf.arrays();
LONGS_EQUAL(1, arrays.size()); LONGS_EQUAL(1, arrays.size());
vector<size_t> expected; expected += 0, 1; const vector<size_t> expected{0, 1};
EXPECT(expected == arrays[dsf.find(0)]); EXPECT(expected == arrays[dsf.find(0)]);
} }
@ -118,10 +119,10 @@ TEST(DSFVector, sets2) {
DSFVector dsf(3); DSFVector dsf(3);
dsf.merge(0,1); dsf.merge(0,1);
dsf.merge(1,2); dsf.merge(1,2);
map<size_t, set<size_t> > sets = dsf.sets(); map<size_t, std::set<size_t> > sets = dsf.sets();
LONGS_EQUAL(1, sets.size()); LONGS_EQUAL(1, sets.size());
set<size_t> expected; expected += 0, 1, 2; const std::set<size_t> expected{0, 1, 2};
EXPECT(expected == sets[dsf.find(0)]); EXPECT(expected == sets[dsf.find(0)]);
} }
@ -133,7 +134,7 @@ TEST(DSFVector, arrays2) {
map<size_t, vector<size_t> > arrays = dsf.arrays(); map<size_t, vector<size_t> > arrays = dsf.arrays();
LONGS_EQUAL(1, arrays.size()); LONGS_EQUAL(1, arrays.size());
vector<size_t> expected; expected += 0, 1, 2; const vector<size_t> expected{0, 1, 2};
EXPECT(expected == arrays[dsf.find(0)]); EXPECT(expected == arrays[dsf.find(0)]);
} }
@ -141,10 +142,10 @@ TEST(DSFVector, arrays2) {
TEST(DSFVector, sets3) { TEST(DSFVector, sets3) {
DSFVector dsf(3); DSFVector dsf(3);
dsf.merge(0,1); dsf.merge(0,1);
map<size_t, set<size_t> > sets = dsf.sets(); map<size_t, std::set<size_t> > sets = dsf.sets();
LONGS_EQUAL(2, sets.size()); LONGS_EQUAL(2, sets.size());
set<size_t> expected; expected += 0, 1; const std::set<size_t> expected{0, 1};
EXPECT(expected == sets[dsf.find(0)]); EXPECT(expected == sets[dsf.find(0)]);
} }
@ -155,7 +156,7 @@ TEST(DSFVector, arrays3) {
map<size_t, vector<size_t> > arrays = dsf.arrays(); map<size_t, vector<size_t> > arrays = dsf.arrays();
LONGS_EQUAL(2, arrays.size()); LONGS_EQUAL(2, arrays.size());
vector<size_t> expected; expected += 0, 1; const vector<size_t> expected{0, 1};
EXPECT(expected == arrays[dsf.find(0)]); EXPECT(expected == arrays[dsf.find(0)]);
} }
@ -163,10 +164,10 @@ TEST(DSFVector, arrays3) {
TEST(DSFVector, set) { TEST(DSFVector, set) {
DSFVector dsf(3); DSFVector dsf(3);
dsf.merge(0,1); dsf.merge(0,1);
set<size_t> set = dsf.set(0); std::set<size_t> set = dsf.set(0);
LONGS_EQUAL(2, set.size()); LONGS_EQUAL(2, set.size());
std::set<size_t> expected; expected += 0, 1; const std::set<size_t> expected{0, 1};
EXPECT(expected == set); EXPECT(expected == set);
} }
@ -175,10 +176,10 @@ TEST(DSFVector, set2) {
DSFVector dsf(3); DSFVector dsf(3);
dsf.merge(0,1); dsf.merge(0,1);
dsf.merge(1,2); dsf.merge(1,2);
set<size_t> set = dsf.set(0); std::set<size_t> set = dsf.set(0);
LONGS_EQUAL(3, set.size()); LONGS_EQUAL(3, set.size());
std::set<size_t> expected; expected += 0, 1, 2; const std::set<size_t> expected{0, 1, 2};
EXPECT(expected == set); EXPECT(expected == set);
} }
@ -195,13 +196,12 @@ TEST(DSFVector, isSingleton) {
TEST(DSFVector, mergePairwiseMatches) { TEST(DSFVector, mergePairwiseMatches) {
// Create some measurements // Create some measurements
vector<size_t> keys; const vector<size_t> keys{1, 2, 3, 4, 5, 6};
keys += 1,2,3,4,5,6;
// Create some "matches" // Create some "matches"
typedef pair<size_t,size_t> Match; typedef pair<size_t,size_t> Match;
vector<Match> matches; const vector<Match> matches{Match(1, 2), Match(2, 3), Match(4, 5),
matches += Match(1,2), Match(2,3), Match(4,5), Match(4,6); Match(4, 6)};
// Merge matches // Merge matches
DSFVector dsf(keys); DSFVector dsf(keys);
@ -209,13 +209,13 @@ TEST(DSFVector, mergePairwiseMatches) {
dsf.merge(m.first,m.second); dsf.merge(m.first,m.second);
// Check that we have two connected components, 1,2,3 and 4,5,6 // Check that we have two connected components, 1,2,3 and 4,5,6
map<size_t, set<size_t> > sets = dsf.sets(); map<size_t, std::set<size_t> > sets = dsf.sets();
LONGS_EQUAL(2, sets.size()); LONGS_EQUAL(2, sets.size());
set<size_t> expected1; expected1 += 1,2,3; const std::set<size_t> expected1{1, 2, 3};
set<size_t> actual1 = sets[dsf.find(2)]; std::set<size_t> actual1 = sets[dsf.find(2)];
EXPECT(expected1 == actual1); EXPECT(expected1 == actual1);
set<size_t> expected2; expected2 += 4,5,6; const std::set<size_t> expected2{4, 5, 6};
set<size_t> actual2 = sets[dsf.find(5)]; std::set<size_t> actual2 = sets[dsf.find(5)];
EXPECT(expected2 == actual2); EXPECT(expected2 == actual2);
} }

View File

@ -11,12 +11,8 @@
#include <gtsam/base/FastSet.h> #include <gtsam/base/FastSet.h>
#include <gtsam/base/FastVector.h> #include <gtsam/base/FastVector.h>
#include <boost/assign/std/vector.hpp>
#include <boost/assign/std/set.hpp>
#include <CppUnitLite/TestHarness.h> #include <CppUnitLite/TestHarness.h>
using namespace boost::assign;
using namespace gtsam; using namespace gtsam;
/* ************************************************************************* */ /* ************************************************************************* */
@ -25,7 +21,7 @@ TEST( testFastContainers, KeySet ) {
KeyVector init_vector {2, 3, 4, 5}; KeyVector init_vector {2, 3, 4, 5};
KeySet actSet(init_vector); KeySet actSet(init_vector);
KeySet expSet; expSet += 2, 3, 4, 5; KeySet expSet{2, 3, 4, 5};
EXPECT(actSet == expSet); EXPECT(actSet == expSet);
} }

View File

@ -17,14 +17,12 @@
#include <CppUnitLite/TestHarness.h> #include <CppUnitLite/TestHarness.h>
#include <gtsam/base/SymmetricBlockMatrix.h> #include <gtsam/base/SymmetricBlockMatrix.h>
#include <boost/assign/list_of.hpp>
using namespace std; using namespace std;
using namespace gtsam; using namespace gtsam;
using boost::assign::list_of;
static SymmetricBlockMatrix testBlockMatrix( static SymmetricBlockMatrix testBlockMatrix(
list_of(3)(2)(1), std::vector<size_t>{3, 2, 1},
(Matrix(6, 6) << (Matrix(6, 6) <<
1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6,
2, 8, 9, 10, 11, 12, 2, 8, 9, 10, 11, 12,
@ -101,7 +99,8 @@ TEST(SymmetricBlockMatrix, Ranges)
/* ************************************************************************* */ /* ************************************************************************* */
TEST(SymmetricBlockMatrix, expressions) TEST(SymmetricBlockMatrix, expressions)
{ {
SymmetricBlockMatrix expected1(list_of(2)(3)(1), (Matrix(6, 6) << const std::vector<size_t> dimensions{2, 3, 1};
SymmetricBlockMatrix expected1(dimensions, (Matrix(6, 6) <<
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 4, 6, 8, 0, 0, 0, 4, 6, 8, 0,
@ -109,7 +108,7 @@ TEST(SymmetricBlockMatrix, expressions)
0, 0, 0, 0, 16, 0, 0, 0, 0, 0, 16, 0,
0, 0, 0, 0, 0, 0).finished()); 0, 0, 0, 0, 0, 0).finished());
SymmetricBlockMatrix expected2(list_of(2)(3)(1), (Matrix(6, 6) << SymmetricBlockMatrix expected2(dimensions, (Matrix(6, 6) <<
0, 0, 10, 15, 20, 0, 0, 0, 10, 15, 20, 0,
0, 0, 12, 18, 24, 0, 0, 0, 12, 18, 24, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@ -120,32 +119,32 @@ TEST(SymmetricBlockMatrix, expressions)
Matrix a = (Matrix(1, 3) << 2, 3, 4).finished(); Matrix a = (Matrix(1, 3) << 2, 3, 4).finished();
Matrix b = (Matrix(1, 2) << 5, 6).finished(); Matrix b = (Matrix(1, 2) << 5, 6).finished();
SymmetricBlockMatrix bm1(list_of(2)(3)(1)); SymmetricBlockMatrix bm1(dimensions);
bm1.setZero(); bm1.setZero();
bm1.diagonalBlock(1).rankUpdate(a.transpose()); bm1.diagonalBlock(1).rankUpdate(a.transpose());
EXPECT(assert_equal(Matrix(expected1.selfadjointView()), bm1.selfadjointView())); EXPECT(assert_equal(Matrix(expected1.selfadjointView()), bm1.selfadjointView()));
SymmetricBlockMatrix bm2(list_of(2)(3)(1)); SymmetricBlockMatrix bm2(dimensions);
bm2.setZero(); bm2.setZero();
bm2.updateOffDiagonalBlock(0, 1, b.transpose() * a); bm2.updateOffDiagonalBlock(0, 1, b.transpose() * a);
EXPECT(assert_equal(Matrix(expected2.selfadjointView()), bm2.selfadjointView())); EXPECT(assert_equal(Matrix(expected2.selfadjointView()), bm2.selfadjointView()));
SymmetricBlockMatrix bm3(list_of(2)(3)(1)); SymmetricBlockMatrix bm3(dimensions);
bm3.setZero(); bm3.setZero();
bm3.updateOffDiagonalBlock(1, 0, a.transpose() * b); bm3.updateOffDiagonalBlock(1, 0, a.transpose() * b);
EXPECT(assert_equal(Matrix(expected2.selfadjointView()), bm3.selfadjointView())); EXPECT(assert_equal(Matrix(expected2.selfadjointView()), bm3.selfadjointView()));
SymmetricBlockMatrix bm4(list_of(2)(3)(1)); SymmetricBlockMatrix bm4(dimensions);
bm4.setZero(); bm4.setZero();
bm4.updateDiagonalBlock(1, expected1.diagonalBlock(1)); bm4.updateDiagonalBlock(1, expected1.diagonalBlock(1));
EXPECT(assert_equal(Matrix(expected1.selfadjointView()), bm4.selfadjointView())); EXPECT(assert_equal(Matrix(expected1.selfadjointView()), bm4.selfadjointView()));
SymmetricBlockMatrix bm5(list_of(2)(3)(1)); SymmetricBlockMatrix bm5(dimensions);
bm5.setZero(); bm5.setZero();
bm5.updateOffDiagonalBlock(0, 1, expected2.aboveDiagonalBlock(0, 1)); bm5.updateOffDiagonalBlock(0, 1, expected2.aboveDiagonalBlock(0, 1));
EXPECT(assert_equal(Matrix(expected2.selfadjointView()), bm5.selfadjointView())); EXPECT(assert_equal(Matrix(expected2.selfadjointView()), bm5.selfadjointView()));
SymmetricBlockMatrix bm6(list_of(2)(3)(1)); SymmetricBlockMatrix bm6(dimensions);
bm6.setZero(); bm6.setZero();
bm6.updateOffDiagonalBlock(1, 0, expected2.aboveDiagonalBlock(0, 1).transpose()); bm6.updateOffDiagonalBlock(1, 0, expected2.aboveDiagonalBlock(0, 1).transpose());
EXPECT(assert_equal(Matrix(expected2.selfadjointView()), bm6.selfadjointView())); EXPECT(assert_equal(Matrix(expected2.selfadjointView()), bm6.selfadjointView()));
@ -162,7 +161,8 @@ TEST(SymmetricBlockMatrix, inverseInPlace) {
inputMatrix += c * c.transpose(); inputMatrix += c * c.transpose();
const Matrix expectedInverse = inputMatrix.inverse(); const Matrix expectedInverse = inputMatrix.inverse();
SymmetricBlockMatrix symmMatrix(list_of(2)(1), inputMatrix); const std::vector<size_t> dimensions{2, 1};
SymmetricBlockMatrix symmMatrix(dimensions, inputMatrix);
// invert in place // invert in place
symmMatrix.invertInPlace(); symmMatrix.invertInPlace();
EXPECT(assert_equal(expectedInverse, symmMatrix.selfadjointView())); EXPECT(assert_equal(expectedInverse, symmMatrix.selfadjointView()));

View File

@ -23,16 +23,13 @@
#include <list> #include <list>
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
#include <boost/make_shared.hpp> #include <boost/make_shared.hpp>
#include <boost/assign/std/list.hpp>
using boost::assign::operator+=;
using namespace std;
using namespace gtsam; using namespace gtsam;
struct TestNode { struct TestNode {
typedef boost::shared_ptr<TestNode> shared_ptr; typedef boost::shared_ptr<TestNode> shared_ptr;
int data; int data;
vector<shared_ptr> children; std::vector<shared_ptr> children;
TestNode() : data(-1) {} TestNode() : data(-1) {}
TestNode(int data) : data(data) {} TestNode(int data) : data(data) {}
}; };
@ -110,10 +107,8 @@ TEST(treeTraversal, DepthFirst)
TestForest testForest = makeTestForest(); TestForest testForest = makeTestForest();
// Expected visit order // Expected visit order
std::list<int> preOrderExpected; const std::list<int> preOrderExpected{0, 2, 3, 4, 1};
preOrderExpected += 0, 2, 3, 4, 1; const std::list<int> postOrderExpected{2, 4, 3, 0, 1};
std::list<int> postOrderExpected;
postOrderExpected += 2, 4, 3, 0, 1;
// Actual visit order // Actual visit order
PreOrderVisitor preVisitor; PreOrderVisitor preVisitor;
@ -135,8 +130,7 @@ TEST(treeTraversal, CloneForest)
testForest2.roots_ = treeTraversal::CloneForest(testForest1); testForest2.roots_ = treeTraversal::CloneForest(testForest1);
// Check that the original and clone both are expected // Check that the original and clone both are expected
std::list<int> preOrder1Expected; const std::list<int> preOrder1Expected{0, 2, 3, 4, 1};
preOrder1Expected += 0, 2, 3, 4, 1;
std::list<int> preOrder1Actual = getPreorder(testForest1); std::list<int> preOrder1Actual = getPreorder(testForest1);
std::list<int> preOrder2Actual = getPreorder(testForest2); std::list<int> preOrder2Actual = getPreorder(testForest2);
EXPECT(assert_container_equality(preOrder1Expected, preOrder1Actual)); EXPECT(assert_container_equality(preOrder1Expected, preOrder1Actual));
@ -144,8 +138,7 @@ TEST(treeTraversal, CloneForest)
// Modify clone - should not modify original // Modify clone - should not modify original
testForest2.roots_[0]->children[1]->data = 10; testForest2.roots_[0]->children[1]->data = 10;
std::list<int> preOrderModifiedExpected; const std::list<int> preOrderModifiedExpected{0, 2, 10, 4, 1};
preOrderModifiedExpected += 0, 2, 10, 4, 1;
// Check that original is the same and only the clone is modified // Check that original is the same and only the clone is modified
std::list<int> preOrder1ModActual = getPreorder(testForest1); std::list<int> preOrder1ModActual = getPreorder(testForest1);

View File

@ -18,14 +18,14 @@
#include <CppUnitLite/TestHarness.h> #include <CppUnitLite/TestHarness.h>
#include <gtsam/base/VerticalBlockMatrix.h> #include <gtsam/base/VerticalBlockMatrix.h>
#include <boost/assign/list_of.hpp>
using namespace std; #include<list>
#include<vector>
using namespace gtsam; using namespace gtsam;
using boost::assign::list_of;
list<size_t> L = list_of(3)(2)(1); const std::list<size_t> L{3, 2, 1};
vector<size_t> dimensions(L.begin(),L.end()); const std::vector<size_t> dimensions(L.begin(), L.end());
//***************************************************************************** //*****************************************************************************
TEST(VerticalBlockMatrix, Constructor1) { TEST(VerticalBlockMatrix, Constructor1) {

View File

@ -399,13 +399,9 @@ TEST(ADT, factor_graph) {
/* ************************************************************************* */ /* ************************************************************************* */
// test equality // test equality
TEST(ADT, equality_noparser) { TEST(ADT, equality_noparser) {
DiscreteKey A(0, 2), B(1, 2); const DiscreteKey A(0, 2), B(1, 2);
Signature::Table tableA, tableB; const Signature::Row rA{80, 20}, rB{60, 40};
Signature::Row rA, rB; const Signature::Table tableA{rA}, tableB{rB};
rA += 80, 20;
rB += 60, 40;
tableA += rA;
tableB += rB;
// Check straight equality // Check straight equality
ADT pA1 = create(A % tableA); ADT pA1 = create(A % tableA);
@ -520,9 +516,9 @@ TEST(ADT, elimination) {
// normalize // normalize
ADT actual = f1 / actualSum; ADT actual = f1 / actualSum;
vector<double> cpt; const vector<double> cpt{
cpt += 1.0 / 3, 2.0 / 3, 3.0 / 7, 4.0 / 7, 5.0 / 11, 6.0 / 11, // 1.0 / 3, 2.0 / 3, 3.0 / 7, 4.0 / 7, 5.0 / 11, 6.0 / 11, //
1.0 / 9, 8.0 / 9, 3.0 / 6, 3.0 / 6, 5.0 / 10, 5.0 / 10; 1.0 / 9, 8.0 / 9, 3.0 / 6, 3.0 / 6, 5.0 / 10, 5.0 / 10};
ADT expected(A & B & C, cpt); ADT expected(A & B & C, cpt);
CHECK(assert_equal(expected, actual)); CHECK(assert_equal(expected, actual));
} }
@ -535,9 +531,9 @@ TEST(ADT, elimination) {
// normalize // normalize
ADT actual = f1 / actualSum; ADT actual = f1 / actualSum;
vector<double> cpt; const vector<double> cpt{
cpt += 1.0 / 21, 2.0 / 21, 3.0 / 21, 4.0 / 21, 5.0 / 21, 6.0 / 21, // 1.0 / 21, 2.0 / 21, 3.0 / 21, 4.0 / 21, 5.0 / 21, 6.0 / 21, //
1.0 / 25, 8.0 / 25, 3.0 / 25, 3.0 / 25, 5.0 / 25, 5.0 / 25; 1.0 / 25, 8.0 / 25, 3.0 / 25, 3.0 / 25, 5.0 / 25, 5.0 / 25};
ADT expected(A & B & C, cpt); ADT expected(A & B & C, cpt);
CHECK(assert_equal(expected, actual)); CHECK(assert_equal(expected, actual));
} }

View File

@ -26,7 +26,9 @@
#include <gtsam/discrete/DecisionTree-inl.h> #include <gtsam/discrete/DecisionTree-inl.h>
#include <gtsam/discrete/Signature.h> #include <gtsam/discrete/Signature.h>
using namespace std; using std::vector;
using std::string;
using std::map;
using namespace gtsam; using namespace gtsam;
template <typename T> template <typename T>
@ -280,8 +282,7 @@ TEST(DecisionTree, Compose) {
DT f1(B, DT(A, 0, 1), DT(A, 2, 3)); DT f1(B, DT(A, 0, 1), DT(A, 2, 3));
// Create from string // Create from string
vector<DT::LabelC> keys; vector<DT::LabelC> keys{DT::LabelC(A, 2), DT::LabelC(B, 2)};
keys += DT::LabelC(A, 2), DT::LabelC(B, 2);
DT f2(keys, "0 2 1 3"); DT f2(keys, "0 2 1 3");
EXPECT(assert_equal(f2, f1, 1e-9)); EXPECT(assert_equal(f2, f1, 1e-9));
@ -291,7 +292,7 @@ TEST(DecisionTree, Compose) {
DOT(f4); DOT(f4);
// a bigger tree // a bigger tree
keys += DT::LabelC(C, 2); keys.push_back(DT::LabelC(C, 2));
DT f5(keys, "0 4 2 6 1 5 3 7"); DT f5(keys, "0 4 2 6 1 5 3 7");
EXPECT(assert_equal(f5, f4, 1e-9)); EXPECT(assert_equal(f5, f4, 1e-9));
DOT(f5); DOT(f5);
@ -322,7 +323,7 @@ TEST(DecisionTree, Containers) {
/* ************************************************************************** */ /* ************************************************************************** */
// Test nrAssignments. // Test nrAssignments.
TEST(DecisionTree, NrAssignments) { TEST(DecisionTree, NrAssignments) {
pair<string, size_t> A("A", 2), B("B", 2), C("C", 2); const std::pair<string, size_t> A("A", 2), B("B", 2), C("C", 2);
DT tree({A, B, C}, "1 1 1 1 1 1 1 1"); DT tree({A, B, C}, "1 1 1 1 1 1 1 1");
EXPECT(tree.root_->isLeaf()); EXPECT(tree.root_->isLeaf());
auto leaf = boost::dynamic_pointer_cast<const DT::Leaf>(tree.root_); auto leaf = boost::dynamic_pointer_cast<const DT::Leaf>(tree.root_);
@ -472,8 +473,8 @@ TEST(DecisionTree, unzip) {
// Test thresholding. // Test thresholding.
TEST(DecisionTree, threshold) { TEST(DecisionTree, threshold) {
// Create three level tree // Create three level tree
vector<DT::LabelC> keys; const vector<DT::LabelC> keys{DT::LabelC("C", 2), DT::LabelC("B", 2),
keys += DT::LabelC("C", 2), DT::LabelC("B", 2), DT::LabelC("A", 2); DT::LabelC("A", 2)};
DT tree(keys, "0 1 2 3 4 5 6 7"); DT tree(keys, "0 1 2 3 4 5 6 7");
// Check number of leaves equal to zero // Check number of leaves equal to zero
@ -495,8 +496,8 @@ TEST(DecisionTree, threshold) {
// Test apply with assignment. // Test apply with assignment.
TEST(DecisionTree, ApplyWithAssignment) { TEST(DecisionTree, ApplyWithAssignment) {
// Create three level tree // Create three level tree
vector<DT::LabelC> keys; const vector<DT::LabelC> keys{DT::LabelC("C", 2), DT::LabelC("B", 2),
keys += DT::LabelC("C", 2), DT::LabelC("B", 2), DT::LabelC("A", 2); DT::LabelC("A", 2)};
DT tree(keys, "1 2 3 4 5 6 7 8"); DT tree(keys, "1 2 3 4 5 6 7 8");
DecisionTree<string, double> probTree( DecisionTree<string, double> probTree(

View File

@ -53,12 +53,8 @@ TEST(DiscreteConditional, constructors) {
TEST(DiscreteConditional, constructors_alt_interface) { TEST(DiscreteConditional, constructors_alt_interface) {
DiscreteKey X(0, 2), Y(2, 3), Z(1, 2); // watch ordering ! DiscreteKey X(0, 2), Y(2, 3), Z(1, 2); // watch ordering !
Signature::Table table; const Signature::Row r1{1, 1}, r2{2, 3}, r3{1, 4};
Signature::Row r1, r2, r3; const Signature::Table table{r1, r2, r3};
r1 += 1.0, 1.0;
r2 += 2.0, 3.0;
r3 += 1.0, 4.0;
table += r1, r2, r3;
DiscreteConditional actual1(X, {Y}, table); DiscreteConditional actual1(X, {Y}, table);
DecisionTreeFactor f1(X & Y, "0.5 0.4 0.2 0.5 0.6 0.8"); DecisionTreeFactor f1(X & Y, "0.5 0.4 0.2 0.5 0.6 0.8");

View File

@ -183,8 +183,7 @@ TEST_UNSAFE(DiscreteMarginals, truss2) {
F[j] /= sum; F[j] /= sum;
// Marginals // Marginals
vector<double> table; const vector<double> table{F[j], T[j]};
table += F[j], T[j];
DecisionTreeFactor expectedM(key[j], table); DecisionTreeFactor expectedM(key[j], table);
DiscreteFactor::shared_ptr actualM = marginals(j); DiscreteFactor::shared_ptr actualM = marginals(j);
EXPECT(assert_equal( EXPECT(assert_equal(

View File

@ -20,12 +20,9 @@
#include <gtsam/geometry/OrientedPlane3.h> #include <gtsam/geometry/OrientedPlane3.h>
#include <gtsam/base/numericalDerivative.h> #include <gtsam/base/numericalDerivative.h>
#include <CppUnitLite/TestHarness.h> #include <CppUnitLite/TestHarness.h>
#include <boost/assign/std/vector.hpp>
using namespace boost::assign;
using namespace std::placeholders; using namespace std::placeholders;
using namespace gtsam; using namespace gtsam;
using namespace std;
using boost::none; using boost::none;
GTSAM_CONCEPT_TESTABLE_INST(OrientedPlane3) GTSAM_CONCEPT_TESTABLE_INST(OrientedPlane3)

View File

@ -23,12 +23,10 @@
#include <gtsam/geometry/Pose2.h> #include <gtsam/geometry/Pose2.h>
#include <gtsam/geometry/Rot2.h> #include <gtsam/geometry/Rot2.h>
#include <boost/assign/std/vector.hpp> // for operator +=
#include <boost/optional.hpp> #include <boost/optional.hpp>
#include <cmath> #include <cmath>
#include <iostream> #include <iostream>
using namespace boost::assign;
using namespace gtsam; using namespace gtsam;
using namespace std; using namespace std;
@ -749,11 +747,10 @@ namespace align_3 {
TEST(Pose2, align_3) { TEST(Pose2, align_3) {
using namespace align_3; using namespace align_3;
Point2Pairs ab_pairs;
Point2Pair ab1(make_pair(a1, b1)); Point2Pair ab1(make_pair(a1, b1));
Point2Pair ab2(make_pair(a2, b2)); Point2Pair ab2(make_pair(a2, b2));
Point2Pair ab3(make_pair(a3, b3)); Point2Pair ab3(make_pair(a3, b3));
ab_pairs += ab1, ab2, ab3; const Point2Pairs ab_pairs{ab1, ab2, ab3};
boost::optional<Pose2> aTb = Pose2::Align(ab_pairs); boost::optional<Pose2> aTb = Pose2::Align(ab_pairs);
EXPECT(assert_equal(expected, *aTb)); EXPECT(assert_equal(expected, *aTb));
@ -778,9 +775,7 @@ namespace {
TEST(Pose2, align_4) { TEST(Pose2, align_4) {
using namespace align_3; using namespace align_3;
Point2Vector as, bs; Point2Vector as{a1, a2, a3}, bs{b3, b1, b2}; // note in 3,1,2 order !
as += a1, a2, a3;
bs += b3, b1, b2; // note in 3,1,2 order !
Triangle t1; t1.i_=0; t1.j_=1; t1.k_=2; Triangle t1; t1.i_=0; t1.j_=1; t1.k_=2;
Triangle t2; t2.i_=1; t2.j_=2; t2.k_=0; Triangle t2; t2.i_=1; t2.j_=2; t2.k_=0;

View File

@ -20,15 +20,13 @@
#include <gtsam/base/lieProxies.h> #include <gtsam/base/lieProxies.h>
#include <gtsam/base/TestableAssertions.h> #include <gtsam/base/TestableAssertions.h>
#include <boost/assign/std/vector.hpp> // for operator +=
using namespace boost::assign;
using namespace std::placeholders;
#include <CppUnitLite/TestHarness.h> #include <CppUnitLite/TestHarness.h>
#include <cmath> #include <cmath>
using namespace std; using namespace std;
using namespace gtsam; using namespace gtsam;
using namespace std::placeholders;
GTSAM_CONCEPT_TESTABLE_INST(Pose3) GTSAM_CONCEPT_TESTABLE_INST(Pose3)
GTSAM_CONCEPT_LIE_INST(Pose3) GTSAM_CONCEPT_LIE_INST(Pose3)
@ -809,11 +807,10 @@ TEST( Pose3, adjointMap) {
TEST(Pose3, Align1) { TEST(Pose3, Align1) {
Pose3 expected(Rot3(), Point3(10,10,0)); Pose3 expected(Rot3(), Point3(10,10,0));
vector<Point3Pair> correspondences; Point3Pair ab1(Point3(10,10,0), Point3(0,0,0));
Point3Pair ab1(make_pair(Point3(10,10,0), Point3(0,0,0))); Point3Pair ab2(Point3(30,20,0), Point3(20,10,0));
Point3Pair ab2(make_pair(Point3(30,20,0), Point3(20,10,0))); Point3Pair ab3(Point3(20,30,0), Point3(10,20,0));
Point3Pair ab3(make_pair(Point3(20,30,0), Point3(10,20,0))); const vector<Point3Pair> correspondences{ab1, ab2, ab3};
correspondences += ab1, ab2, ab3;
boost::optional<Pose3> actual = Pose3::Align(correspondences); boost::optional<Pose3> actual = Pose3::Align(correspondences);
EXPECT(assert_equal(expected, *actual)); EXPECT(assert_equal(expected, *actual));
@ -825,15 +822,12 @@ TEST(Pose3, Align2) {
Rot3 R = Rot3::RzRyRx(0.3, 0.2, 0.1); Rot3 R = Rot3::RzRyRx(0.3, 0.2, 0.1);
Pose3 expected(R, t); Pose3 expected(R, t);
vector<Point3Pair> correspondences;
Point3 p1(0,0,1), p2(10,0,2), p3(20,-10,30); Point3 p1(0,0,1), p2(10,0,2), p3(20,-10,30);
Point3 q1 = expected.transformFrom(p1), Point3 q1 = expected.transformFrom(p1),
q2 = expected.transformFrom(p2), q2 = expected.transformFrom(p2),
q3 = expected.transformFrom(p3); q3 = expected.transformFrom(p3);
Point3Pair ab1(make_pair(q1, p1)); const Point3Pair ab1{q1, p1}, ab2{q2, p2}, ab3{q3, p3};
Point3Pair ab2(make_pair(q2, p2)); const vector<Point3Pair> correspondences{ab1, ab2, ab3};
Point3Pair ab3(make_pair(q3, p3));
correspondences += ab1, ab2, ab3;
boost::optional<Pose3> actual = Pose3::Align(correspondences); boost::optional<Pose3> actual = Pose3::Align(correspondences);
EXPECT(assert_equal(expected, *actual, 1e-5)); EXPECT(assert_equal(expected, *actual, 1e-5));

View File

@ -36,7 +36,6 @@
#include <cmath> #include <cmath>
#include <random> #include <random>
using namespace boost::assign;
using namespace std::placeholders; using namespace std::placeholders;
using namespace gtsam; using namespace gtsam;
using namespace std; using namespace std;
@ -51,9 +50,8 @@ Point3 point3_(const Unit3& p) {
} }
TEST(Unit3, point3) { TEST(Unit3, point3) {
vector<Point3> ps; const vector<Point3> ps{Point3(1, 0, 0), Point3(0, 1, 0), Point3(0, 0, 1),
ps += Point3(1, 0, 0), Point3(0, 1, 0), Point3(0, 0, 1), Point3(1, 1, 0) Point3(1, 1, 0) / sqrt(2.0)};
/ sqrt(2.0);
Matrix actualH, expectedH; Matrix actualH, expectedH;
for(Point3 p: ps) { for(Point3 p: ps) {
Unit3 s(p); Unit3 s(p);

View File

@ -42,17 +42,11 @@
#include <CppUnitLite/TestHarness.h> #include <CppUnitLite/TestHarness.h>
#include <boost/shared_ptr.hpp>
#include <boost/tuple/tuple.hpp>
#include <boost/assign/std/vector.hpp>
#include <cmath> #include <cmath>
#include <list> #include <list>
#include <utility> #include <utility>
#include <vector> #include <vector>
using namespace boost::assign;
#include <iostream> #include <iostream>
using namespace std; using namespace std;
@ -79,8 +73,7 @@ TEST( GaussianJunctionTreeB, constructor2 ) {
// linearize // linearize
GaussianFactorGraph::shared_ptr fg = nlfg.linearize(values); GaussianFactorGraph::shared_ptr fg = nlfg.linearize(values);
Ordering ordering; const Ordering ordering {X(1), X(3), X(5), X(7), X(2), X(6), X(4)};
ordering += X(1), X(3), X(5), X(7), X(2), X(6), X(4);
// create an ordering // create an ordering
GaussianEliminationTree etree(*fg, ordering); GaussianEliminationTree etree(*fg, ordering);