head	1.3;
access;
symbols
	r2_1:1.3
	r2_0:1.3
	r1_1_beta:1.3
	r0_11:1.3;
locks; strict;
comment	@//@;


1.3
date	94.04.27.18.26.09;	author rjj;	state Exp;
branches;
next	1.2;

1.2
date	93.11.11.01.17.31;	author rjj;	state Exp;
branches;
next	1.1;

1.1
date	92.12.16.02.15.17;	author rjj;	state Exp;
branches;
next	;


desc
@Initial test program for IA_Deque
@


1.3
log
@Changed T operator[](int) const  to operator().
@
text
@// -*- C++ -*-
//      Copyright 1993, Center for Computer Vision and Visualization,
//      University of Florida.  All rights reserved.

#include "ia.h"
#include "Deque.h"

static char test_deque_c_rcsid[] = "$Id: test-deque.c,v 1.2 1993/11/11 01:17:31 rjj Exp rjj $";

// $Log: test-deque.c,v $
//Revision 1.2  1993/11/11  01:17:31  rjj
//Added new tests for op== and op!=.
//
//Revision 1.1  92/12/16  02:15:17  rjj
//Initial revision
//

//////////////////////////////////////////////////////////////////////////////
// Macros 
//////////////////////////////////////////////////////////////////////////////
#define frst(dstr,d) cout << "\n" << dstr << ".first() = " << d.first()

    int dint;
#define prtd(dstr, d) \
    cout << "\n" << dstr << "\t<"; \
    for (dint=0; dint < d.length();  dint++ ) \
	{ cout << d[dint] << " "; }; \
    cout << ">";

#define dilen(k) \
    cout << "\ndi" << k << ".length() = " ; \
    cout << di##k.length();

#define outd(dstr, valstr) \
    cout << "\n" << dstr << "\t" << valstr;


