#include #include #include "JTools/JCollection.hh" #include "JTools/JElement.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" namespace { /** * Function. * * \param i abscissa value * \return function value */ inline int f1(const int i) { return i*1000; } } /** * \file * * Example program to test JTOOLS::JCollection class. * \author mdejong */ int main(int argc, char **argv) { using namespace std; using namespace JPP; int debug; try { JParser<> zap("Example program to test collection class."); zap['d'] = make_field(debug) = 3; zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << endl); } { typedef JElement2D JElement_t; typedef JCollection JCollection_t; JCollection_t a; JCollection_t b; JCollection_t c; for (int i = 0; i != 5; ++i) { a.put(i, 10 + i); b.put(i, 100 + i); } //b.put(10,10); // throws error at 'a + b' as should be try { c = a + b; c += 1000; c *= 2; c += f1; } catch(const JException& error) { FATAL(error.what() << endl); } for (JCollection_t::const_iterator i = a.begin(), j = b.begin(), k = c.begin(); i != a.end() && j != b.end() && k != c.end(); ++i, ++j, ++k) { DEBUG(setw(4) << k->getY() << " == " << setw(4) << (i->getY() + j->getY() + 1000) * 2 + f1(i->getX()) << endl); ASSERT(k->getY() == (i->getY() + j->getY() + 1000) * 2 + f1(i->getX())); } } { JDistance::precision = 1.0e-10; typedef JElement2D JElement_t; typedef JCollection JCollection_t; JCollection_t a; JCollection_t b; JCollection_t c; a.put(0.0, 0.0); a.put(1.0, 1.0); a.put(2.0, 2.0); b.put(1.0, 1.0); b.put(2.0, 2.0); b.put(3.0, 3.0); c = a + b; ASSERT(c.getY(0) == 0.0); ASSERT(c.getY(1) == 2.0); ASSERT(c.getY(2) == 4.0); ASSERT(c.getY(3) == 3.0); } return 0; }