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 /* ************************************************************************* */
TestRegistry::runAllTests
static int runAllTests(TestResult &result)
Definition: TestRegistry.cpp:27
EXPECT
#define EXPECT(condition)
Definition: Test.h:150
TestHarness.h
main
int main()
Definition: testSymbolicConditional.cpp:112
gtsam::KeyVector
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition: Key.h:92
SymbolicConditional.h
TestableAssertions.h
Provides additional testing facilities for common data structures.
c1
static double c1
Definition: airy.c:54
cholesky::expected
Matrix expected
Definition: testMatrix.cpp:971
gtsam::SymbolicConditional::equals
bool equals(const This &c, double tol=1e-9) const
Definition: SymbolicConditional.cpp:31
gtsam::equals
Definition: Testable.h:112
TestResult
Definition: TestResult.h:26
gtsam::Conditional::nrFrontals
size_t nrFrontals() const
Definition: Conditional.h:131
TEST
TEST(SymbolicConditional, empty)
Definition: testSymbolicConditional.cpp:27
gtsam::SymbolicConditional
Definition: SymbolicConditional.h:36
empty
Definition: test_copy_move.cpp:19
gtsam
traits
Definition: SFMdata.h:40
CHECK
#define CHECK(condition)
Definition: Test.h:108
std
Definition: BFloat16.h:88
c2
static double c2
Definition: airy.c:55
gtsam::assert_equal
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
Definition: Matrix.cpp:40
gtsam::Conditional::nrParents
size_t nrParents() const
Definition: Conditional.h:134
LONGS_EQUAL
#define LONGS_EQUAL(expected, actual)
Definition: Test.h:134


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:08:45