interval_intersection_unittest.cpp
Go to the documentation of this file.
1 /**********************************************************************
2  *
3  * Software License Agreement (BSD License)
4  *
5  * Copyright (c) 2009, Willow Garage, Inc.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above
15  * copyright notice, this list of conditions and the following
16  * disclaimer in the documentation and/or other materials provided
17  * with the distribution.
18  * * Neither the name of the Willow Garage nor the names of its
19  * contributors may be used to endorse or promote products derived
20  * from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  *********************************************************************/
35 
36 // Tests interval_intersector.cpp, but it does not test with concurrency.
37 
38 
39 #include <vector>
40 #include <string>
41 #include <sstream>
42 #include <gtest/gtest.h>
43 
44 #include "calibration_msgs/Interval.h"
46 
47 using namespace std;
48 using namespace interval_intersection;
49 
50 stringstream output_stream;
51 typedef boost::function<void (const calibration_msgs::IntervalConstPtr &)> Input;
52 vector<Input> inputs;
53 
54 void publish(const calibration_msgs::Interval &interval)
55 {
56  //cout << "publishing" << endl;
57  output_stream << "[" << interval.start << ", " << interval.end << "] ";
58 }
59 
60 void input_interval(ros::Time start, ros::Time end, int input_num) {
61  boost::shared_ptr<calibration_msgs::Interval> interval(new calibration_msgs::Interval());
62  interval->start = start;
63  interval->end = end;
64  //cout << "inputing" << endl;
65  inputs[input_num](interval);
66 }
67 
68 TEST(Intersection, testCase1)
69 {
70  // Creat IntervalIntersector and hook its inputs and output
71  IntervalIntersector intersector(&publish);
72  int n = 3;
73  for (int i=0; i<n; i++) {
74  inputs.push_back(intersector.getNewInputStream());
75  }
76 
77  // Feed it some input
78  typedef ros::Time T;
79  input_interval(T(10), T(20), 0);
80  input_interval(T(2), T(16), 1);
81  input_interval(T(8), T(21), 2);
82  input_interval(T(23), T(30), 0);
83  input_interval(T(6), T(25), 1);
84  input_interval(T(18), T(28), 2);
85 
86  string correct_answer = "[10.000000000, 16.000000000] [10.000000000, 20.000000000] [23.000000000, 23.000000000] [23.000000000, 25.000000000] ";
87  EXPECT_EQ(output_stream.str(), correct_answer);
88 }
89 
90 
91 // Main
92 int main(int argc, char **argv){
93  testing::InitGoogleTest(&argc, argv);
94  return RUN_ALL_TESTS();
95 }
96 
97 
vector< Input > inputs
boost::function< void(const calibration_msgs::IntervalConstPtr &)> getNewInputStream()
stringstream output_stream
int main(int argc, char **argv)
TEST(Intersection, testCase1)
boost::function< void(const calibration_msgs::IntervalConstPtr &)> Input
void publish(const calibration_msgs::Interval &interval)
void input_interval(ros::Time start, ros::Time end, int input_num)


interval_intersection
Author(s): Romain Thibaux
autogenerated on Thu Jun 6 2019 19:17:22