diff --git a/gtsam/base/tests/testGroup.cpp b/gtsam/base/tests/testGroup.cpp new file mode 100644 index 000000000..2cee30070 --- /dev/null +++ b/gtsam/base/tests/testGroup.cpp @@ -0,0 +1,78 @@ +/* ---------------------------------------------------------------------------- + + * GTSAM Copyright 2010, Georgia Tech Research Corporation, + * Atlanta, Georgia 30332-0415 + * All Rights Reserved + * Authors: Frank Dellaert, et al. (see THANKS for the full author list) + + * See LICENSE for the license information + + * -------------------------------------------------------------------------- */ + +/** + * @file testGroup.cpp + * @brief Unit tests for groups + * @author Frank Dellaert + **/ + +#include +#include +#include + +namespace gtsam { + +template +class Permutation: public Eigen::PermutationMatrix { +public: + Permutation() { + Eigen::PermutationMatrix::setIdentity(); + } + Permutation(const Eigen::PermutationMatrix& P) : + Eigen::PermutationMatrix(P) { + } + Permutation inverse() const { + return Eigen::PermutationMatrix(Eigen::PermutationMatrix::inverse()); + } +}; + +/// Define permutation group traits to be a model of the Multiplicative Group concept +template +struct traits > : internal::MultiplicativeGroupTraits< + Permutation > { + static void Print(const Permutation& m, const std::string& str = "") { + std::cout << m << std::endl; + } + static bool Equals(const Permutation& m1, const Permutation& m2, + double tol = 1e-8) { + return m1.indices() == m2.indices(); + } +}; + +} // namespace gtsam + +#include +#include + +using namespace std; +using namespace gtsam; + +typedef Permutation<3> G; // Let's use the permutation group of order 3 + +//****************************************************************************** +TEST(Group, Concept) { + BOOST_CONCEPT_ASSERT((IsGroup)); +} + +//****************************************************************************** +TEST(Group , Invariants) { + G g, h; + EXPECT(check_group_invariants(g, h)); +} + +//****************************************************************************** +int main() { + TestResult tr; + return TestRegistry::runAllTests(tr); +} +//****************************************************************************** +