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


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


desc
@A module filled with generic IntPointSet tests.
@



1.1
log
@Initial revision
@
text
@// Emacs: -*- C++ -*-
static char rcsid[] = "$Id$";

// 
// $Log$
//

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

#include "generic-tests.h"

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 test_intersection(IntPointSet a, IntPointSet b, IntPointSet ab)
{
    IntPoint	p;
    
    IPSIter	iter;
    
    iter = a;
    
    while (iter(p)) {
	if (b.contains(p) != ab.contains(p)) {
	    cout << p;
	    cout << "##a error##\n";
	}
    }
    
    iter = b;
    
    while (iter(p)) {
	if (a.contains(p) != ab.contains(p)) {
	    cout << p;
	    cout << "##b error##\n";
	}
    }
    
    iter = ab;
    
    while (iter(p)) {
	if (! (a.contains(p) && b.contains(p))) {
	    cout << p;
	    cout << "##ab extra##\n";
	}
    }
    cout << "intersection test complete\n";
}

void test_XOR(IntPointSet a, IntPointSet b, IntPointSet ab)
{
    IntPoint	p;
    
    IPSIter	iter;
    
    iter = a;
    
    while (iter(p)) {
	if (b.contains(p) && ab.contains(p)) {
	    cout << p;
	    cout << "##a extra error##\n";
	} else if (!b.contains(p) && !ab.contains(p)) {
	    cout << p;
	    cout << "##a missing error##\n";
	}
    }
    
    iter = b;
    
    while (iter(p)) {
	if (a.contains(p) && ab.contains(p)) {
	    cout << p;
	    cout << "##b extra error##\n";
	} else if (!a.contains(p) && !ab.contains(p)) {
	    cout << p;
	    cout << "##b missing error##\n";
	}
    }
    
    iter = ab;
    
    while (iter(p)) {
	if (a.contains(p) == b.contains(p)) {
	    cout << p;
	    cout << "##ab extra##\n";
	}
    }
    
    if ( ((a-b) | (b-a)) != ab ) {
	cout << "(a-b) | (b-a) != a^b\n";
    }
    
    cout << "symmetric difference test complete\n";
}

void test_minus(IntPointSet a, IntPointSet b, IntPointSet ab)
{
    IntPoint	p;
    
    IPSIter	iter;
    
    iter = a;
    
    while (iter(p)) {
	if (b.contains(p) && ab.contains(p)) {
	    cout << p << "##extra [a] error##\n";
	} else if ( ! b.contains(p) && ! ab.contains(p) ) {
	    cout << p << "##missing [a] error##\n";
	}
    }
    
    iter = b;
    
    while (iter(p)) {
	if (ab.contains(p)) {
	    cout << p;
	    cout << "##b error##\n";
	}
    }
    
    iter = ab;
    
    while (iter(p)) {
	if (!a.contains(p) || b.contains(p)) {
	    cout << p;
	    cout << "##ab extra##\n";
	}
    }
    
    cout << "difference 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";
}
@
