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

Go to the source code of this file.

Functions

 TEST (TestCore, Permutations)
 

Function Documentation

TEST ( TestCore  ,
Permutations   
)

Definition at line 35 of file TestPermutations.cxx.

36 {
37  // Empty vector - no permutations
38  {
39  const Container kEmptyCollection = Container();
40  auto permutations = Permutations<Container, Const_IT>(kEmptyCollection.begin(), kEmptyCollection.end());
41  EXPECT_EQ(0, permutations.size());
42  }
43 
44  // Inversed iterator - no permutations
45  {
46  const Container kUnicCollection = Container(1,10);
47  auto permutations = Permutations<Container, Const_IT>(kUnicCollection.end(), kUnicCollection.begin());
48  EXPECT_EQ(0, permutations.size());
49  }
50 
51  // Unic element vector - Unique object returned as permutation
52  {
53  const Container kUnicCollection = Container(1,10);
54  auto permutations = Permutations<Container, Const_IT>(kUnicCollection.begin(), kUnicCollection.end());
55  EXPECT_EQ(1, permutations.size());
56  EXPECT_EQ(1, permutations.begin()->size());
57  EXPECT_EQ(10, *(permutations.begin()->begin()));
58  }
59 
60  // Same elements vector - n! list of n equivalent elements
61  {
62  const Container kSameElCollection = Container(3,10);
63  auto permutations = Permutations<Container, Const_IT>(kSameElCollection.begin(), kSameElCollection.end());
64  EXPECT_EQ(6, permutations.size());
65  for (auto it = permutations.begin(); it != permutations.end(); ++it)
66  {
67  EXPECT_EQ(3, it->size());
68  for (Container::const_iterator itEl = it->begin(); itEl != it->end(); ++itEl)
69  EXPECT_EQ(10, *itEl);
70  }
71  }
72 
73  // Run with value 2, 1, 3
74  {
75  const Container kSmallArray(SmallIntArray, SmallIntArray + sizeof(SmallIntArray) /
76  sizeof(Container::value_type));
77  auto permutations = Permutations<Container, Const_IT>(kSmallArray.begin(), kSmallArray.end());
78  EXPECT_EQ(6, permutations.size());
79  for (auto it = permutations.begin(); it != permutations.end(); ++it)
80  EXPECT_EQ(3, it->size());
81  }
82 
83  // String run
84  {
85  const std::string abcStr = "abc";
86  std::list<std::string> permutations =
87  Permutations<std::string, std::string::const_iterator>(abcStr.begin(), abcStr.end());
88  EXPECT_EQ(6, permutations.size());
89  for (std::list<std::string>::const_iterator it = permutations.begin(); it != permutations.end(); ++it)
90  EXPECT_EQ(3, it->size());
91  }
92 }