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());
54  EXPECT(assert_equal(symbol, LabeledSymbol(key)));
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());
65  EXPECT(assert_equal(symbol, LabeledSymbol(key)));
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 
const gtsam::Symbol key('X', 0)
Provides additional testing facilities for common data structures.
int main()
Concept check for values that can be used in unit tests.
static int runAllTests(TestResult &result)
Matrix expected
Definition: testMatrix.cpp:971
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
Definition: Matrix.cpp:40
TEST(LabeledSymbol, KeyLabeledSymbolConversion)
Definition: BFloat16.h:88
Definition: pytypes.h:1403
#define EXPECT(condition)
Definition: Test.h:150
string labeledSymbolMyFormatter(Key key)
Key symbol(unsigned char c, std::uint64_t j)
traits
Definition: chartTesting.h:28
#define EXPECT_LONGS_EQUAL(expected, actual)
Definition: Test.h:154
static const gtsam::KeyFormatter MultiRobotKeyFormatter
Definition: Key.h:54
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:102


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:38:33