head     1.3;
branch   ;
access   ;
symbols  ;
locks    ; strict;
comment  @// @;


1.3
date     92.08.20.11.16.30;  author thoth;  state Exp;
branches ;
next     1.2;

1.2
date     92.08.14.15.48.49;  author thoth;  state Exp;
branches ;
next     1.1;

1.1
date     92.07.26.16.48.55;  author thoth;  state Exp;
branches ;
next     ;


desc
@static test program for the point set union operation.
@


1.3
log
@tests have been moved to a separate module
@
text
@// Emacs: -*- C++ -*-
static char rcsid[] = "$Id: test002.cc,v 1.2 92/08/14 15:48:49 thoth Exp $";

// 
// $Log:	test002.cc,v $
// Revision 1.2  92/08/14  15:48:49  thoth
// Added better testing of the iterators, also tests for
// the old card() function and tests for the new index()
// function.
// 
// Revision 1.1  92/07/26  16:48:55  thoth
// Initial revision
// 
// Revision 1.1  92/07/16  11:57:43  thoth
// Initial revision
// 
// 

#include "IntPoint.h"
#include "IntPointSet.h"
#include "IPSIter.h"

#include "generic-tests.h"

main()
{
#if 1
    const int	x0=-17, x1=-10, x2=-8, x3=0, x4=4, x5=7, x6=10;
    const int	y0=-2, y1=4, y2=7, y3=12, y4=17, y5=20;
#else
    const int	x0=-4, x1=-4, x2=-2, x3=-1, x4=-1, x5=1, x6=1;
    const int	y0=-2, y1=-2, y2=0, y3=0, y4=2, y5=2;
#endif
    IntPointSet ps0,ps1;

    malloc_debug(2);

    ps0 = IntPointSet(IntPoint(y0), IntPoint(y1));
    test_iter(ps0);
    ps1 = IntPointSet(IntPoint(y2), IntPoint(y5));
    test_iter(ps1);
    ps0 = ps0 | ps1;
    test_iter(ps0);
    ps1 = IntPointSet(IntPoint(y2), IntPoint(y3));
    test_iter(ps1);
    test_union(ps0, ps1, ps0|ps1);
    

    ps0 = IntPointSet(IntPoint(x5,y0), IntPoint(x6,y5));
    test_iter(ps0);
    ps1 = IntPointSet(IntPoint(x0,y0), IntPoint(x6,y1));
    test_iter(ps1);
    test_union(ps0, ps1, ps0|ps1);

    ps0 = ps0 | ps1;
    test_iter(ps0);
    printIntSet(ps0);
    ps1 = IntPointSet(IntPoint(x0,y5), IntPoint(x1,y0));
    test_iter(ps1);
    test_union(ps0, ps1, ps0|ps1);

    ps0 = ps0 | ps1;
    test_iter(ps0);
    printIntSet(ps0);
    ps1 = IntPointSet(IntPoint(x4,y4), IntPoint(x0,y5));
    test_iter(ps1);
    test_union(ps0, ps1, ps0|ps1);

    ps0 = ps0 | ps1;
    test_iter(ps0);
    printIntSet(ps0);
    ps1 = IntPointSet(IntPoint(x4,y4), IntPoint(x0,y5));
    test_iter(ps1);
    test_union(ps0, ps1, ps0|ps1);

    ps0 = ps0 | ps1;
    test_iter(ps0);
    printIntSet(ps0);
    ps1 = IntPointSet(IntPoint(x4,y4), IntPoint(x3,y2));
    test_iter(ps1);
    test_union(ps0, ps1, ps0|ps1);

    ps0 = ps0 | ps1;
    test_iter(ps0);
    printIntSet(ps0);
    ps1 = IntPointSet(IntPoint(x2,y3), IntPoint(x4,y2));
    test_iter(ps1);
    test_union(ps0, ps1, ps0|ps1);

    ps0 = ps0 | ps1;
    test_iter(ps0);
    cout << ps0.contains(IntPoint(-1,1));
    printIntSet(ps0);
}
@


