head     2.0;
branch   ;
access   ;
symbols  ;
locks    ; strict;
comment  @@;


2.0
date     92.07.27.06.23.11;  author fischer;  state Exp;
branches ;
next     1.3;

1.3
date     92.07.01.18.08.31;  author fischer;  state Exp;
branches ;
next     1.2;

1.2
date     92.06.30.07.57.03;  author fischer;  state Exp;
branches ;
next     1.1;

1.1
date     92.06.29.07.31.14;  author fischer;  state Exp;
branches ;
next     ;


desc
@test for rounding functions on 1-d points.
@


2.0
log
@cleaned up for IntPoint/FloatPoint (only the later makes
sense now.
@
text
@// Emacs: -*- C++ -*-

#include "FloatPoint.h"
#include <ACG.h>

#define TBL_SIZE 40

int main(int argc, char**argv)
{
    void	print_rounding_table(FloatPoint[], int);
    FloatPoint	make_random_point(int, int, int, ACG&); 
    ACG		generator(69, 96);
    FloatPoint  points[TBL_SIZE];
    
    for (int i = 0; i < TBL_SIZE; i++) 
	points[i] = make_random_point(1, -2, +2, generator);

    
    print_rounding_table(points, TBL_SIZE);
}


void
print_rounding_table(FloatPoint point_array[], int number_points)
{
//  Run all rounding ops on an array of points, printing a table
    
    cout << "aint()\t"
	 << "anint()\t"
	 << "ceil()\t"
	 << "floor()\t"
	 << "rint()\t"
	 << "irint()\t"
	 << "nint()\t"
	 << "trunc()\t"
	 << "for Point\n";
    
    for (int i = 0; i < number_points; i++ ) {

	cout << aint(point_array[i]); 	cout << "\t";
	cout << anint(point_array[i]); 	cout << "\t";
	cout << ceil(point_array[i]); 	cout << "\t";
	cout << floor(point_array[i]); 	cout << "\t";
	cout << rint(point_array[i]); 	cout << "\t";
	cout << irint(point_array[i]); 	cout << "\t";
	cout << nint(point_array[i]); 	cout << "\t";
	cout << trunc(point_array[i]); 	cout << "\t";
	cout << point_array[i] << "\n";


    }
}


FloatPoint
make_random_point(int dimensions, int bottom, int top, ACG& gen)
{
    int   range;

    if (top < bottom) {
	int temp = top;
	top = bottom;
	bottom = temp;
    }
    range = top - bottom + 1;    

    switch (dimensions) {
    case 0:
	return FloatPoint();
    case 1:
	return FloatPoint(bottom +  gen.asFloat() * range);
    case 2:
	return FloatPoint(bottom +  gen.asFloat() * range,
			  bottom +  gen.asFloat() * range);
    case 3:
	return FloatPoint(bottom +  gen.asFloat() * range,
			  bottom +  gen.asFloat() * range,
			  bottom +  gen.asFloat() * range);
    case 4:
	return FloatPoint(bottom +  gen.asFloat() * range,
			  bottom +  gen.asFloat() * range,
			  bottom +  gen.asFloat() * range,
			  bottom +  gen.asFloat() * range);
    case 5:
	return FloatPoint(bottom +  gen.asFloat() * range,
			  bottom +  gen.asFloat() * range,
			  bottom +  gen.asFloat() * range,
			  bottom +  gen.asFloat() * range,
			  bottom +  gen.asFloat() * range);
    default:
	return FloatPoint(0.0, 0.0, 0.0, 0.0, 0.0);    
    }
}

@


1.3
log
@modified to use friend functions, now that thoth's fixed em.
@
text
@d3 1
a3 1
#include <Point.h>
d10 7
a16 3
    void	print_rounding_table(Point[], int);
    void	make_INTEGER_points(Point[], int, ACG&);             // random integer valued
    void	make_REAL_points(Point[], int, ACG&);                // random integer valued
d18 2
a19 10
    ACG		generator(69, 96);    
    Point       points_list[TBL_SIZE];

    cout <<  "\n\nINTEGER Points:\n";
    make_INTEGER_points(points_list, TBL_SIZE, generator);
    print_rounding_table(points_list, TBL_SIZE);

    cout <<  "\n\nREAL Points:\n";
    make_REAL_points(points_list, TBL_SIZE, generator);
    print_rounding_table(points_list, TBL_SIZE);
a21 4
void
make_REAL_points(Point point_array[], int number_points, ACG& generator)
{
    Point	make_random_point(int, int, int, NumericType, ACG&); // dimension, bottom, top, type
a22 4
    for (int i = 0; i < number_points; i++) 
	point_array[i] = make_random_point(1, -2, +2, REAL, generator);
}	

d24 1
a24 1
make_INTEGER_points(Point point_array[], int number_points, ACG& generator)
a25 10
    Point	make_random_point(int, int, int, NumericType, ACG&); // dimension, bottom, top, type

    for (int i = 0; i < number_points; i++) 
	point_array[i] = make_random_point(1, -2, +2, INTEGER, generator);
}	


