| 1 |
|
#include "utils/NextCombinationTestCase.hpp" |
| 2 |
|
#include <iostream> |
| 3 |
|
#include <algorithm> |
| 4 |
< |
#include "utils/next_combination.hpp" |
| 4 |
> |
|
| 5 |
|
// Registers the fixture into the 'registry' |
| 6 |
|
CPPUNIT_TEST_SUITE_REGISTRATION( NextCombinationTestCase); |
| 7 |
|
|
| 8 |
+ |
|
| 9 |
|
void NextCombinationTestCase::testNextCombination() { |
| 10 |
< |
std::vector<double> dv; |
| 11 |
< |
std::vector<std::vector<double>::iterator> ic; |
| 10 |
> |
std::vector<int> iv; |
| 11 |
> |
std::vector<std::vector<int>::iterator> ic; |
| 12 |
> |
std::vector<std::vector<int>::iterator>::iterator i; |
| 13 |
> |
iv.push_back(0); |
| 14 |
> |
iv.push_back(1); |
| 15 |
> |
iv.push_back(4); |
| 16 |
> |
std::cout << std::endl; |
| 17 |
|
|
| 18 |
< |
while (next_combination(ic, dv.begin(), dv.end()) { |
| 18 |
> |
std::vector<std::vector<int> > results; |
| 19 |
> |
while (next_combination(ic, iv.begin(), iv.end())) { |
| 20 |
> |
std::vector<int> v; |
| 21 |
> |
for(i = ic.begin();i != ic.end(); ++i) { |
| 22 |
> |
v.push_back(**i); |
| 23 |
> |
} |
| 24 |
> |
results.push_back(v); |
| 25 |
> |
} |
| 26 |
|
|
| 27 |
< |
|
| 27 |
> |
CPPUNIT_ASSERT(results.size() == 7); |
| 28 |
> |
CPPUNIT_ASSERT(results[0][0] == 0 && results[0].size() == 1); |
| 29 |
> |
CPPUNIT_ASSERT(results[1][0] == 1 && results[1].size() == 1); |
| 30 |
> |
CPPUNIT_ASSERT(results[2][0] == 4 && results[2].size() == 1); |
| 31 |
> |
CPPUNIT_ASSERT(results[3][0] == 0 && results[3][1] == 1 && results[3].size() == 2); |
| 32 |
> |
CPPUNIT_ASSERT(results[4][0] == 0 && results[4][1] == 4 && results[4].size() == 2); |
| 33 |
> |
CPPUNIT_ASSERT(results[5][0] == 1 && results[5][1] == 4 && results[5].size() == 2); |
| 34 |
> |
CPPUNIT_ASSERT(results[6][0] == 0 && results[6][1] == 1 && results[6][2] == 4 && results[6].size() == 3); |
| 35 |
> |
|
| 36 |
> |
std::vector<std::string> sv; |
| 37 |
> |
std::vector<std::vector<std::string>::iterator> sic; |
| 38 |
> |
std::vector<std::vector<std::string>::iterator>::iterator j; |
| 39 |
> |
std::vector<std::vector<std::string> > resultStrings; |
| 40 |
> |
std::vector<std::string> resultString; |
| 41 |
> |
sv.push_back("H"); |
| 42 |
> |
sv.push_back("C"); |
| 43 |
> |
sv.push_back("N"); |
| 44 |
> |
|
| 45 |
> |
while (replaceWildCard(sic, sv, resultString)) { |
| 46 |
> |
resultStrings.push_back(resultString); |
| 47 |
|
} |
| 48 |
< |
} |
| 48 |
> |
|
| 49 |
> |
CPPUNIT_ASSERT(resultStrings.size() == 7); |
| 50 |
> |
CPPUNIT_ASSERT(resultStrings[0][0] == "H" && resultStrings[0][1] == "X" && resultStrings[0][2] == "X" && resultStrings[0].size() == 3); |
| 51 |
> |
CPPUNIT_ASSERT(resultStrings[1][0] == "X" && resultStrings[1][1] == "C" && resultStrings[1][2] == "X" && resultStrings[1].size() == 3); |
| 52 |
> |
CPPUNIT_ASSERT(resultStrings[2][0] == "X" && resultStrings[2][1] == "X" && resultStrings[2][2] == "N" && resultStrings[2].size() == 3); |
| 53 |
> |
CPPUNIT_ASSERT(resultStrings[3][0] == "H" && resultStrings[3][1] == "C" && resultStrings[3][2] == "X" && resultStrings[3].size() == 3); |
| 54 |
> |
CPPUNIT_ASSERT(resultStrings[4][0] == "H" && resultStrings[4][1] == "X" && resultStrings[4][2] == "N" && resultStrings[4].size() == 3); |
| 55 |
> |
CPPUNIT_ASSERT(resultStrings[5][0] == "X" && resultStrings[5][1] == "C" && resultStrings[5][2] == "N" && resultStrings[5].size() == 3); |
| 56 |
> |
CPPUNIT_ASSERT(resultStrings[6][0] == "H" && resultStrings[6][1] == "C" && resultStrings[6][2] == "N" && resultStrings[6].size() == 3); |
| 57 |
> |
|
| 58 |
> |
} |
| 59 |
> |
|