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 
22 
23 using namespace std;
24 using namespace gtsam;
25 
26 /* ************************************************************************* */
28 {
30  LONGS_EQUAL(0, (long)c0.nrFrontals());
31  LONGS_EQUAL(0, (long)c0.nrParents());
32 }
33 
34 /* ************************************************************************* */
36 {
37  SymbolicConditional c0(0);
38  LONGS_EQUAL(1, (long)c0.nrFrontals());
39  LONGS_EQUAL(0, (long)c0.nrParents());
40 }
41 
42 /* ************************************************************************* */
43 TEST( SymbolicConditional, oneParents )
44 {
45  SymbolicConditional c0(0,1);
46  LONGS_EQUAL(1, (long)c0.nrFrontals());
47  LONGS_EQUAL(1, (long)c0.nrParents());
48 }
49 
50 /* ************************************************************************* */
51 TEST( SymbolicConditional, twoParents )
52 {
53  SymbolicConditional c0(0,1,2);
54  LONGS_EQUAL(1, (long)c0.nrFrontals());
55  LONGS_EQUAL(2, (long)c0.nrParents());
56 }
57 
58 /* ************************************************************************* */
59 TEST( SymbolicConditional, threeParents )
60 {
61  SymbolicConditional c0(0,1,2,3);
62  LONGS_EQUAL(1, (long)c0.nrFrontals());
63  LONGS_EQUAL(3, (long)c0.nrParents());
64 }
65 
66 /* ************************************************************************* */
67 TEST( SymbolicConditional, fourParents )
68 {
69  auto c0 = SymbolicConditional::FromKeys(KeyVector{0, 1, 2, 3, 4}, 1);
70  LONGS_EQUAL(1, (long)c0.nrFrontals());
71  LONGS_EQUAL(4, (long)c0.nrParents());
72 }
73 
74 /* ************************************************************************* */
76 {
77  auto c0 = std::make_shared<SymbolicConditional>(
78  SymbolicConditional::FromKeys(KeyVector{1, 2, 3, 4, 5}, 2));
79  LONGS_EQUAL(2, (long)c0->nrFrontals());
80  LONGS_EQUAL(3, (long)c0->nrParents());
81 }
82 
83 /* ************************************************************************* */
84 TEST(SymbolicConditional, Constructors)
85 {
87 
88  SymbolicConditional actual1 = SymbolicConditional::FromKeys(expected.keys(), 1);
89  SymbolicConditional actual2 = SymbolicConditional::FromIterators(expected.begin(), expected.end(), 1);
90  SymbolicConditional actual3 = *SymbolicConditional::FromKeysShared(expected.keys(), 1);
91  SymbolicConditional actual4 = *SymbolicConditional::FromIteratorsShared(expected.begin(), expected.end(), 1);
92 
93  EXPECT(assert_equal(expected, actual1));
94  EXPECT(assert_equal(expected, actual2));
95  EXPECT(assert_equal(expected, actual3));
96  EXPECT(assert_equal(expected, actual4));
97 }
98 
99 /* ************************************************************************* */
101 {
102  SymbolicConditional c0(0, 1, 2), c1(0, 1, 2), c2(1, 2, 3), c3(3,4);
103  CHECK(c0.equals(c1));
104  CHECK(c1.equals(c0));
105  CHECK(!c0.equals(c2));
106  CHECK(!c2.equals(c0));
107  CHECK(!c0.equals(c3));
108  CHECK(!c3.equals(c0));
109 }
110 
111 /* ************************************************************************* */
112 int main() {
113  TestResult tr;
114  return TestRegistry::runAllTests(tr);
115 }
116 /* ************************************************************************* */
Provides additional testing facilities for common data structures.
#define CHECK(condition)
Definition: Test.h:108
static int runAllTests(TestResult &result)
bool equals(const This &c, double tol=1e-9) const
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
size_t nrFrontals() const
Definition: Conditional.h:129
const_iterator end() const
Definition: Factor.h:148
#define EXPECT(condition)
Definition: Test.h:150
TEST(SymbolicConditional, empty)
#define LONGS_EQUAL(expected, actual)
Definition: Test.h:134
traits
Definition: chartTesting.h:28
const KeyVector & keys() const
Access the factor&#39;s involved variable keys.
Definition: Factor.h:142
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition: Key.h:86
const_iterator begin() const
Definition: Factor.h:145
size_t nrParents() const
Definition: Conditional.h:132


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:39:43