comparison trajectorymanagement/test/DTWMetricTest.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 "DTWMetricTest.h"
2
3 void DTWMetricTest::setUp(void)
4 {
5 trajectoryA = new Trajectory<CvPoint> ();
6 trajectoryB = new Trajectory<CvPoint> ();
7 metric = new DTWMetric<CvPoint, double> ();
8 }
9
10 void DTWMetricTest::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 DTWMetricTest::testMetric1(void)
22 {
23 double result = double(0);
24 metric->distance(trajectoryA, trajectoryB, result);
25 CPPUNIT_ASSERT_EQUAL(result, double(0));
26 }
27
28 void DTWMetricTest::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 DTWMetricTest::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, sqrt(double(2)));
44 }
45
46 void DTWMetricTest::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(5));
53 }
54
55 void DTWMetricTest::testMetric5(void)
56 {
57 double result = double(0);
58 unsigned n = 100;
59 for (unsigned i = 1; i <= n; ++i)
60 {
61 trajectoryA->add(cvPoint(i * 100, i * 100));
62 trajectoryB ->add(cvPoint(i * 100 + 3, i * 100 + 4));
63 }
64 metric->distance(trajectoryA, trajectoryB, result);
65 CPPUNIT_ASSERT_EQUAL(result, double(n * 5));
66 }
67
68 void DTWMetricTest::testMetric6(void)
69 {
70 double result = double(0);
71 unsigned n = 100;
72 for (unsigned i = 1; i <= n; ++i)
73 {
74 trajectoryA->add(cvPoint(i * 100, i * 100));
75 trajectoryB ->add(cvPoint(i * 100 + 6, i * 100 + 8));
76 }
77 metric->distance(trajectoryA, trajectoryB, result);
78 CPPUNIT_ASSERT_EQUAL(result, double(n * sqrt(double(100))));
79 }