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 #include <boost/assign/std/list.hpp> // for operator +=
23 
24 using namespace boost::assign;
25 using namespace std;
26 using namespace gtsam;
27 
28 /* ************************************************************************* */
29 TEST(LabeledSymbol, KeyLabeledSymbolConversion ) {
30  LabeledSymbol expected('x', 'A', 4);
31  Key key(expected);
32  LabeledSymbol actual(key);
33 
34  EXPECT(assert_equal(expected, actual))
35 }
36 
37 /* ************************************************************************* */
38 TEST(LabeledSymbol, KeyLabeledSymbolEncoding ) {
39 
40  // Test encoding of LabeledSymbol <-> size_t <-> string
41  // Encoding scheme:
42  // Top 8 bits: variable type (255 possible values) - zero will not process
43  // Next 8 high bits: variable type (255 possible values)
44  // TODO: use fewer bits for type - only 4 or 5 should be necessary - will need more decoding
45 
46  if(sizeof(Key) == 8) {
47  LabeledSymbol symbol(0x78, 0x41, 5);
48  Key key = 0x7841000000000005;
49  string str = "xA5";
50 
51  EXPECT_LONGS_EQUAL((long)key, (long)(Key)symbol);
52  EXPECT_LONGS_EQUAL(5, symbol.index());
53  EXPECT_LONGS_EQUAL(0x78, symbol.chr());
54  EXPECT_LONGS_EQUAL(0x41, symbol.label());
56  EXPECT(assert_equal(symbol, LabeledSymbol(key)));
57  } else if(sizeof(Key) == 4) {
58  LabeledSymbol symbol(0x78, 0x41, 5);
59  Key key = 0x78410005;
60  string str = "xA5";
61 
62  EXPECT_LONGS_EQUAL((long)key, (long)(Key) symbol);
63  EXPECT_LONGS_EQUAL(5, symbol.index());
64  EXPECT_LONGS_EQUAL(0x78, symbol.chr());
65  EXPECT_LONGS_EQUAL(0x41, symbol.label());
67  EXPECT(assert_equal(symbol, LabeledSymbol(key)));
68  }
69 }
70 
71 /* ************************************************************************* */
72 TEST(LabeledSymbol, ChrTest) {
73  Key key = LabeledSymbol('c','A',3);
74  EXPECT(LabeledSymbol::TypeTest('c')(key));
75  EXPECT(!LabeledSymbol::TypeTest('d')(key));
76  EXPECT(LabeledSymbol::LabelTest('A')(key));
77  EXPECT(!LabeledSymbol::LabelTest('D')(key));
78  EXPECT(LabeledSymbol::TypeLabelTest('c','A')(key));
79  EXPECT(!LabeledSymbol::TypeLabelTest('c','D')(key));
80 }
81 
82 /* ************************************************************************* */
83 // A custom (nonsensical) formatter.
85  return "special";
86 }
87 
88 TEST(LabeledSymbol, Formatting) {
89  LabeledSymbol symbol('c', 'A', 3);
90 
91  // use key_formatter with a function pointer
92  stringstream ss2;
94  EXPECT("special" == ss2.str());
95 
96  // use key_formatter with a function object.
97  stringstream ss3;
99  EXPECT("cA3" == ss3.str());
100 }
101 
102 /* ************************************************************************* */
103 int main() {
104  TestResult tr;
105  return TestRegistry::runAllTests(tr);
106 }
107 /* ************************************************************************* */
108 
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:974
TEST(LabeledSymbol, KeyLabeledSymbolConversion)
Definition: Half.h:150
Definition: pytypes.h:928
#define EXPECT(condition)
Definition: Test.h:151
string labeledSymbolMyFormatter(Key key)
Key symbol(unsigned char c, std::uint64_t j)
traits
Definition: chartTesting.h:28
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
Definition: Matrix.cpp:42
#define EXPECT_LONGS_EQUAL(expected, actual)
Definition: Test.h:155
static const gtsam::KeyFormatter MultiRobotKeyFormatter
Definition: Key.h:54
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:61


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:47:43