| 
									
										
										
										
											2009-10-30 11:48:32 +08:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * @file    testSymbolicFactor.cpp | 
					
						
							|  |  |  |  * @brief   Unit tests for a symbolic Factor | 
					
						
							|  |  |  |  * @author  Frank Dellaert | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-20 01:23:19 +08:00
										 |  |  | #include <gtsam/CppUnitLite/TestHarness.h>
 | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | #include <gtsam/base/TestableAssertions.h>
 | 
					
						
							|  |  |  | #include <gtsam/inference/Factor-inl.h>
 | 
					
						
							|  |  |  | #include <gtsam/inference/Conditional.h>
 | 
					
						
							| 
									
										
										
										
											2009-10-30 11:48:32 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | #include <boost/assign/std/vector.hpp>
 | 
					
						
							| 
									
										
										
										
											2009-10-30 11:48:32 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | using namespace std; | 
					
						
							|  |  |  | using namespace gtsam; | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | using namespace boost::assign; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | TEST(SymbolicFactor, eliminate) { | 
					
						
							| 
									
										
										
										
											2010-10-12 05:14:35 +08:00
										 |  |  |   vector<Index> keys; keys += 2, 3, 4, 6, 7, 9, 10, 11; | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  |   Factor actual(keys.begin(), keys.end()); | 
					
						
							|  |  |  |   BayesNet<Conditional> fragment = *actual.eliminate(3); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   Factor expected(keys.begin()+3, keys.end()); | 
					
						
							| 
									
										
										
										
											2010-10-12 08:14:50 +08:00
										 |  |  |   Conditional::shared_ptr expected0 = Conditional::fromRange(keys.begin(), keys.end(), 1); | 
					
						
							|  |  |  |   Conditional::shared_ptr expected1 = Conditional::fromRange(keys.begin()+1, keys.end(), 1); | 
					
						
							|  |  |  |   Conditional::shared_ptr expected2 = Conditional::fromRange(keys.begin()+2, keys.end(), 1); | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   CHECK(assert_equal(fragment.size(), size_t(3))); | 
					
						
							|  |  |  |   CHECK(assert_equal(expected, actual)); | 
					
						
							|  |  |  |   BayesNet<Conditional>::const_iterator fragmentCond = fragment.begin(); | 
					
						
							| 
									
										
										
										
											2010-10-12 08:14:50 +08:00
										 |  |  |   CHECK(assert_equal(**fragmentCond++, *expected0)); | 
					
						
							|  |  |  |   CHECK(assert_equal(**fragmentCond++, *expected1)); | 
					
						
							|  |  |  |   CHECK(assert_equal(**fragmentCond++, *expected2)); | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2009-10-30 11:48:32 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | int main() { | 
					
						
							|  |  |  | 	TestResult tr; | 
					
						
							|  |  |  | 	return TestRegistry::runAllTests(tr); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | /* ************************************************************************* */ |