main() {
    IA::abort_on_throw = 0;           // Don\'t abort on errors.

    cout << "\nAllocating deques....\n";
    IA_Deque<int> di;
    IA_Deque<int> di0(0);
    IA_Deque<int> di1(10);
    IA_Deque<int> di2(20, 21);
    IA_Deque<int> di3(30, 31, 32);
    IA_Deque<int> di4(40, 41, 42, 43);

    cout << "\nAllocating deque iterators....\n";
    int diterValue;
    IA_DequeIter<int>
	diter(di,0),       // forward iterator
	diter0(di0,1),     // forward iterator
	diter1(di1,-1),    // backward iterator
	diter2(di2,2),     // forward iterator
	diter3(di3,-3),    // backward iterator
	diter4(di4,4);     // forward iterator

    int dvec[10];                   // Construct an array of values.
    for (int i=0; i<10; i++) {
	dvec[i] = i*i + i;
    }
    IA_Deque<int> longD(dvec, 10);  // Construct deque with array arg
    IA_DequeIter<int>
	ld10neg(longD,-1),   // backward iterator
	ld10zero(longD,0),   // forward iterator
	ld10pos(longD,1);    // forward iterator

//#define ALLOC_DUMP
#ifdef  ALLOC_DUMP
    cout << "\n\n";
    prtd("di0", di0);
    prtd("di1", di1);
    prtd("di2", di2);
    prtd("di3", di3);
    prtd("di4", di4);
#undef  ALLOC_DUMP
#endif


//#define ITERATORS
#ifdef  ITERATORS

    cout << "\n\n";
    cout << "\nEntering while loop with diter";
    while ( diter(diterValue) ) {
	cout << "\n\tditer returned: " << diterValue;
    }
    cout << "\nEntering while loop for di0";
    while ( diter0(diterValue) ) {
	cout << "\n\tditer0 returned: " << diterValue;
    }
    cout << "\nEntering while loop for di1";
    while ( diter1(diterValue) ) {
	cout << "\n\tditer1 returned: " << diterValue;
    }
    cout << "\nEntering while loop for di2";
    while ( diter2(diterValue) ) {
	cout << "\n\tditer2 returned: " << diterValue;
    }
    cout << "\nEntering while loop for di3";
    while ( diter3(diterValue) ) {
	cout << "\n\tditer3 returned: " << diterValue;
    }
    cout << "\nEntering while loop for di4";
    while ( diter4(diterValue) ) {
	cout << "\n\tditer4 returned: " << diterValue;
    }

#undef ITERATORS
#endif


//#define VARITERATORS
#ifdef  VARITERATORS
    cout << "\n\nPlaying with long vectors\n";
    cout << "\nEntering while loop for ld10neg";
    while ( ld10neg(diterValue) ) {
	cout << "\n\tld10neg returned: " << diterValue;
    }
    cout << "\n\nEntering while loop for ld10zero";
    while ( ld10zero(diterValue) ) {
	cout << "\n\tld10zero returned: " << diterValue;
    }
    cout << "\n\nEntering while loop for ld10pos";
    while ( ld10pos(diterValue) ) {
	cout << "\n\tld10pos returned: " << diterValue;
    }
#undef VARITERATORSA
#endif


#define OPERATORS
#ifdef  OPERATORS

    prtd("longD",longD);
    IA_Deque<int> copyD( longD );
    prtd("copyD", copyD);

    outd("longD==copyD", (longD==copyD));
    outd("longD!=copyD", (longD!=copyD));

    longD[3] = - longD[3];
    prtd("long[3] = -longD[3]", longD);

    outd("longD==copyD", (longD==copyD));
    outd("longD!=copyD", (longD!=copyD));
#undef  OPERATORS
#endif

//#define MEMBER_FUNCTIONS_SIMPLE
#ifdef  MEMBER_FUNCTIONS_SIMPLE

    cout << "\n\n";
    outd("di0.length() = ",di0.length());
    frst("di0", di0);
    outd("di0.last() = ", di0.last());

    outd("di1.length() = ",di1.length());
    frst("di1", di1);
    outd("di1.last() = ", di1.last());

    outd("di2.length() = ",di2.length());
    frst("di2", di2);
    outd("di2.last() = ", di2.last());

#undef  MEMBER_FUNCTIONS_SIMPLE
#endif

//#define MEMBER_FUNCTIONS_INS_DEL
#ifdef  MEMBER_FUNCTIONS_INS_DEL

    cout << "\n\n";
    IA_Deque<int>  dq1(-3,-2,-1,-2);

    prtd("dq1", dq1);               // -3 -2 -1 -2
    outd("dq1.length() = ", dq1.length());

    dq1.insFront(-4);
    prtd("dq1.insFront(-4)", dq1);  // -4 -3 -2 -1 -2
    outd("dq1.length() = ", dq1.length());

    dq1.insBack(0);
    prtd("dq1.insBack(0)  ", dq1);  // -4 -3 -2 -1 -2  0
    outd("dq1.length() = ", dq1.length());

    dq1.delFront();
    prtd("dq1.delFront()  ", dq1);  // -3 -2 -1 -2  0
    outd("dq1.length() = ", dq1.length());

    dq1.delNth(3);
    prtd("dq1.delNth(3)   ", dq1);  // -3 -2 -1  0
    outd("dq1.length() = ", dq1.length());

    dq1.delValue(0);
    prtd("dq1.delValue(0) ", dq1);  // -3 -2 -1
    outd("dq1.length() = ", dq1.length());

    dq1.delBack();
    prtd("dq1.delBack()   ", dq1);  // -3 -2
    outd("dq1.length() = ", dq1.length());

#undef  MEMBER_FUNCTIONS_INS_DEL
#endif

#define MEMBER_FUNCTIONS_REV_SUB
#ifdef  MEMBER_FUNCTIONS_REV_SUB

    cout << "\n\n";
    IA_Deque<int> plus2thru7, minus3thru2, outOfBounds, dq_result;
    longD.sub(2, 7, plus2thru7);
    longD.sub(-3, 2, minus3thru2);
//    longD.sub(-3, 10, outOfBounds );  // Should cause throw in sub()
    
    prtd("plus2thru7",plus2thru7);
    prtd("minus3thru2",minus3thru2);
    prtd("outOfBounds",outOfBounds);

    cout << "\n";
    prtd("longD", longD);
    longD.reverse(dq_result);
    prtd("longD.reverse(dq_result)", dq_result);
#undef  MEMBER_FUNCTIONS_REV_SUB
#endif

#define FRIEND_FUNCTIONS
#ifdef  FRIEND_FUNCTIONS
    cout << "\n\n";
    IA_Deque<int>  concat1(6,7,8,9), concat2(10,11,12,13,14),
        concat_result;

    prtd("concat1", concat1);
    prtd("concat2", concat2);

    concat( concat1, concat2, concat_result);
    prtd("concat(concat1, concat2, concat_result) =", concat_result);

    concat( concat2, concat1, concat_result);
    prtd("concat( concat2, concat1, concat_result) =", concat_result);

    concat( concat1, concat1, concat_result);
    prtd("concat( concat1, concat1, concat_result) =", concat_result);

    concat( concat1, concat2, concat1);
    prtd("concat( concat1, concat2, concat1) =", concat1);

    concat( concat2, concat1, concat1);
    prtd("concat( concat2, concat1, concat1) =", concat1);
#undef  FRIEND_FUNCTIONS
#endif

    cout << "\n";
}