void
print_rounding_table(Point point_array[], int number_points)
{
a27 2
    void my_print(Point&);
    
d40 8
a47 18
// 	my_print((point_array[i]).aint()); 	cout << "\t";
// 	my_print((point_array[i]).anint()); 	cout << "\t";
// 	my_print((point_array[i]).ceil()); 	cout << "\t";
// 	my_print((point_array[i]).floor()); 	cout << "\t";
// 	my_print((point_array[i]).rint()); 	cout << "\t";
// 	my_print((point_array[i]).irint()); 	cout << "\t";
// 	my_print((point_array[i]).nint()); 	cout << "\t";
// 	my_print((point_array[i]).trunc()); 	cout << "\t";
// 	cout << point_array[i] << "\n";

	my_print(aint(point_array[i])); 	cout << "\t";
	my_print(anint(point_array[i])); 	cout << "\t";
	my_print(ceil(point_array[i])); 	cout << "\t";
	my_print(floor(point_array[i])); 	cout << "\t";
	my_print(rint(point_array[i])); 	cout << "\t";
	my_print(irint(point_array[i])); 	cout << "\t";
	my_print(nint(point_array[i])); 	cout << "\t";
	my_print(trunc(point_array[i])); 	cout << "\t";
d55 2
a56 2
void
my_print (Point& p)
a57 17
    switch (p.type()) {
    case REAL:
	cout << "R";
	break;
    case INTEGER:
	cout << "I";
	break;
    default:
	cout << "?";
    }
    cout << p;
}

Point
make_random_point(int dimensions, int bottom, int top, NumericType type, ACG& gen)
{
    Coord coordinate;
d67 25
a91 59
    if (type == REAL)
      switch (dimensions) {
      case 0:
          return Point();
      case 1:
          coordinate = (bottom +  gen.asFloat() * range);
          return Point(coordinate);
      case 2:
          return Point(bottom +  gen.asFloat() * range,
                       bottom +  gen.asFloat() * range);
      case 3:
          return Point(bottom +  gen.asFloat() * range,
                       bottom +  gen.asFloat() * range,
                       bottom +  gen.asFloat() * range);
      case 4:
          return Point(bottom +  gen.asFloat() * range,
                       bottom +  gen.asFloat() * range,
                       bottom +  gen.asFloat() * range,
                       bottom +  gen.asFloat() * range);
      case 5:
          return Point(bottom +  gen.asFloat() * range,
                       bottom +  gen.asFloat() * range,
                       bottom +  gen.asFloat() * range,
                       bottom +  gen.asFloat() * range,
                       bottom +  gen.asFloat() * range);
      default:
          return Point(0.0, 0.0, 0.0, 0.0, 0.0);    // shouldn't happen
      }
    else if (type == INTEGER)
      switch (dimensions) {
      case 0:
          return Point();
      case 1:
          coordinate = (bottom + int(gen.asFloat() * range));
          return Point(coordinate);
      case 2:
          return Point(bottom +  int(gen.asFloat() * range),
                       bottom +  int(gen.asFloat() * range));
      case 3:
          return Point(bottom +  int(gen.asFloat() * range),
                       bottom +  int(gen.asFloat() * range),
                       bottom +  int(gen.asFloat() * range));
      case 4:
          return Point(bottom +  int(gen.asFloat() * range),
                       bottom +  int(gen.asFloat() * range),
                       bottom +  int(gen.asFloat() * range),
                       bottom +  int(gen.asFloat() * range));
      case 5:
          return Point(bottom +  int(gen.asFloat() * range),
                       bottom +  int(gen.asFloat() * range),
                       bottom +  int(gen.asFloat() * range),
                       bottom +  int(gen.asFloat() * range),
                       bottom +  int(gen.asFloat() * range));
      default:
          return Point(0, 0, 0, 0, 0);    // shouldn't happen
      }
    else {
      cout << "random_point: NumericType " << type << " is not one of REAL, INTEGER\n";
      exit(1);
a92 1
    return Point(-1, -1, -1, -1, -1);    // can\'t happen, but make compiler shut up.
@


1.2
log
@changed format to more readable, ``R'' and ``I'' print first.
@
text
@d55 1
a55 1
	 << "floar()\t"
d63 19
a81 9
	
	my_print((point_array[i]).aint()); 	cout << "\t";
	my_print((point_array[i]).anint()); 	cout << "\t";
	my_print((point_array[i]).ceil()); 	cout << "\t";
	my_print((point_array[i]).floor()); 	cout << "\t";
	my_print((point_array[i]).rint()); 	cout << "\t";
	my_print((point_array[i]).irint()); 	cout << "\t";
	my_print((point_array[i]).nint()); 	cout << "\t";
	my_print((point_array[i]).trunc()); 	cout << "\t";
a82 10

// 	my_print(aint(point_array[i])); 	cout << "\t";
// 	my_print(anint(point_array[i])); 	cout << "\t";
// 	my_print(ceil(point_array[i])); 	cout << "\t";
// 	my_print(floor(point_array[i])); 	cout << "\t";
// 	my_print(rint(point_array[i])); 	cout << "\t";
// 	my_print(irint(point_array[i])); 	cout << "\t";
// 	my_print(nint(point_array[i])); 	cout << "\t";
// 	my_print(trunc(point_array[i])); 	cout << "\t";
//      cout << point_array[i] << "\n";
@


1.1
log
@Initial revision
@
text
@d17 4
a23 4

    cout <<  "\n\nINTEGER Points:\n";
    make_INTEGER_points(points_list, TBL_SIZE, generator);
    print_rounding_table(points_list, TBL_SIZE);
d72 1
a72 1
	my_print(point_array[i]); 	        cout << "\n";
d82 1
a82 1
// 	my_print(point_array[i]); 	        cout << "\n";
d84 1
a91 1
    cout << p;
d102 1
@
