gtsam
geometry
tests
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
>
20
#include <
CppUnitLite/TestHarness.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) {
30
GTSAM_CONCEPT_ASSERT
(
IsGroup<Z3>
);
31
EXPECT_LONGS_EQUAL
(0,
traits<Z3>::Identity
());
32
}
33
34
//******************************************************************************
35
TEST
(
Cyclic
, Constructor) {
36
Z3
g
(0);
37
}
38
39
//******************************************************************************
40
TEST
(
Cyclic
, Compose) {
41
EXPECT_LONGS_EQUAL
(0,
traits<Z3>::Compose
(
Z3
(0),
Z3
(0)));
42
EXPECT_LONGS_EQUAL
(1,
traits<Z3>::Compose
(
Z3
(0),
Z3
(1)));
43
EXPECT_LONGS_EQUAL
(2,
traits<Z3>::Compose
(
Z3
(0),
Z3
(2)));
44
45
EXPECT_LONGS_EQUAL
(2,
traits<Z3>::Compose
(
Z3
(2),
Z3
(0)));
46
EXPECT_LONGS_EQUAL
(0,
traits<Z3>::Compose
(
Z3
(2),
Z3
(1)));
47
EXPECT_LONGS_EQUAL
(1,
traits<Z3>::Compose
(
Z3
(2),
Z3
(2)));
48
}
49
50
//******************************************************************************
51
TEST
(
Cyclic
,
Between
) {
52
EXPECT_LONGS_EQUAL
(0,
traits<Z3>::Between
(
Z3
(0),
Z3
(0)));
53
EXPECT_LONGS_EQUAL
(1,
traits<Z3>::Between
(
Z3
(0),
Z3
(1)));
54
EXPECT_LONGS_EQUAL
(2,
traits<Z3>::Between
(
Z3
(0),
Z3
(2)));
55
56
EXPECT_LONGS_EQUAL
(1,
traits<Z3>::Between
(
Z3
(2),
Z3
(0)));
57
EXPECT_LONGS_EQUAL
(2,
traits<Z3>::Between
(
Z3
(2),
Z3
(1)));
58
EXPECT_LONGS_EQUAL
(0,
traits<Z3>::Between
(
Z3
(2),
Z3
(2)));
59
}
60
61
//******************************************************************************
62
TEST
(
Cyclic
,
Inverse
) {
63
EXPECT_LONGS_EQUAL
(0,
traits<Z3>::Inverse
(
Z3
(0)));
64
EXPECT_LONGS_EQUAL
(2,
traits<Z3>::Inverse
(
Z3
(1)));
65
EXPECT_LONGS_EQUAL
(1,
traits<Z3>::Inverse
(
Z3
(2)));
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:
90
typedef
DirectSum<Z2, Z2>
K4
;
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
= 1
e
-8) {
101
return
m1
==
m2
;
102
}
103
};
104
105
}
// namespace gtsam
106
107
TEST
(
Cyclic
,
DirectSum
) {
108
// The Direct sum of Z2 and Z2 is *not* Cyclic<4>, but the
109
// smallest non-cyclic group called the Klein four-group:
110
GTSAM_CONCEPT_ASSERT
(
IsGroup<K4>
);
111
GTSAM_CONCEPT_ASSERT
(
IsTestable<K4>
);
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
TestRegistry::runAllTests
static int runAllTests(TestResult &result)
Definition:
TestRegistry.cpp:27
gtsam::traits< K4 >::Print
static void Print(const K4 &m, const string &s="")
Definition:
testCyclic.cpp:97
s
RealScalar s
Definition:
level1_cplx_impl.h:126
e
Array< double, 1, 3 > e(1./3., 0.5, 2.)
EXPECT_LONGS_EQUAL
#define EXPECT_LONGS_EQUAL(expected, actual)
Definition:
Test.h:154
Testable.h
Concept check for values that can be used in unit tests.
EXPECT
#define EXPECT(condition)
Definition:
Test.h:150
TestHarness.h
gtsam::Cyclic
Cyclic group of order N.
Definition:
Cyclic.h:30
c
Scalar Scalar * c
Definition:
benchVecAdd.cpp:17
b
Scalar * b
Definition:
benchVecAdd.cpp:17
Z2
Cyclic< 2 > Z2
Definition:
testCyclic.cpp:26
m1
Matrix3d m1
Definition:
IOFormat.cpp:2
Cyclic.h
Cyclic group, i.e., the integers modulo N.
h
const double h
Definition:
testSimpleHelicopter.cpp:19
gtsam::IsGroup
Definition:
Group.h:42
Z3
Cyclic< 3 > Z3
Definition:
testCyclic.cpp:25
m2
MatrixType m2(n_dims)
K4
DirectSum< Z2, Z2 > K4
Definition:
testCyclic.cpp:90
m
Matrix3f m
Definition:
AngleAxis_mimic_euler.cpp:1
g
void g(const string &key, int i)
Definition:
testBTree.cpp:41
TestResult
Definition:
TestResult.h:26
a
ArrayXXi a
Definition:
Array_initializer_list_23_cxx11.cpp:1
gtsam
traits
Definition:
SFMdata.h:40
main
int main()
Definition:
testCyclic.cpp:136
gtsam::traits
Definition:
Group.h:36
std
Definition:
BFloat16.h:88
gtsam::assert_equal
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
Definition:
Matrix.cpp:40
Inverse
Definition:
Inverse.java:13
gtsam::tol
const G double tol
Definition:
Group.h:79
TEST
TEST(Cyclic, Concept)
Definition:
testCyclic.cpp:29
gtsam::IsTestable
Definition:
Testable.h:59
GTSAM_CONCEPT_ASSERT
#define GTSAM_CONCEPT_ASSERT(concept)
Definition:
base/concepts.h:22
gtsam::traits< K4 >::Equals
static bool Equals(const K4 &m1, const K4 &m2, double tol=1e-8)
Definition:
testCyclic.cpp:100
gtsam::BetweenFactor
Definition:
BetweenFactor.h:40
gtsam::DirectSum
Definition:
Group.h:165
gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:07:19