diff --git a/gtsam/base/concepts.h b/gtsam/base/concepts.h index d3f2fe87c..9011c759b 100644 --- a/gtsam/base/concepts.h +++ b/gtsam/base/concepts.h @@ -143,15 +143,19 @@ public: d = between(g, h); ig = inverse(g); test = operator_usage(g, h, flavor); -// test2 = equal(g, h); } - bool check_invariants(const G& a, const G& b) { - return (equal(compose(a, inverse(a)), e)) - && (equal(between(a, b), compose(inverse(a), b))) - && (equal(compose(a, between(a, b)), b)) - && operator_usage(a, b, flavor); - } +// TODO: these all require default constructors :-( +// Also, requires equal which is not required of a group +// Group():e(group::traits::identity::value) { +// } +// +// bool check_invariants(const G& a, const G& b) { +// return (equal(compose(a, inverse(a)), e)) +// && (equal(between(a, b), compose(inverse(a), b))) +// && (equal(compose(a, between(a, b)), b)) +// && operator_usage(a, b, flavor); +// } private: flavor_tag flavor; diff --git a/gtsam/geometry/tests/testCyclic.cpp b/gtsam/geometry/tests/testCyclic.cpp index 882d8fb1c..f46b85511 100644 --- a/gtsam/geometry/tests/testCyclic.cpp +++ b/gtsam/geometry/tests/testCyclic.cpp @@ -32,6 +32,10 @@ public: operator size_t() const { return i_; } + /// Addition modulo N + Cyclic operator+(const Cyclic& h) const { + return (i_+h.i_) % N; + } }; namespace traits { @@ -42,14 +46,21 @@ template struct structure_category > { } // \namespace traits namespace group { -template -Cyclic compose(const Cyclic&g, const Cyclic& h); template -Cyclic between(const Cyclic&g, const Cyclic& h); +Cyclic compose(const Cyclic&g, const Cyclic& h) { + return g + h; +} template -Cyclic inverse(const Cyclic&g); +Cyclic between(const Cyclic&g, const Cyclic& h) { + return h - g; +} + +template +Cyclic inverse(const Cyclic&g) { + return -g; +} namespace traits { /// Define the trait that specifies Cyclic's identity element @@ -100,8 +111,10 @@ typedef Cyclic<6> G; // Let's use the cyclic group of order 6 //****************************************************************************** TEST(Cyclic, Concept) { - EXPECT_LONGS_EQUAL(0, group::traits::identity::value); BOOST_CONCEPT_ASSERT((Group)); + EXPECT_LONGS_EQUAL(0, group::traits::identity::value); + G g(2), h(3); + // EXPECT(Group().check_invariants(g,h)) } //****************************************************************************** @@ -109,6 +122,22 @@ TEST(Cyclic, Constructor) { G g(0); } +//****************************************************************************** +TEST(Cyclic, Compose) { + G e(0), g(2), h(3); + EXPECT_LONGS_EQUAL(5, group::compose(g,h)); + EXPECT_LONGS_EQUAL(0, group::compose(h,h)); + EXPECT_LONGS_EQUAL(3, group::compose(h,e)); +} + +//****************************************************************************** +TEST(Cyclic, Between) { + G g(2), h(3); + EXPECT_LONGS_EQUAL(1, group::between(g,h)); + EXPECT_LONGS_EQUAL(0, group::between(g,g)); + EXPECT_LONGS_EQUAL(0, group::between(h,h)); +} + //****************************************************************************** int main() { TestResult tr;