testCyclic.cpp
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2 
3  * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4  * Atlanta, Georgia 30332-0415
5  * All Rights Reserved
6  * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7 
8  * See LICENSE for the license information
9 
10  * -------------------------------------------------------------------------- */
11 
18 #include <gtsam/geometry/Cyclic.h>
19 #include <gtsam/base/Testable.h>
21 
22 using namespace std;
23 using namespace gtsam;
24 
25 typedef Cyclic<3> Z3; // Let's use the cyclic group of order 3
26 typedef Cyclic<2> Z2;
27 
28 //******************************************************************************
29 TEST(Cyclic, Concept) {
32 }
33 
34 //******************************************************************************
35 TEST(Cyclic, Constructor) {
36  Z3 g(0);
37 }
38 
39 //******************************************************************************
40 TEST(Cyclic, Compose) {
44 
48 }
49 
50 //******************************************************************************
55 
59 }
60 
61 //******************************************************************************
66 }
67 
68 //******************************************************************************
69 TEST(Cyclic, Negation) {
70  EXPECT_LONGS_EQUAL(0, -Z3(0));
71  EXPECT_LONGS_EQUAL(2, -Z3(1));
72  EXPECT_LONGS_EQUAL(1, -Z3(2));
73 }
74 
75 //******************************************************************************
76 TEST(Cyclic, Negation2) {
77  EXPECT_LONGS_EQUAL(0, -Z2(0));
78  EXPECT_LONGS_EQUAL(1, -Z2(1));
79 }
80 
81 //******************************************************************************
82 TEST(Cyclic , Invariants) {
83  Z3 g(2), h(1);
84  EXPECT(check_group_invariants(g,h));
85 }
86 
87 //******************************************************************************
88 // The Direct sum of Z2 and Z2 is *not* Cyclic<4>, but the
89 // smallest non-cyclic group called the Klein four-group:
91 
92 namespace gtsam {
93 
95 template<>
96 struct traits<K4> : internal::AdditiveGroupTraits<K4> {
97  static void Print(const K4& m, const string& s = "") {
98  cout << s << "(" << m.first << "," << m.second << ")" << endl;
99  }
100  static bool Equals(const K4& m1, const K4& m2, double tol = 1e-8) {
101  return m1 == m2;
102  }
103 };
104 
105 } // namespace gtsam
106 
108  // The Direct sum of Z2 and Z2 is *not* Cyclic<4>, but the
109  // smallest non-cyclic group called the Klein four-group:
112 
113  // Refer to http://en.wikipedia.org/wiki/Klein_four-group
114  K4 e(0,0), a(0, 1), b(1, 0), c(1, 1);
115  EXPECT(assert_equal(a, - a));
116  EXPECT(assert_equal(b, - b));
117  EXPECT(assert_equal(c, - c));
118  EXPECT(assert_equal(a, a + e));
119  EXPECT(assert_equal(b, b + e));
120  EXPECT(assert_equal(c, c + e));
121  EXPECT(assert_equal(e, a + a));
122  EXPECT(assert_equal(e, b + b));
123  EXPECT(assert_equal(e, c + c));
124  EXPECT(assert_equal(c, a + b));
125  EXPECT(assert_equal(b, a + c));
126  EXPECT(assert_equal(a, b + c));
127  EXPECT(assert_equal(c, a - b));
128  EXPECT(assert_equal(a, b - c));
129  EXPECT(assert_equal(b, c - a));
130  EXPECT(check_group_invariants(a, b));
131  EXPECT(check_group_invariants(b, c));
132  EXPECT(check_group_invariants(c, a));
133 }
134 
135 //******************************************************************************
136 int main() {
137  TestResult tr;
138  return TestRegistry::runAllTests(tr);
139 }
140 //******************************************************************************
141 
Matrix3f m
#define GTSAM_CONCEPT_ASSERT(concept)
Definition: base/concepts.h:22
Scalar * b
Definition: benchVecAdd.cpp:17
Concept check for values that can be used in unit tests.
static int runAllTests(TestResult &result)
Cyclic< 2 > Z2
Definition: testCyclic.cpp:26
MatrixType m2(n_dims)
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
Definition: Matrix.cpp:40
Scalar Scalar * c
Definition: benchVecAdd.cpp:17
Definition: BFloat16.h:88
static bool Equals(const K4 &m1, const K4 &m2, double tol=1e-8)
Definition: testCyclic.cpp:100
void g(const string &key, int i)
Definition: testBTree.cpp:41
Cyclic group of order N.
Definition: Cyclic.h:30
Matrix3d m1
Definition: IOFormat.cpp:2
Cyclic< 3 > Z3
Definition: testCyclic.cpp:25
#define EXPECT(condition)
Definition: Test.h:150
static void Print(const K4 &m, const string &s="")
Definition: testCyclic.cpp:97
Array< double, 1, 3 > e(1./3., 0.5, 2.)
RealScalar s
traits
Definition: chartTesting.h:28
DirectSum< Z2, Z2 > K4
Definition: testCyclic.cpp:90
const double h
#define EXPECT_LONGS_EQUAL(expected, actual)
Definition: Test.h:154
TEST(Cyclic, Concept)
Definition: testCyclic.cpp:29
int main()
Definition: testCyclic.cpp:136
const G double tol
Definition: Group.h:86
Cyclic group, i.e., the integers modulo N.


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:37:59