testLabeledSymbol.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 
12 /*
13  * @file testLabeledSymbol.cpp
14  * @author Alex Cunningham
15  */
16 
18 #include <gtsam/base/Testable.h>
20 
22 
23 using namespace std;
24 using namespace gtsam;
25 
26 /* ************************************************************************* */
27 TEST(LabeledSymbol, KeyLabeledSymbolConversion ) {
28  LabeledSymbol expected('x', 'A', 4);
29  Key key(expected);
30  LabeledSymbol actual(key);
31 
32  EXPECT(assert_equal(expected, actual))
33 }
34 
35 /* ************************************************************************* */
36 TEST(LabeledSymbol, KeyLabeledSymbolEncoding ) {
37 
38  // Test encoding of LabeledSymbol <-> size_t <-> string
39  // Encoding scheme:
40  // Top 8 bits: variable type (255 possible values) - zero will not process
41  // Next 8 high bits: variable type (255 possible values)
42  // TODO: use fewer bits for type - only 4 or 5 should be necessary - will need more decoding
43 
44  if(sizeof(Key) == 8) {
45  LabeledSymbol symbol(0x78, 0x41, 5);
46  Key key = 0x7841000000000005;
47  string str = "xA5";
48 
49  EXPECT_LONGS_EQUAL((long)key, (long)(Key)symbol);
50  EXPECT_LONGS_EQUAL(5, symbol.index());
51  EXPECT_LONGS_EQUAL(0x78, symbol.chr());
52  EXPECT_LONGS_EQUAL(0x41, symbol.label());
55  } else if(sizeof(Key) == 4) {
56  LabeledSymbol symbol(0x78, 0x41, 5);
57  Key key = 0x78410005;
58  string str = "xA5";
59 
60  EXPECT_LONGS_EQUAL((long)key, (long)(Key) symbol);
61  EXPECT_LONGS_EQUAL(5, symbol.index());
62  EXPECT_LONGS_EQUAL(0x78, symbol.chr());
63  EXPECT_LONGS_EQUAL(0x41, symbol.label());
66  }
67 }
68 
69 /* ************************************************************************* */
70 TEST(LabeledSymbol, ChrTest) {
71  Key key = LabeledSymbol('c','A',3);
72  EXPECT(LabeledSymbol::TypeTest('c')(key));
73  EXPECT(!LabeledSymbol::TypeTest('d')(key));
74  EXPECT(LabeledSymbol::LabelTest('A')(key));
75  EXPECT(!LabeledSymbol::LabelTest('D')(key));
76  EXPECT(LabeledSymbol::TypeLabelTest('c','A')(key));
77  EXPECT(!LabeledSymbol::TypeLabelTest('c','D')(key));
78 }
79 
80 /* ************************************************************************* */
81 // A custom (nonsensical) formatter.
83  return "special";
84 }
85 
86 TEST(LabeledSymbol, Formatting) {
87  LabeledSymbol symbol('c', 'A', 3);
88 
89  // use key_formatter with a function pointer
90  stringstream ss2;
92  EXPECT("special" == ss2.str());
93 
94  // use key_formatter with a function object.
95  stringstream ss3;
97  EXPECT("cA3" == ss3.str());
98 }
99 
100 /* ************************************************************************* */
101 int main() {
102  TestResult tr;
103  return TestRegistry::runAllTests(tr);
104 }
105 /* ************************************************************************* */
106 
TestRegistry::runAllTests
static int runAllTests(TestResult &result)
Definition: TestRegistry.cpp:27
TEST
TEST(LabeledSymbol, KeyLabeledSymbolConversion)
Definition: testLabeledSymbol.cpp:27
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::LabeledSymbol
Definition: LabeledSymbol.h:37
TestableAssertions.h
Provides additional testing facilities for common data structures.
gtsam::MultiRobotKeyFormatter
static const gtsam::KeyFormatter MultiRobotKeyFormatter
Definition: Key.h:60
cholesky::expected
Matrix expected
Definition: testMatrix.cpp:971
gtsam::symbol
Key symbol(unsigned char c, std::uint64_t j)
Definition: inference/Symbol.h:139
LabeledSymbol.h
labeledSymbolMyFormatter
string labeledSymbolMyFormatter(Key key)
Definition: testLabeledSymbol.cpp:82
TestResult
Definition: TestResult.h:26
str
Definition: pytypes.h:1558
key
const gtsam::Symbol key('X', 0)
gtsam
traits
Definition: SFMdata.h:40
std
Definition: BFloat16.h:88
gtsam::key_formatter
Definition: Key.h:78
gtsam::assert_equal
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
Definition: Matrix.cpp:41
gtsam::Key
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:97
main
int main()
Definition: testLabeledSymbol.cpp:101


gtsam
Author(s):
autogenerated on Sun Dec 22 2024 04:16:37