From 6284312a5c7c50482a471801458399795c7f8129 Mon Sep 17 00:00:00 2001 From: Alex Cunningham Date: Mon, 24 Sep 2012 19:42:41 +0000 Subject: [PATCH] Added unit test for Fast* containers, added generic interface to convert from containers to KeySet --- gtsam.h | 2 ++ gtsam/base/FastSet.h | 6 +++++ gtsam/base/tests/testFastContainers.cpp | 34 +++++++++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 gtsam/base/tests/testFastContainers.cpp diff --git a/gtsam.h b/gtsam.h index 308ebdf7e..130c5260c 100644 --- a/gtsam.h +++ b/gtsam.h @@ -1517,6 +1517,8 @@ class KeyList { class KeySet { KeySet(); KeySet(const gtsam::KeySet& other); + KeySet(const gtsam::KeyVector& other); + KeySet(const gtsam::KeyList& other); // Testable void print(string s) const; diff --git a/gtsam/base/FastSet.h b/gtsam/base/FastSet.h index 123a8bb31..6076c7f03 100644 --- a/gtsam/base/FastSet.h +++ b/gtsam/base/FastSet.h @@ -61,6 +61,12 @@ public: Base(first, last) { } + /** Constructor from a iterable container, passes through to base class */ + template + explicit FastSet(const INPUTCONTAINER& container) : + Base(container.begin(), container.end()) { + } + /** Copy constructor from another FastSet */ FastSet(const FastSet& x) : Base(x) { diff --git a/gtsam/base/tests/testFastContainers.cpp b/gtsam/base/tests/testFastContainers.cpp new file mode 100644 index 000000000..b3e065921 --- /dev/null +++ b/gtsam/base/tests/testFastContainers.cpp @@ -0,0 +1,34 @@ +/** + * @file testFastContainers.cpp + * + * @brief Test for the Fast* containers that use boost pool allocators and interfaces + * + * @date Sep 24, 2012 + * @author Alex Cunningham + */ + +#include + +#include +#include + +#include +#include + +using namespace boost::assign; +using namespace gtsam; + +/* ************************************************************************* */ +TEST( testFastContainers, KeySet ) { + + FastVector init_vector; + init_vector += 2, 3, 4, 5; + + FastSet actSet(init_vector); + FastSet expSet; expSet += 2, 3, 4, 5; + EXPECT(actSet == expSet); +} + +/* ************************************************************************* */ +int main() { TestResult tr; return TestRegistry::runAllTests(tr); } +/* ************************************************************************* */