TestIntersection.cxx File Reference
#include <gtest/gtest.h>
#include <intersection.hxx>
#include <list>
Include dependency graph for TestIntersection.cxx:

Go to the source code of this file.

Functions

 TEST (TestIntersection, Intersections)
 

Function Documentation

TEST ( TestIntersection  ,
Intersections   
)

Definition at line 48 of file TestIntersection.cxx.

49 {
50  // Null intersection on empty vectors - empty intersection expected
51  {
52  const Container kEmptyEl = Container();
53  auto intersection = Intersection<Container, Const_IT>
54  (kEmptyEl.begin(), kEmptyEl.end(), kEmptyEl.begin(), kEmptyEl.end());
55  EXPECT_EQ(0, intersection.size());
56  }
57 
58  // Null intersection with one empty vector - empty intersection expected
59  {
60  const Container kEmptyEl = Container();
61  const Container kCollection = Container(10,1);
62  Container intersection = Intersection<Container, Const_IT>
63  (kEmptyEl.begin(), kEmptyEl.end(), kCollection.begin(), kCollection.end());
64  EXPECT_EQ(0, intersection.size());
65  }
66 
67  // Basic run with same collection - intersection as the collection itself expected
68  {
69  const Container kSortedArray(SortedArrayInt, SortedArrayInt + sizeof(SortedArrayInt) / sizeof(Value));
70  Container intersection = Intersection<Container, Const_IT>
71  (kSortedArray.begin(), kSortedArray.end(), kSortedArray.begin(), kSortedArray.end());
72 
73  // The intersection of the same vector should return the same vector
74  Const_IT kIntersectIt = intersection.begin();
75  for (Const_IT it = kSortedArray.begin(); it != kSortedArray.end(); ++it, ++kIntersectIt)
76  EXPECT_EQ(*it, *kIntersectIt);
77  }
78 
79  // Basic run with same collection containing duplicates- intersection as the collection itself expected
80  {
81  const Container kFirstRandom(RandomArrayInt, RandomArrayInt + sizeof(RandomArrayInt) / sizeof(Value));
82  const Container kSecondRandom(RandomArrayInt, RandomArrayInt + sizeof(RandomArrayInt) / sizeof(Value));
83 
84  Container intersection = Intersection<Container, Const_IT>
85  (kFirstRandom.begin(), kFirstRandom.end(), kSecondRandom.begin(), kSecondRandom.end());
86 
87  // The intersection with the copy vector should return the same vector
88  Const_IT kIntersectIt = intersection.begin();
89  for (Const_IT it = kFirstRandom.begin(); it != kFirstRandom.end(); ++it, ++kIntersectIt)
90  EXPECT_EQ(*it, *kIntersectIt);
91  }
92 
93  // Basic run with normal values
94  {
95  const Container kFirstRandom(RandomArrayInt, RandomArrayInt + sizeof(RandomArrayInt) / sizeof(Value));
96  const Container kSecondRandom
97  (RandomArrayInterInt, RandomArrayInterInt + sizeof(RandomArrayInterInt) / sizeof(Value));
98 
99  Container intersection = Intersection<Container, Const_IT>
100  (kFirstRandom.begin(), kFirstRandom.end(), kSecondRandom.begin(), kSecondRandom.end());
101 
102  // Should return [-18, -5, 3, 5, 5] after sorting
103  std::sort(intersection.begin(), intersection.end());
104  EXPECT_EQ(-18, intersection[0]);
105  EXPECT_EQ(-5, intersection[1]);
106  EXPECT_EQ(3, intersection[2]);
107  EXPECT_EQ(5, intersection[3]);
108  EXPECT_EQ(5, intersection[4]);
109  }
110 
111  // String run
112  {
113  std::string intersection = Intersection<std::string, std::string::const_iterator>
114  (OrderedStr.begin(), OrderedStr.end(), RandomStr.begin(), RandomStr.end());
115 
116  // Should return ['a', 'c', 'e', 'g'] after sorting
117  std::sort(intersection.begin(), intersection.end());
118  EXPECT_EQ('a', intersection[0]);
119  EXPECT_EQ('c', intersection[1]);
120  EXPECT_EQ('e', intersection[2]);
121  EXPECT_EQ('g', intersection[3]);
122  }
123 }