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