Mercurial Hosting > traffic-intelligence
comparison trajectorymanagement/test/EuclideanMetricTest.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 "EuclideanMetricTest.h" | |
2 | |
3 void EuclideanMetricTest::setUp(void) | |
4 { | |
5 trajectoryA = new Trajectory<CvPoint> (); | |
6 trajectoryB = new Trajectory<CvPoint> (); | |
7 metric = new EuclideanMetric<CvPoint, double> (); | |
8 } | |
9 | |
10 void EuclideanMetricTest::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 EuclideanMetricTest::testMetric1(void) | |
22 { | |
23 double result = double(0); | |
24 CPPUNIT_ASSERT_THROW(metric->distance(trajectoryA, trajectoryB, result), TrajectoryLengthErrorException); | |
25 } | |
26 | |
27 void EuclideanMetricTest::testMetric2(void) | |
28 { | |
29 double result = double(0); | |
30 trajectoryA->add(cvPoint(0, 0)); | |
31 trajectoryB->add(cvPoint(0, 0)); | |
32 metric->distance(trajectoryA, trajectoryB, result); | |
33 CPPUNIT_ASSERT_EQUAL(result, double(0)); | |
34 } | |
35 | |
36 void EuclideanMetricTest::testMetric3(void) | |
37 { | |
38 double result = double(0); | |
39 trajectoryA->add(cvPoint(0, 0)); | |
40 trajectoryB->add(cvPoint(1, 1)); | |
41 metric->distance(trajectoryA, trajectoryB, result); | |
42 CPPUNIT_ASSERT_EQUAL(result, double(sqrt(2))); | |
43 } | |
44 | |
45 void EuclideanMetricTest::testMetric4(void) | |
46 { | |
47 double result = double(0); | |
48 trajectoryA->add(cvPoint(0, 0)); | |
49 trajectoryB->add(cvPoint(3, 4)); | |
50 metric->distance(trajectoryA, trajectoryB, result); | |
51 CPPUNIT_ASSERT_EQUAL(result, double(5)); | |
52 } | |
53 | |
54 void EuclideanMetricTest::testMetric5(void) | |
55 { | |
56 double result = double(0); | |
57 trajectoryA->add(cvPoint(0, 0)); | |
58 trajectoryA->add(cvPoint(-4, -3)); | |
59 trajectoryB->add(cvPoint(3, 4)); | |
60 trajectoryB->add(cvPoint(0, 0)); | |
61 metric->distance(trajectoryA, trajectoryB, result); | |
62 CPPUNIT_ASSERT_EQUAL(result, sqrt(double(50))); | |
63 } | |
64 | |
65 void EuclideanMetricTest::testMetric6(void) | |
66 { | |
67 double result = double(0); | |
68 unsigned n = 100; | |
69 unsigned maxRand = 10000; | |
70 srand(time(NULL)); | |
71 for (unsigned i = 0; i < n; ++i) | |
72 { | |
73 unsigned rand1 = rand() % maxRand; | |
74 unsigned rand2 = rand() % maxRand; | |
75 trajectoryA->add(cvPoint(rand1, rand2)); | |
76 trajectoryB ->add(cvPoint(rand1 + 3, rand2 + 4)); | |
77 } | |
78 metric->distance(trajectoryA, trajectoryB, result); | |
79 CPPUNIT_ASSERT_EQUAL(result, sqrt(double(n * 9 + n * 16))); | |
80 } |