testDiscreteValues.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  * testDiscreteValues.cpp
14  *
15  * @date Jan, 2022
16  * @author Frank Dellaert
17  */
18 
20 #include <gtsam/base/Testable.h>
23 
24 using namespace std;
25 using namespace gtsam;
26 
27 static const DiscreteValues kExample{{12, 1}, {5, 0}};
28 
29 /* ************************************************************************* */
30 // Check insert
31 TEST(DiscreteValues, Insert) {
32  EXPECT(assert_equal({{12, 1}, {5, 0}, {13, 2}},
33  DiscreteValues(kExample).insert({{13, 2}})));
34 }
35 
36 /* ************************************************************************* */
37 // Check update.
38 TEST(DiscreteValues, Update) {
39  EXPECT(assert_equal({{12, 2}, {5, 0}},
40  DiscreteValues(kExample).update({{12, 2}})));
41 }
42 
43 /* ************************************************************************* */
44 // Check markdown representation with a value formatter.
45 TEST(DiscreteValues, markdownWithValueFormatter) {
46  string expected =
47  "|Variable|value|\n"
48  "|:-:|:-:|\n"
49  "|B|-|\n"
50  "|A|One|\n";
51  auto keyFormatter = [](Key key) { return key == 12 ? "A" : "B"; };
52  DiscreteValues::Names names{{12, {"Zero", "One", "Two"}}, {5, {"-", "+"}}};
53  string actual = kExample.markdown(keyFormatter, names);
54  EXPECT(actual == expected);
55 }
56 
57 /* ************************************************************************* */
58 // Check html representation with a value formatter.
59 TEST(DiscreteValues, htmlWithValueFormatter) {
60  string expected =
61  "<div>\n"
62  "<table class='DiscreteValues'>\n"
63  " <thead>\n"
64  " <tr><th>Variable</th><th>value</th></tr>\n"
65  " </thead>\n"
66  " <tbody>\n"
67  " <tr><th>B</th><td>-</td></tr>\n"
68  " <tr><th>A</th><td>One</td></tr>\n"
69  " </tbody>\n"
70  "</table>\n"
71  "</div>";
72  auto keyFormatter = [](Key key) { return key == 12 ? "A" : "B"; };
73  DiscreteValues::Names names{{12, {"Zero", "One", "Two"}}, {5, {"-", "+"}}};
74  string actual = kExample.html(keyFormatter, names);
75  EXPECT(actual == expected);
76 }
77 
78 /* ************************************************************************* */
79 int main() {
80  TestResult tr;
81  return TestRegistry::runAllTests(tr);
82 }
83 /* ************************************************************************* */
TestRegistry::runAllTests
static int runAllTests(TestResult &result)
Definition: TestRegistry.cpp:27
Testable.h
Concept check for values that can be used in unit tests.
EXPECT
#define EXPECT(condition)
Definition: Test.h:150
TestHarness.h
gtsam::DiscreteValues::markdown
std::string markdown(const KeyFormatter &keyFormatter=DefaultKeyFormatter, const Names &names={}) const
Output as a markdown table.
Definition: DiscreteValues.cpp:88
gtsam::DiscreteValues::html
std::string html(const KeyFormatter &keyFormatter=DefaultKeyFormatter, const Names &names={}) const
Output as a html table.
Definition: DiscreteValues.cpp:105
main
int main()
Definition: testDiscreteValues.cpp:79
gtsam::DiscreteValues::update
DiscreteValues & update(const DiscreteValues &values)
Definition: DiscreteValues.cpp:64
Signature.h
signatures for conditional densities
cholesky::expected
Matrix expected
Definition: testMatrix.cpp:971
TestResult
Definition: TestResult.h:26
key
const gtsam::Symbol key('X', 0)
process_shonan_timing_results.names
dictionary names
Definition: process_shonan_timing_results.py:175
gtsam
traits
Definition: SFMdata.h:40
DiscreteValues.h
gtsam::DiscreteValues
Definition: DiscreteValues.h:34
std
Definition: BFloat16.h:88
gtsam::DiscreteValues::insert
std::pair< iterator, bool > insert(const value_type &value)
Definition: DiscreteValues.h:68
TEST
TEST(DiscreteValues, Insert)
Definition: testDiscreteValues.cpp:31
gtsam::assert_equal
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
Definition: Matrix.cpp:40
gtsam::DiscreteValues::Names
std::map< Key, std::vector< std::string > > Names
Translation table from values to strings.
Definition: DiscreteValues.h:95
gtsam::Key
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:97
kExample
static const DiscreteValues kExample
Definition: testDiscreteValues.cpp:27


gtsam
Author(s):
autogenerated on Thu Nov 28 2024 04:07:52