testSymbolicConditional.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 
18 #include <boost/assign/list_of.hpp>
19 using namespace boost::assign;
20 #include <boost/make_shared.hpp>
21 
25 
26 using namespace std;
27 using namespace gtsam;
28 
29 /* ************************************************************************* */
31 {
33  LONGS_EQUAL(0, (long)c0.nrFrontals());
34  LONGS_EQUAL(0, (long)c0.nrParents());
35 }
36 
37 /* ************************************************************************* */
39 {
40  SymbolicConditional c0(0);
41  LONGS_EQUAL(1, (long)c0.nrFrontals());
42  LONGS_EQUAL(0, (long)c0.nrParents());
43 }
44 
45 /* ************************************************************************* */
46 TEST( SymbolicConditional, oneParents )
47 {
48  SymbolicConditional c0(0,1);
49  LONGS_EQUAL(1, (long)c0.nrFrontals());
50  LONGS_EQUAL(1, (long)c0.nrParents());
51 }
52 
53 /* ************************************************************************* */
54 TEST( SymbolicConditional, twoParents )
55 {
56  SymbolicConditional c0(0,1,2);
57  LONGS_EQUAL(1, (long)c0.nrFrontals());
58  LONGS_EQUAL(2, (long)c0.nrParents());
59 }
60 
61 /* ************************************************************************* */
62 TEST( SymbolicConditional, threeParents )
63 {
64  SymbolicConditional c0(0,1,2,3);
65  LONGS_EQUAL(1, (long)c0.nrFrontals());
66  LONGS_EQUAL(3, (long)c0.nrParents());
67 }
68 
69 /* ************************************************************************* */
70 TEST( SymbolicConditional, fourParents )
71 {
72  SymbolicConditional c0 = SymbolicConditional::FromKeys(
73  list_of(0)(1)(2)(3)(4), 1);
74  LONGS_EQUAL(1, (long)c0.nrFrontals());
75  LONGS_EQUAL(4, (long)c0.nrParents());
76 }
77 
78 /* ************************************************************************* */
80 {
82  boost::make_shared<SymbolicConditional>(
83  SymbolicConditional::FromKeys(list_of(1)(2)(3)(4)(5), 2));
84  LONGS_EQUAL(2, (long)c0->nrFrontals());
85  LONGS_EQUAL(3, (long)c0->nrParents());
86 }
87 
88 /* ************************************************************************* */
89 TEST(SymbolicConditional, Constructors)
90 {
92 
93  SymbolicConditional actual1 = SymbolicConditional::FromKeys(expected.keys(), 1);
94  SymbolicConditional actual2 = SymbolicConditional::FromIterators(expected.begin(), expected.end(), 1);
95  SymbolicConditional actual3 = *SymbolicConditional::FromKeysShared(expected.keys(), 1);
96  SymbolicConditional actual4 = *SymbolicConditional::FromIteratorsShared(expected.begin(), expected.end(), 1);
97 
98  EXPECT(assert_equal(expected, actual1));
99  EXPECT(assert_equal(expected, actual2));
100  EXPECT(assert_equal(expected, actual3));
101  EXPECT(assert_equal(expected, actual4));
102 }
103 
104 /* ************************************************************************* */
106 {
107  SymbolicConditional c0(0, 1, 2), c1(0, 1, 2), c2(1, 2, 3), c3(3,4);
108  CHECK(c0.equals(c1));
109  CHECK(c1.equals(c0));
110  CHECK(!c0.equals(c2));
111  CHECK(!c2.equals(c0));
112  CHECK(!c0.equals(c3));
113  CHECK(!c3.equals(c0));
114 }
115 
116 /* ************************************************************************* */
117 int main() {
118  TestResult tr;
119  return TestRegistry::runAllTests(tr);
120 }
121 /* ************************************************************************* */
bool equals(const This &c, double tol=1e-9) const
Provides additional testing facilities for common data structures.
#define CHECK(condition)
Definition: Test.h:109
static const Key c2
static int runAllTests(TestResult &result)
Matrix expected
Definition: testMatrix.cpp:974
static const Key c3
const_iterator end() const
Definition: Factor.h:130
Definition: Half.h:150
size_t nrFrontals() const
Definition: Conditional.h:85
boost::shared_ptr< This > shared_ptr
Typedef to the conditional base class.
const_iterator begin() const
Definition: Factor.h:127
#define EXPECT(condition)
Definition: Test.h:151
size_t nrParents() const
Definition: Conditional.h:88
TEST(SymbolicConditional, empty)
#define LONGS_EQUAL(expected, actual)
Definition: Test.h:135
traits
Definition: chartTesting.h:28
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
Definition: Matrix.cpp:42
const KeyVector & keys() const
Access the factor&#39;s involved variable keys.
Definition: Factor.h:124
static const Key c1


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:49:57