Mercurial > hg > nsaunier > traffic-intelligence
comparison trajectorymanagement/test/ManhattanMetricTest.cpp @ 1159:e1e7acef8eab
moved trajectory management library into Traffic Intelligence
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Mon, 22 Feb 2021 22:09:35 -0500 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 1158:7eb972942f22 | 1159:e1e7acef8eab |
|---|---|
| 1 #include "ManhattanMetricTest.h" | |
| 2 | |
| 3 void ManhattanMetricTest::setUp(void) | |
| 4 { | |
| 5 trajectoryA = new Trajectory<CvPoint> (); | |
| 6 trajectoryB = new Trajectory<CvPoint> (); | |
| 7 metric = new ManhattanMetric<CvPoint, int> (); | |
| 8 } | |
| 9 | |
| 10 void ManhattanMetricTest::tearDown(void) | |
| 11 { | |
| 12 delete trajectoryA; | |
| 13 delete trajectoryB; | |
| 14 delete metric; | |
| 15 | |
| 16 trajectoryA = NULL; | |
| 17 trajectoryB = NULL; | |
| 18 metric = NULL; | |
| 19 } | |
| 20 | |
| 21 void ManhattanMetricTest::testMetric1(void) | |
| 22 { | |
| 23 int result = 0; | |
| 24 CPPUNIT_ASSERT_THROW(metric->distance(trajectoryA, trajectoryB, result), | |
| 25 TrajectoryLengthErrorException); | |
| 26 } | |
| 27 | |
| 28 void ManhattanMetricTest::testMetric2(void) | |
| 29 { | |
| 30 int result = 0; | |
| 31 trajectoryA->add(cvPoint(0, 0)); | |
| 32 trajectoryB->add(cvPoint(0, 0)); | |
| 33 metric->distance(trajectoryA, trajectoryB, result); | |
| 34 CPPUNIT_ASSERT_EQUAL(result, 0); | |
| 35 } | |
| 36 | |
| 37 void ManhattanMetricTest::testMetric3(void) | |
| 38 { | |
| 39 int result = 0; | |
| 40 trajectoryA->add(cvPoint(0, 0)); | |
| 41 trajectoryB->add(cvPoint(1, 1)); | |
| 42 metric->distance(trajectoryA, trajectoryB, result); | |
| 43 CPPUNIT_ASSERT_EQUAL(result, 2); | |
| 44 } | |
| 45 | |
| 46 void ManhattanMetricTest::testMetric4(void) | |
| 47 { | |
| 48 int result = 0; | |
| 49 trajectoryA->add(cvPoint(0, 0)); | |
| 50 trajectoryB->add(cvPoint(3, 4)); | |
| 51 metric->distance(trajectoryA, trajectoryB, result); | |
| 52 CPPUNIT_ASSERT_EQUAL(result, 7); | |
| 53 } | |
| 54 | |
| 55 void ManhattanMetricTest::testMetric5(void) | |
| 56 { | |
| 57 int result = 0; | |
| 58 trajectoryA->add(cvPoint(0, 0)); | |
| 59 trajectoryA->add(cvPoint(-4, -3)); | |
| 60 trajectoryB->add(cvPoint(3, 4)); | |
| 61 trajectoryB->add(cvPoint(0, 0)); | |
| 62 metric->distance(trajectoryA, trajectoryB, result); | |
| 63 CPPUNIT_ASSERT_EQUAL(result, 14); | |
| 64 } | |
| 65 | |
| 66 void ManhattanMetricTest::testMetric6(void) | |
| 67 { | |
| 68 int result = 0; | |
| 69 unsigned n = 100; | |
| 70 unsigned maxRand = 10000; | |
| 71 srand(time(NULL)); | |
| 72 for (unsigned i = 0; i < n; ++i) | |
| 73 { | |
| 74 unsigned rand1 = rand() % maxRand; | |
| 75 unsigned rand2 = rand() % maxRand; | |
| 76 trajectoryA->add(cvPoint(rand1, rand2)); | |
| 77 trajectoryB ->add(cvPoint(rand1 + 3, rand2 + 4)); | |
| 78 } | |
| 79 metric->distance(trajectoryA, trajectoryB, result); | |
| 80 CPPUNIT_ASSERT_EQUAL(result, int(n * 3 + n * 4)); | |
| 81 } |