@


1.2
log
@Added new tests for op== and op!=.
@
text
@d8 1
a8 1
static char test_deque_c_rcsid[] = "$Id: test-deque.c,v 1.1 92/12/16 02:15:17 rjj Exp Locker: rjj $";
d10 4
a13 1
// $Log:	test-deque.c,v $
d39 1
a39 1
    IA::exit_on_throw = 0;           // Don\'t abort on errors.
@


1.1
log
@Initial revision
@
text
@d2 2
d8 1
a8 1
static char test_deque_c_rcsid[] = "$Id$";
d10 4
a13 1
// $Log$
a25 1
					
d27 3
d31 2
a32 3
double  my_func(int x) {
    return (double( x + double(x)/10));
}
d36 1
a36 1
    IA::exit_on_throw = 0;
d38 1
a38 1
    cout << "Allocating di...\n";
a39 1
    cout << "Allocating di0...\n";
a40 1
    cout << "Allocating di1...\n";
a41 1
    cout << "Allocating di2...\n";
a42 1
    cout << "Allocating di3...\n";
a43 1
    cout << "Allocating di4...\n";
d46 1
a46 1
    cout << "\nAllocating diter4(di)\n";
d49 6
a54 6
	diter(di,0),
	diter0(di0,1),
	diter1(di1,-1),
	diter2(di2,2),
	diter3(di3,-3),
	diter4(di4,4);
d56 1
a56 1
    int dvec[10];
d60 16
a75 2
    IA_Deque<int> longD(dvec, 10);
    IA_DequeIter<int> ld10neg(longD,-1), ld10zero(longD,0), ld10pos(longD,1);
d78 1
a78 2

#define ITERATORS
d81 2
a82 11
#define dilen(k) \
    cout << "\ndi" << k << ".length() = " ; \
    cout << di##k.length();

    dilen(0);
    dilen(1);
    dilen(2);
    dilen(3);
    dilen(4);

    cout << "\nEntering while loop for di";
d111 1
a111 1
#define VARITERATORS
d133 20
d154 3
d158 1
d160 35
a194 2
    prtd("di3",di3);
    prtd("longD",longD);
d196 3
a198 1
    IA_Deque<int> myD, tailD;
d200 2
a201 2
    myD = longD;
    prtd("myD",myD);
d203 2
d206 2
a207 1
    IA_Deque<int> plus2thru7, minus3thru2, outOfBounds;
d216 5
a220 1
#undef  OPERATORS
d223 4
a226 3
#define FUNCTIONS
#ifdef  FUNCTIONS
    IA_Deque<int>  concat1(1,2,3,4,5), concat2(10,11,12,13,14),
d233 1
a233 1
    prtd("concat1, concat2,concat_result) =", concat_result);
d236 1
a236 1
    prtd("concat2, concat1, concat_result) =", concat_result);
d239 1
a239 4
    prtd("concat1, concat1, concat_result) =", concat_result);
#undef  FUNCTIONS
#endif

d241 2
a242 3
//#define  MAP
#ifdef MAP
    cout << "\n\nMapping function test\n" ;
d244 3
a246 13
    IA_Deque<int>  map_in(50,60,70,80,90);
    IA_Deque<double> map_out;

    double  (*my_fp)(int);  // declare such a function exists...
    void  IA_Deque_map(my_func,
		       IA_Deque<int>,
		       IA_Deque<double>);

    prtd("map_in", map_in);
    IA_Deque_map(my_func, map_in, map_out);
    prtd("map(my_func, map_in, map_out) =>", map_out);

#undef  MAP
a247 1

@
