#include #include #include #include "JTools/JCombinatorics.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" /** * \file * Example program to test combinatorics of pairs of indices (class JTOOLS::JCombinatorics). * \author mdejong */ int main(int argc, char **argv) { using namespace std; int numberOfElements; int debug; try { JParser<> zap("Example program to test combinatorics of pairs of indices."); zap['n'] = make_field(numberOfElements); zap['d'] = make_field(debug) = 1; zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << endl); } using namespace JPP; if (numberOfElements <= 0) { FATAL("Number of elements " << numberOfElements << " <= 0" << endl); } JCombinatorics combinatorics(numberOfElements); int n = 0; for (int i = 0; i != (int) combinatorics.getNumberOfPairs(); ++i) { STATUS("event: " << setw(8) << i << '\r'); DEBUG(endl); JCombinatorics::pair_type pair = combinatorics.getPair(i); if (i != combinatorics.getIndex(pair.first, pair.second)) { ++n; ERROR(endl << ' ' << setw(3) << pair.first << ' ' << setw(3) << pair.second << ' ' << setw(4) << combinatorics.getIndex(pair.first, pair.second) << endl); } } DEBUG(endl); NOTICE("Number of elements " << setw(8) << right << numberOfElements << endl); NOTICE("Number of pairs " << setw(8) << right << combinatorics.getNumberOfPairs() << endl); NOTICE("Number of errors " << setw(8) << right << n << endl); ASSERT(n == 0); }