1.2
log
@Added better testing of the iterators, also tests for
the old card() function and tests for the new index()
function.
@
text
@d2 1
a2 1
static char rcsid[] = "$Id: test002.cc,v 1.1 92/07/26 16:48:55 thoth Exp Locker: thoth $";
d6 5
d23 1
a23 93
void test_union(IntPointSet a, IntPointSet b, IntPointSet ab)
{
    IntPoint	p;
    
    IPSIter	iter;
    
    iter = a;
    
    while (iter(p)) {
	if (!ab.contains(p)) {
	    cout << p;
	    cout << "##missing##\n";
	}
    }
    
    iter = b;
    
    while (iter(p)) {
	if (!ab.contains(p)) {
	    cout << p;
	    cout << "##missing##\n";
	}
    }
    
    iter = ab;
    
    while (iter(p)) {
	if (! (a.contains(p) || b.contains(p))) {
	    cout << p;
	    cout << "##extra##\n";
	}
    }
    cout << "union test complete\n";
}

void printIntSet(IntPointSet ips)
{
    char	image[80][40];
    int	x,y;
    
    for (x=0; x<40; x++)
	for (y=0; y<40; y++)
	    image[x][y] = ' ';
    
    IPSIter	iter(ips);
    IntPoint	p;
    while (iter(p)) {
	image[p[0]+20][p[1]+10] = '#';
    }

    for (x=40; x<80; x++)
	for (y=0; y<40; y++)
	    image[x][y] = ips.contains(IntPoint(x-60,y-10)) ? '*' : '.';
    
    for (y=0; y<40; y++) {
	for (x=0; x<75; x++)
	    cout << image[x][y];
	cout << '\n';
    }
    
}


void test_iter(IntPointSet ps)
{
    IPSIter	iter(ps);
    IntPoint	p, oldp;
    unsigned	idx=0;

    while (iter(p)) {

	// the following is not part of the IAC++ spec, it just happens
	// to be the way we implemented iteration.
	if (idx>0 && Pointcmp(oldp,p)!=-1) {
	    cout << "iteration order error: " << oldp << ">=" << p << '\n';
	}

	// this IS part of the spec
	// cout << "index(" << p << ")=" << ps.index(p) << '\n';
	if (ps.index(p) != idx) {
	    cout << "Iteration order error: index("<<p<<")=" << ps.index(p)
		<< "!="<<idx<<'\n';
	}

	idx++;
	oldp = p;
    }
    if (idx != ps.card()) {
	cout << "Cardinality error: ps.card()=" << ps.card()
	    << "!=" << idx << '\n';
    }
    cout << "iteration test complete\n";
}
@


1.1
log
@Initial revision
@
text
@d2 1
a2 1
static char rcsid[] = "$Id: test001.cc,v 1.1 92/07/16 11:57:43 thoth Exp Locker: thoth $";
d5 4
a8 1
// $Log:	test001.cc,v $
d21 7
a27 5

    {
	IPSIter	iter(a);

	while (iter(p)) {
d29 1
a29 4
	    if (!ab.contains(p)) {
		cout << "##missing##";
	    }
	    cout << '\t';
a30 1
	cout << '\n';
d32 5
a36 5

    {
	IPSIter	iter(b);

	while (iter(p)) {
d38 1
a38 4
	    if (!ab.contains(p)) {
		cout << "##missing##";
	    }
	    cout << '\t';
a39 1
	cout << '\n';
d41 5
a45 5

    {
	IPSIter	iter(ab);

	while (iter(p)) {
d47 1
a47 4
	    if (! (a.contains(p) || b.contains(p))) {
		cout << "##extra##";
	    }
	    cout << '\t';
a48 1
	cout << '\n';
d50 1
a50 2

    cout << '\n';
d80 32
d126 1
d128 1
d130 1
d132 1
d137 1
d139 1
d143 1
d146 1
d150 1
d153 1
d157 1
d160 1
d164 1
d167 1
d171 1
d174 1
d178 1
@
