Mercurial > hg > nsaunier > traffic-intelligence
comparison c/test_graph.cpp @ 201:f7ddfc4aeb1e
added tests for graphs
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Mon, 05 Mar 2012 01:52:56 -0500 |
| parents | 0a27fa343257 |
| children | f0f800b95765 bc4ea09b1743 |
comparison
equal
deleted
inserted
replaced
| 200:0a27fa343257 | 201:f7ddfc4aeb1e |
|---|---|
| 4 #include "opencv2/core/core.hpp" | 4 #include "opencv2/core/core.hpp" |
| 5 | 5 |
| 6 #include <boost/test/unit_test.hpp> | 6 #include <boost/test/unit_test.hpp> |
| 7 #include <boost/test/floating_point_comparison.hpp> | 7 #include <boost/test/floating_point_comparison.hpp> |
| 8 | 8 |
| 9 #include <iostream> | |
| 10 | |
| 9 using namespace std; | 11 using namespace std; |
| 10 using namespace cv; | 12 using namespace cv; |
| 11 | 13 |
| 12 BOOST_AUTO_TEST_SUITE(test_graph) | 14 BOOST_AUTO_TEST_SUITE(test_graph) |
| 13 | 15 |
| 14 BOOST_AUTO_TEST_CASE(graph_add_delete) { | 16 BOOST_AUTO_TEST_CASE(graph_add_connected_components) { |
| 15 FeatureGraph featureGraph(5, 1, 5 /* min time interval */, 1.); | 17 FeatureGraph featureGraph(5, 1, 5 , 1.); // (float _connectionDistance, float _segmentationDistance, unsigned int _minFeatureTime, float _minNFeaturesPerGroup) |
| 16 FeatureTrajectoryPtr ft1 = createFeatureTrajectory(10, 20, Point2f(1,1), Point2f(0.5, 0.)); | 18 unsigned int lastInstant = 20; |
| 17 FeatureTrajectoryPtr ft2 = createFeatureTrajectory(10, 20, Point2f(1.1,1), Point2f(0.5, 0.)); | 19 FeatureTrajectoryPtr ft1 = createFeatureTrajectory(1, 10, lastInstant, Point2f(1,1), Point2f(0.5, 0.)); |
| 20 FeatureTrajectoryPtr ft2 = createFeatureTrajectory(2, 10, lastInstant, Point2f(1.1,1), Point2f(0.5, 0.)); | |
| 18 | 21 |
| 19 featureGraph.addFeature(ft1); | 22 featureGraph.addFeature(ft1); |
| 20 BOOST_CHECK_EQUAL(featureGraph.getNVertices(), 1); | 23 BOOST_CHECK_EQUAL(featureGraph.getNVertices(), 1); |
| 21 BOOST_CHECK_EQUAL(featureGraph.getNEdges(), 0); | 24 BOOST_CHECK_EQUAL(featureGraph.getNEdges(), 0); |
| 22 | 25 |
| 23 featureGraph.addFeature(ft2); | 26 featureGraph.addFeature(ft2); |
| 24 BOOST_CHECK_EQUAL(featureGraph.getNVertices(), 2); | 27 BOOST_CHECK_EQUAL(featureGraph.getNVertices(), 2); |
| 25 BOOST_CHECK_EQUAL(featureGraph.getNEdges(), 1); | 28 BOOST_CHECK_EQUAL(featureGraph.getNEdges(), 1); |
| 26 | 29 |
| 27 | 30 featureGraph.connectedComponents(lastInstant); |
| 31 vector<vector<unsigned int> > components = featureGraph.getFeatureGroups(); | |
| 32 BOOST_CHECK_EQUAL(components.size(), 0); | |
| 33 BOOST_CHECK_EQUAL(featureGraph.getNVertices(), 2); | |
| 34 BOOST_CHECK_EQUAL(featureGraph.getNEdges(), 1); | |
| 35 | |
| 36 featureGraph.connectedComponents(lastInstant+1); | |
| 37 components = featureGraph.getFeatureGroups(); | |
| 38 BOOST_CHECK_EQUAL(components.size(), 1); | |
| 39 BOOST_CHECK_EQUAL(components[0].size(), 2); | |
| 40 BOOST_CHECK_EQUAL(featureGraph.getNVertices(), 0); | |
| 41 BOOST_CHECK_EQUAL(featureGraph.getNEdges(), 0); | |
| 42 | |
| 43 // test connection distance | |
| 44 featureGraph.addFeature(ft1); | |
| 45 featureGraph.addFeature(ft2); | |
| 46 FeatureTrajectoryPtr ft3 = createFeatureTrajectory(3, 10, lastInstant, Point2f(6.05,1), Point2f(0.5, 0.)); // connected to ft2 only | |
| 47 featureGraph.addFeature(ft3); | |
| 48 FeatureTrajectoryPtr ft4 = createFeatureTrajectory(4, 10, lastInstant, Point2f(11.1,1), Point2f(0.5, 0.)); // not connected | |
| 49 featureGraph.addFeature(ft4); | |
| 50 | |
| 51 BOOST_CHECK_EQUAL(featureGraph.getNVertices(), 4); | |
| 52 BOOST_CHECK_EQUAL(featureGraph.getNEdges(), 2); | |
| 53 | |
| 54 featureGraph.connectedComponents(lastInstant+1); | |
| 55 components = featureGraph.getFeatureGroups(); | |
| 56 BOOST_CHECK_EQUAL(components.size(), 2); | |
| 57 BOOST_CHECK_EQUAL(components[0].size(), 3); | |
| 58 BOOST_CHECK_EQUAL(components[1].size(), 1); | |
| 59 BOOST_CHECK_EQUAL(featureGraph.getNVertices(), 0); | |
| 60 BOOST_CHECK_EQUAL(featureGraph.getNEdges(), 0); | |
| 28 } | 61 } |
| 29 | 62 |
| 30 BOOST_AUTO_TEST_SUITE_END() | 63 BOOST_AUTO_TEST_SUITE_END() |
