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 /* ************************************************************************* */
const gtsam::Symbol key('X', 0)
Concept check for values that can be used in unit tests.
static int runAllTests(TestResult &result)
signatures for conditional densities
std::string markdown(const KeyFormatter &keyFormatter=DefaultKeyFormatter, const Names &names={}) const
Output as a markdown table.
Matrix expected
Definition: testMatrix.cpp:971
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
Definition: Matrix.cpp:40
Definition: BFloat16.h:88
std::string html(const KeyFormatter &keyFormatter=DefaultKeyFormatter, const Names &names={}) const
Output as a html table.
int main()
#define EXPECT(condition)
Definition: Test.h:150
DiscreteValues & update(const DiscreteValues &values)
TEST(DiscreteValues, Insert)
traits
Definition: chartTesting.h:28
static const DiscreteValues kExample
std::pair< iterator, bool > insert(const value_type &value)
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:102


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