velocity_iterator_test.cpp
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2017, Locus Robotics
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of the copyright holder nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  */
34 #include <gtest/gtest.h>
36 
38 
39 const double EPSILON = 1e-3;
40 
41 TEST(VelocityIterator, basics)
42 {
43  OneDVelocityIterator it(2.0, 0.0, 5.0, 1.0, -1.0, 1.0, 2);
44  EXPECT_FALSE(it.isFinished());
45  EXPECT_NEAR(it.getVelocity(), 1.0, EPSILON);
46  EXPECT_FALSE(it.isFinished());
47  ++it;
48  EXPECT_FALSE(it.isFinished());
49  EXPECT_NEAR(it.getVelocity(), 3.0, EPSILON);
50  EXPECT_FALSE(it.isFinished());
51  ++it;
52  EXPECT_TRUE(it.isFinished());
53  it.reset();
54  EXPECT_FALSE(it.isFinished());
55  EXPECT_NEAR(it.getVelocity(), 1.0, EPSILON);
56 }
57 
58 TEST(VelocityIterator, limits)
59 {
60  OneDVelocityIterator it(2.0, 1.5, 2.5, 1.0, -1.0, 1.0, 2);
61  EXPECT_NEAR(it.getVelocity(), 1.5, EPSILON);
62  ++it;
63  EXPECT_NEAR(it.getVelocity(), 2.5, EPSILON);
64 }
65 
66 TEST(VelocityIterator, acceleration)
67 {
68  OneDVelocityIterator it(2.0, 0.0, 5.0, 0.5, -0.5, 1.0, 2);
69  EXPECT_NEAR(it.getVelocity(), 1.5, EPSILON);
70  ++it;
71  EXPECT_NEAR(it.getVelocity(), 2.5, EPSILON);
72 }
73 
74 
75 TEST(VelocityIterator, time)
76 {
77  OneDVelocityIterator it(2.0, 0.0, 5.0, 1.0, -1.0, 0.5, 2);
78  EXPECT_NEAR(it.getVelocity(), 1.5, EPSILON);
79  ++it;
80  EXPECT_NEAR(it.getVelocity(), 2.5, EPSILON);
81 }
82 
83 TEST(VelocityIterator, samples)
84 {
85  OneDVelocityIterator it(2.0, 0.0, 5.0, 1.0, -1.0, 1.0, 3);
86  EXPECT_NEAR(it.getVelocity(), 1.0, EPSILON);
87  ++it;
88  EXPECT_NEAR(it.getVelocity(), 2.0, EPSILON);
89  ++it;
90  EXPECT_NEAR(it.getVelocity(), 3.0, EPSILON);
91  ++it;
92  EXPECT_TRUE(it.isFinished());
93 }
94 
95 
96 TEST(VelocityIterator, samples2)
97 {
98  OneDVelocityIterator it(2.0, 0.0, 5.0, 1.0, -1.0, 1.0, 5);
99  EXPECT_NEAR(it.getVelocity(), 1.0, EPSILON);
100  ++it;
101  EXPECT_NEAR(it.getVelocity(), 1.5, EPSILON);
102  ++it;
103  EXPECT_NEAR(it.getVelocity(), 2.0, EPSILON);
104  ++it;
105  EXPECT_NEAR(it.getVelocity(), 2.5, EPSILON);
106  ++it;
107  EXPECT_NEAR(it.getVelocity(), 3.0, EPSILON);
108  ++it;
109  EXPECT_TRUE(it.isFinished());
110 }
111 
112 TEST(VelocityIterator, around_zero)
113 {
114  OneDVelocityIterator it(0.0, -5.0, 5.0, 1.0, -1.0, 1.0, 2);
115  EXPECT_NEAR(it.getVelocity(), -1.0, EPSILON);
116  ++it;
117  EXPECT_NEAR(it.getVelocity(), 0.0, EPSILON);
118  ++it;
119  EXPECT_NEAR(it.getVelocity(), 1.0, EPSILON);
120  ++it;
121 }
122 
123 TEST(VelocityIterator, around_zero2)
124 {
125  OneDVelocityIterator it(0.0, -5.0, 5.0, 1.0, -1.0, 1.0, 4);
126  EXPECT_NEAR(it.getVelocity(), -1.0, EPSILON);
127  ++it;
128  EXPECT_NEAR(it.getVelocity(), -0.3333, EPSILON);
129  ++it;
130  EXPECT_NEAR(it.getVelocity(), 0.0, EPSILON);
131  ++it;
132  EXPECT_NEAR(it.getVelocity(), 0.3333, EPSILON);
133  ++it;
134  EXPECT_NEAR(it.getVelocity(), 1.0, EPSILON);
135  ++it;
136 }
137 
138 int main(int argc, char **argv)
139 {
140  testing::InitGoogleTest(&argc, argv);
141  return RUN_ALL_TESTS();
142 }
int main(int argc, char **argv)
TEST(VelocityIterator, basics)
An iterator for generating a number of samples in a range.
double getVelocity() const
Get the next velocity available.
void reset()
Reset back to the first velocity.
const double EPSILON


dwb_plugins
Author(s):
autogenerated on Wed Jun 26 2019 20:06:16