TestCombinations.cxx File Reference
#include <gtest/gtest.h>
#include <combinations.hxx>
Include dependency graph for TestCombinations.cxx:

Go to the source code of this file.

Functions

 TEST (TestCombinations, Combinations)
 

Function Documentation

TEST ( TestCombinations  ,
Combinations   
)

Definition at line 37 of file TestCombinations.cxx.

38 {
39  // Empty vector - no combinations
40  {
41  const Container kEmptyCollection = Container();
42  List combinations = Combinations<Container, Const_IT>(kEmptyCollection.begin(), kEmptyCollection.end());
43  EXPECT_EQ(static_cast<size_t>(0), combinations.size());
44  }
45 
46  // Inversed iterator - no combinations
47  {
48  const Container kUnicCollection = Container(1, 10);
49  List combinations = Combinations<Container, Const_IT>(kUnicCollection.end(), kUnicCollection.begin());
50  EXPECT_EQ(static_cast<size_t>(0), combinations.size());
51  }
52 
53  // Unic element vector - Unique object returned as combinations
54  {
55  const Container kUnicCollection = Container(1, 10);
56  List combinations = Combinations<Container, Const_IT>(kUnicCollection.begin(), kUnicCollection.end());
57  EXPECT_EQ(static_cast<size_t>(1), combinations.size());
58  EXPECT_EQ(static_cast<size_t>(1), combinations.begin()->size());
59  EXPECT_EQ(10, *(combinations.begin()->begin()));
60  }
61 
62  // Run with value 2, 1, 3
63  {
64  const Container kSmallArray(SmallIntArray, SmallIntArray + sizeof(SmallIntArray) / sizeof(Value));
65  List combinations = Combinations<Container, Const_IT>(kSmallArray.begin(), kSmallArray.end());
66  EXPECT_EQ(static_cast<size_t>(7), combinations.size());
67 
68  int countEls = 0;
69  for (List::const_iterator it = combinations.begin(); it != combinations.end(); ++it)
70  countEls += static_cast<int>(it->size());
71  EXPECT_EQ(12, countEls);
72  //@TODO check sequence by sequence? (non ordered)
73  }
74 
75  // String run
76  {
77  const std::string abcStr = "abc";
78  std::list<std::string> combinations =
79  Combinations<std::string, std::string::const_iterator>(abcStr.begin(), abcStr.end());
80  EXPECT_EQ(static_cast<size_t>(7), combinations.size());
81 
82  int countEls = 0;
83  for (std::list<std::string>::const_iterator it = combinations.begin(); it != combinations.end(); ++it)
84  countEls += static_cast<int>(it->size());
85  EXPECT_EQ(12, countEls);
86  //@TODO check sequence by sequence? (non ordered)
87  }
88 }