test_timestamp_moving_average.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright 2018 The urg_stamped Authors
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  * http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 #include <gtest/gtest.h>
00018 
00019 #include <timestamp_moving_average.h>
00020 
00021 TEST(TimestampMovingAverage, ResetAndGo)
00022 {
00023   TimestampMovingAverage ma(3, ros::Duration(0.1));
00024   for (double t = 10.0; t < 11.0; t += 0.1)
00025   {
00026     ASSERT_EQ(ma.update(ros::Time(t)), ros::Time(t));
00027   }
00028   ma.reset();
00029   for (double t = 12.0; t < 13.0; t += 0.1)
00030   {
00031     ASSERT_EQ(ma.update(ros::Time(t)), ros::Time(t));
00032   }
00033 }
00034 
00035 TEST(TimestampMovingAverage, MovingAverage)
00036 {
00037   TimestampMovingAverage ma(3, ros::Duration(0.1));
00038   ASSERT_EQ(ma.update(ros::Time(10.000)), ros::Time(10.000));
00039   ASSERT_EQ(ma.update(ros::Time(10.100)), ros::Time(10.100));
00040   ASSERT_EQ(ma.update(ros::Time(10.203)), ros::Time(10.201));
00041   ASSERT_EQ(ma.update(ros::Time(10.300)), ros::Time(10.301));
00042   ASSERT_EQ(ma.update(ros::Time(10.400)), ros::Time(10.401));
00043   ASSERT_EQ(ma.update(ros::Time(10.500)), ros::Time(10.500));
00044 }
00045 
00046 TEST(TimestampMovingAverage, SkippedInput)
00047 {
00048   TimestampMovingAverage ma(3, ros::Duration(0.1));
00049   for (double t = 10.0; t < 11.0; t += 0.1)
00050   {
00051     ASSERT_EQ(ma.update(ros::Time(t)), ros::Time(t));
00052   }
00053   // skip 0.5 sec.
00054   for (double t = 11.5; t < 12.0; t += 0.1)
00055   {
00056     ASSERT_EQ(ma.update(ros::Time(t)), ros::Time(t));
00057   }
00058 }
00059 
00060 int main(int argc, char **argv)
00061 {
00062   testing::InitGoogleTest(&argc, argv);
00063 
00064   return RUN_ALL_TESTS();
00065 }


urg_stamped
Author(s): Atsushi Watanabe
autogenerated on Thu Jun 6 2019 18:59:51