interval_intersection_unittest.cpp
Go to the documentation of this file.
00001 /**********************************************************************
00002  *
00003  * Software License Agreement (BSD License)
00004  *
00005  *  Copyright (c) 2009, Willow Garage, Inc.
00006  *  All rights reserved.
00007  *
00008  *  Redistribution and use in source and binary forms, with or without
00009  *  modification, are permitted provided that the following conditions
00010  *  are met:
00011  *
00012  *   * Redistributions of source code must retain the above copyright
00013  *     notice, this list of conditions and the following disclaimer.
00014  *   * Redistributions in binary form must reproduce the above
00015  *     copyright notice, this list of conditions and the following
00016  *     disclaimer in the documentation and/or other materials provided
00017  *     with the distribution.
00018  *   * Neither the name of the Willow Garage nor the names of its
00019  *     contributors may be used to endorse or promote products derived
00020  *     from this software without specific prior written permission.
00021  *
00022  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00025  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00026  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00027  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00028  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00029  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00030  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00032  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00033  *  POSSIBILITY OF SUCH DAMAGE.
00034  *********************************************************************/
00035 
00036 // Tests interval_intersector.cpp, but it does not test with concurrency.
00037 
00038 
00039 #include <vector>
00040 #include <string>
00041 #include <sstream>
00042 #include <gtest/gtest.h>
00043 
00044 #include "calibration_msgs/Interval.h"
00045 #include "interval_intersection/interval_intersection.hpp"
00046 
00047 using namespace std;
00048 using namespace interval_intersection;
00049 
00050 stringstream output_stream;
00051 typedef boost::function<void (const calibration_msgs::IntervalConstPtr &)> Input;
00052 vector<Input> inputs;
00053 
00054 void publish(const calibration_msgs::Interval &interval)
00055 {
00056   //cout << "publishing" << endl;
00057   output_stream << "[" << interval.start << ", " << interval.end << "] ";
00058 }
00059 
00060 void input_interval(ros::Time start, ros::Time end, int input_num) {
00061   boost::shared_ptr<calibration_msgs::Interval> interval(new calibration_msgs::Interval());
00062   interval->start = start;
00063   interval->end = end;
00064   //cout << "inputing" << endl;
00065   inputs[input_num](interval);
00066 }
00067 
00068 TEST(Intersection, testCase1)
00069 {
00070   // Creat IntervalIntersector and hook its inputs and output
00071   IntervalIntersector intersector(&publish);
00072   int n = 3;
00073   for (int i=0; i<n; i++) {
00074     inputs.push_back(intersector.getNewInputStream());
00075   }
00076 
00077   // Feed it some input
00078   typedef ros::Time T;
00079   input_interval(T(10), T(20), 0);
00080   input_interval(T(2), T(16), 1);
00081   input_interval(T(8), T(21), 2);
00082   input_interval(T(23), T(30), 0);
00083   input_interval(T(6), T(25), 1);
00084   input_interval(T(18), T(28), 2);
00085 
00086   string correct_answer = "[10.000000000, 16.000000000] [10.000000000, 20.000000000] [23.000000000, 23.000000000] [23.000000000, 25.000000000] ";
00087   EXPECT_EQ(output_stream.str(), correct_answer);
00088 }
00089 
00090 
00091 // Main
00092 int main(int argc, char **argv){
00093   testing::InitGoogleTest(&argc, argv);
00094   return RUN_ALL_TESTS();
00095 }
00096 
00097 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Friends


interval_intersection
Author(s): Romain Thibaux
autogenerated on Thu Aug 15 2013 10:15:57