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