deflated_unittest.cpp
Go to the documentation of this file.
00001 /*********************************************************************
00002 * Software License Agreement (BSD License)
00003 *
00004 *  Copyright (c) 2008, Willow Garage, Inc.
00005 *  All rights reserved.
00006 *
00007 *  Redistribution and use in source and binary forms, with or without
00008 *  modification, are permitted provided that the following conditions
00009 *  are met:
00010 *
00011 *   * Redistributions of source code must retain the above copyright
00012 *     notice, this list of conditions and the following disclaimer.
00013 *   * Redistributions in binary form must reproduce the above
00014 *     copyright notice, this list of conditions and the following
00015 *     disclaimer in the documentation and/or other materials provided
00016 *     with the distribution.
00017 *   * Neither the name of the Willow Garage nor the names of its
00018 *     contributors may be used to endorse or promote products derived
00019 *     from this software without specific prior written permission.
00020 *
00021 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029 *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031 *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032 *  POSSIBILITY OF SUCH DAMAGE.
00033 *********************************************************************/
00034 
00035 #include <gtest/gtest.h>
00036 #include <settlerlib/deflated.h>
00037 
00038 using namespace std;
00039 using namespace settlerlib;
00040 
00041 static const double eps = 1e-6;
00042 
00043 TEST(Deflated, easy1)
00044 {
00045   Deflated before, after;
00046   before.header.stamp = ros::Time(0,0);
00047   after.header.stamp = ros::Time(10,0);
00048 
00049   before.channels_.resize(2);
00050   after.channels_.resize(2);
00051 
00052   before.channels_[0] = 0;
00053   after.channels_[0]  = 100;
00054 
00055   before.channels_[1] = 1000;
00056   after.channels_[1]  = 0;
00057 
00058   vector<double> middle;
00059   bool success;
00060   success = Deflated::interp(before, after, ros::Time(0,0), middle);
00061   EXPECT_TRUE(success);
00062   EXPECT_NEAR(middle[0], 0, eps);
00063   EXPECT_NEAR(middle[1], 1000, eps);
00064 
00065   success = Deflated::interp(before, after, ros::Time(1,0), middle);
00066   EXPECT_TRUE(success);
00067   EXPECT_NEAR(middle[0], 10, eps);
00068   EXPECT_NEAR(middle[1], 900, eps);
00069 
00070   success = Deflated::interp(before, after, ros::Time(10,0), middle);
00071   EXPECT_TRUE(success);
00072   EXPECT_NEAR(middle[0], 100, eps);
00073   EXPECT_NEAR(middle[1], 0, eps);
00074 
00075   EXPECT_TRUE(true);
00076 }
00077 
00078 TEST(Deflated, zeroInterval)
00079 {
00080   Deflated before, after;
00081   before.header.stamp = ros::Time(10,0);
00082   after.header.stamp  = ros::Time(10,0);
00083   before.channels_.resize(2);
00084   after.channels_.resize(2);
00085 
00086   before.channels_[0] = 10;
00087   after.channels_[0]  = 10;
00088 
00089   before.channels_[1] = 20;
00090   after.channels_[1]  = 20;
00091 
00092   vector<double> middle;
00093   bool success;
00094   success = Deflated::interp(before, after, ros::Time(10,0), middle);
00095   EXPECT_TRUE(success);
00096 
00097   EXPECT_NEAR(middle[0], 10, eps);
00098   EXPECT_NEAR(middle[1], 20, eps);
00099 }
00100 
00101 TEST(Deflated, sizeMismatch)
00102 {
00103   Deflated before, after;
00104   before.header.stamp = ros::Time(0,0);
00105   after.header.stamp = ros::Time(10,0);
00106   before.channels_.resize(2);
00107   after.channels_.resize(3);
00108 
00109   vector<double> middle;
00110   bool success;
00111   success = Deflated::interp(before, after, ros::Time(0,0), middle);
00112   EXPECT_FALSE(success);
00113 }
00114 
00115 TEST(Deflated, badIntervals)
00116 {
00117   Deflated before, after;
00118   before.channels_.resize(3);
00119   after.channels_.resize(3);
00120 
00121   vector<double> middle;
00122 
00123   before.header.stamp = ros::Time(10,0);
00124   after.header.stamp =  ros::Time(20,0);
00125   EXPECT_FALSE(Deflated::interp(before, after, ros::Time( 5,0), middle));
00126   EXPECT_TRUE( Deflated::interp(before, after, ros::Time(15,0), middle));
00127   EXPECT_FALSE(Deflated::interp(before, after, ros::Time(25,0), middle));
00128 
00129   before.header.stamp = ros::Time(20,0);
00130   after.header.stamp  = ros::Time(10,0);
00131   EXPECT_FALSE(Deflated::interp(before, after, ros::Time( 5,0), middle));
00132   EXPECT_FALSE(Deflated::interp(before, after, ros::Time(15,0), middle));
00133   EXPECT_FALSE(Deflated::interp(before, after, ros::Time(25,0), middle));
00134 }
00135 
00136 
00137 
00138 int main(int argc, char **argv){
00139   testing::InitGoogleTest(&argc, argv);
00140   return RUN_ALL_TESTS();
00141 }


settlerlib
Author(s): Vijay Pradeep
autogenerated on Sat Jun 8 2019 19:41:50