#include #include #include #include #include "JTools/JRouter.hh" #include "JLang/JObjectID.hh" #include "JIO/JFileStreamIO.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" /** * \file * * Example program to test JTOOLS::JRouter class. * \author mdejong */ int main(int argc, char **argv) { using namespace std; using namespace JPP; int debug; try { JParser<> zap("Example program to test router."); zap['d'] = make_field(debug) = 3; zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << endl); } vector buffer; JRouter router(-1); { buffer.clear(); router.clear(); for (int i = 1; i <= 1000000; i *= 10) { buffer.push_back(i); } for (size_t i = 0; i != buffer.size(); ++i) { router.put(buffer[i], i); } ASSERT(!router.in_range(0), "Test of router range."); ASSERT(!router.has(2), "Test of router has."); for (int i = 1; i <= 1000000; i *= 10) { ASSERT(router.in_range(i), "Test of router range."); ASSERT(router.has(i), "Test of router has."); ASSERT(buffer[router.get(i)] == i, "Test of router lookup."); } } { buffer.clear(); router.clear(); for (int i = 1000000; i >= 1; i /= 10) { buffer.push_back(i); } for (size_t i = 0; i != buffer.size(); ++i) { router.put(buffer[i], i); } ASSERT(!router.in_range(0), "Test of router range."); ASSERT(!router.has(2), "Test of router has."); for (int i = 1000000; i >= 1; i /= 10) { ASSERT(router.in_range(i), "Test of router range."); ASSERT(router.has(i), "Test of router has."); ASSERT(buffer[router.get(i)] == i, "Test of router."); } } return 0; }