45int main(
int argc,
char **argv)
54 JParser<> zap(
"Example program to test range operations.");
60 catch(
const exception &error) {
61 FATAL(error.what() << endl);
65 const double xmin = -1.0;
66 const double xmax = +1.0;
67 const double dx = (xmax - xmin) / 10;
74 JRange_t A(JRange_t::DEFAULT_RANGE());
75 JRange_t B(xmin, xmax);
77 for (
double x = xmin; x < xmax + 0.5 * dx; x += dx) {
79 DEBUG(setw(
WIDTH) << left <<
"inside" <<
' ' << B <<
' ' << setw(5) << x <<
' ' << (B(x) ?
"Y" :
"N") << endl);
81 ASSERT(B(x) == (x >= xmin && x <= xmax));
86 DEBUG(setw(
WIDTH) << left <<
"range" <<
' ' << A << endl);
91 for (
double x = xmin - (xmax - xmin); x < xmax + (xmax - xmin) + 0.5 * dx; x += dx) {
95 while (x1 <= xmin) { x1 += (xmax - xmin); }
96 while (x1 > xmax) { x1 -= (xmax - xmin); }
105 const double x1 = -1.0;
106 const double x2 = +0.5;
107 const double x3 = -0.5;
108 const double x4 = +1.0;
113 DEBUG(setw(
WIDTH) << left <<
"join" <<
' ' << A <<
' ' << B <<
" = " << join(A,B) << endl);
116 ASSERT(join(A,B) == JRange_t(x3,x2));
122 const double x1 = -1.0;
123 const double x2 = -0.5;
124 const double x3 = +0.5;
125 const double x4 = +1.0;
130 DEBUG(setw(
WIDTH) << left <<
"combine" <<
' ' << A <<
' ' << B <<
" = " << combine(A,B) << endl);
132 ASSERT(combine(A,B) == JRange_t(x1,x4));
138 const double x1 = -1.0;
139 const double x2 = -0.5;
140 const double x3 = +0.5;
141 const double x4 = +1.0;
146 DEBUG(setw(
WIDTH) << left <<
"add" <<
' ' << A <<
' ' << B <<
" = " << A + B << endl);
148 ASSERT((A + B) == JRange_t(x1+x3,x2+x4));
155 __A__() : value(0.0) {}
156 __A__(
const double value) : value(value) {}
158 double get()
const {
return value; }
165 for (
double x = xmin; x < xmax + 0.5 * dx; x += dx) {
172 A.setRange(make_array(buffer.begin(), buffer.end(), &__A__::value));
173 B.setRange(make_array(buffer.begin(), buffer.end(), &__A__::get));
175 DEBUG(setw(
WIDTH) << left <<
"setRange" <<
' ' << A << endl);
176 DEBUG(setw(
WIDTH) << left <<
"setRange" <<
' ' << B << endl);
178 ASSERT(A == JRange_t(xmin,xmax));
179 ASSERT(B == JRange_t(xmin,xmax));
186 JRange_t B(A.getLowerLimit(), A.getLowerLimit());
187 JRange_t C(A.getUpperLimit(), A.getUpperLimit());