Code-Eli  0.3.6
combination_test_suite.hpp
Go to the documentation of this file.
1 /*********************************************************************************
2 * Copyright (c) 2013 David D. Marshall <ddmarsha@calpoly.edu>
3 *
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * David D. Marshall - initial code and implementation
11 ********************************************************************************/
12 
13 #ifndef dm_combination_test_suite_hpp
14 #define dm_combination_test_suite_hpp
15 
16 #include <cmath> // std::pow, std::exp
17 
18 #include <typeinfo> // typeid
19 #include <string> // std::string
20 #include <sstream> // std::stringstream
21 #include <iomanip> // std::setw
22 #include <vector> // std::vector
23 #include <functional> // std::less
24 
26 
27 #include <string>
28 #include <vector>
29 
30 class combination_test_suite : public Test::Suite
31 {
32  protected:
33  void AddTests()
34  {
37  }
38 
39  public:
41  {
42  // add the tests
43  AddTests();
44  }
46  {
47  }
48 
49  private:
50  void string_test()
51  {
52  std::string s = "1234";
53  std::size_t comb_size = 3;
54 
55  TEST_ASSERT(eli::mutil::dm::next_combination(s.begin(),s.begin() + comb_size,s.end()));
56  TEST_ASSERT(s=="1243");
57  TEST_ASSERT(eli::mutil::dm::next_combination(s.begin(),s.begin() + comb_size,s.end()));
58  TEST_ASSERT(s=="1342");
59  TEST_ASSERT(eli::mutil::dm::next_combination(s.begin(),s.begin() + comb_size,s.end()));
60  TEST_ASSERT(s=="2341");
61  TEST_ASSERT(!eli::mutil::dm::next_combination(s.begin(),s.begin() + comb_size,s.end()));
62  TEST_ASSERT(s=="1234");
63  }
64 
65  void vector_test()
66  {
67  size_t i;
68  std::vector<int> s(4);
69  std::size_t comb_size = 3;
70 
71  // set s values
72  for (i=0; i<s.size(); ++i)
73  s[i]=static_cast<int>(i)+1;
74 
75  TEST_ASSERT(eli::mutil::dm::next_combination(s.begin(),s.begin() + comb_size,s.end(), std::less<int>()));
76  TEST_ASSERT((s[0]==1) && (s[1]==2) && (s[2]==4) && (s[3]==3));
77  TEST_ASSERT(eli::mutil::dm::next_combination(s.begin(),s.begin() + comb_size,s.end(), std::less<int>()));
78  TEST_ASSERT((s[0]==1) && (s[1]==3) && (s[2]==4) && (s[3]==2));
79  TEST_ASSERT(eli::mutil::dm::next_combination(s.begin(),s.begin() + comb_size,s.end(), std::less<int>()));
80  TEST_ASSERT((s[0]==2) && (s[1]==3) && (s[2]==4) && (s[3]==1));
81  TEST_ASSERT(!eli::mutil::dm::next_combination(s.begin(),s.begin() + comb_size,s.end(), std::less<int>()));
82  TEST_ASSERT((s[0]==1) && (s[1]==2) && (s[2]==3) && (s[3]==4));
83  }
84 };
85 
86 #endif
87 
~combination_test_suite()
Definition: combination_test_suite.hpp:45
Definition: combination_test_suite.hpp:30
void string_test()
Definition: combination_test_suite.hpp:50
void AddTests()
Definition: combination_test_suite.hpp:33
void vector_test()
Definition: combination_test_suite.hpp:65
bool next_combination(const it__ itb, it__ itk, const it__ ite, comp__ comp)
Definition: combination.hpp:35
combination_test_suite()
Definition: combination_test_suite.hpp:40