46{
   49 
   51 
   52  try {
   53 
   54    JParser<> zap(
"Example program to test range operations.");
 
   55 
   57 
   58    zap(argc, argv);
   59  }
   60  catch(const exception &error) {
   61    FATAL(error.what() << endl);
 
   62  }
   63 
   64 
   65  const double xmin = -1.0;
 
   66  const double xmax = +1.0;
 
   67  const double dx   = (
xmax - 
xmin) / 10;
 
   68 
   70 
   71  {
   73 
   74    JRange_t A(JRange_t::DEFAULT_RANGE());
   75    JRange_t B(xmin, xmax);
   76 
   77    for (
double x = xmin; 
x < 
xmax + 0.5 * dx; 
x += dx) {
 
   78      
   79      DEBUG(setw(
WIDTH) << left << 
"inside"   << 
' ' << B << 
' ' << setw(5) << x << 
' ' << (B(x) ? 
"Y" : 
"N") << endl);
 
   80 
   81      ASSERT(B(x) == (x >= xmin && x <= xmax));
 
   82 
   83      A.include(x);
   84    }
   85 
   86    DEBUG(setw(
WIDTH) << left << 
"range"    << 
' ' << A << endl);
 
   87 
   89 
   90 
   91    for (
double x = xmin - (xmax - xmin); 
x < 
xmax + (
xmax - 
xmin) + 0.5 * dx; 
x += dx) {
 
   92    
   94 
   95      while (x1 <= xmin) { x1 += (
xmax - 
xmin); }
 
   96      while (x1 >  xmax) { x1 -= (
xmax - 
xmin); }
 
   97 
   99    }
  100  }
  101  
  102  {
  104 
  105    const double x1 = -1.0;
  106    const double x2 = +0.5;
  107    const double x3 = -0.5;
  108    const double x4 = +1.0;
  109 
  110    JRange_t A(x1, x2);
  111    JRange_t B(x3, x4);
  112 
  113    DEBUG(setw(
WIDTH) << left << 
"join"     << 
' ' << A << 
' ' << B << 
" = " << join(A,B)    << endl);
 
  114 
  116    ASSERT(join(A,B) == JRange_t(x3,x2));
 
  117  } 
  118 
  119  {
  121 
  122    const double x1 = -1.0;
  123    const double x2 = -0.5;
  124    const double x3 = +0.5;
  125    const double x4 = +1.0;
  126 
  127    JRange_t A(x1, x2);
  128    JRange_t B(x3, x4);
  129 
  130    DEBUG(setw(
WIDTH) << left << 
"combine"  << 
' ' << A << 
' ' << B << 
" = " << 
combine(A,B) << endl);
 
  131 
  133  } 
  134 
  135  {
  137 
  138    const double x1 = -1.0;
  139    const double x2 = -0.5;
  140    const double x3 = +0.5;
  141    const double x4 = +1.0;
  142 
  143    JRange_t A(x1, x2);
  144    JRange_t B(x3, x4);
  145 
  146    DEBUG(setw(
WIDTH) << left << 
"add"      << 
' ' << A << 
' ' << B << 
" = " << A + B        << endl);
 
  147 
  148    ASSERT((A + B) == JRange_t(x1+x3,x2+x4));
 
  149  } 
  150 
  151  {
  153 
  154    struct __A__ {
  155      __A__() : value(0.0) {}
  156      __A__(const double value) : value(value) {}
  157 
  158      double get() const { return value; }
  159 
  160      double value;
  161    };
  162 
  164 
  165    for (
double x = xmin; 
x < 
xmax + 0.5 * dx; 
x += dx) {
 
  166      buffer.push_back(x);
  167    }
  168 
  169    JRange_t A;
  170    JRange_t B;
  171 
  172    A.setRange(make_array(buffer.begin(), buffer.end(), &__A__::value));
  173    B.setRange(make_array(buffer.begin(), buffer.end(), &__A__::get));
  174 
  175    DEBUG(setw(
WIDTH) << left << 
"setRange"  << 
' ' << A << endl);
 
  176    DEBUG(setw(
WIDTH) << left << 
"setRange"  << 
' ' << B << endl);
 
  177 
  178    ASSERT(A == JRange_t(xmin,xmax));
 
  179    ASSERT(B == JRange_t(xmin,xmax));
 
  180  }
  181 
  182  {
  184 
  185    JRange_t A(1,100);
  186    JRange_t B(A.getLowerLimit(), A.getLowerLimit());
  187    JRange_t C(A.getUpperLimit(), A.getUpperLimit());
  188 
  192  }
  193 
  194  return 0;
  195}
#define DEBUG(A)
Message macros.
 
#define ASSERT(A,...)
Assert macro.
 
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
 
Utility class to parse command line options.
 
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
 
Auxiliary data structure for alignment of data.