head	1.2;
access;
symbols;
locks; strict;
comment	@// @;


1.2
date	94.12.21.19.12.14;	author monica;	state Exp;
branches;
next	1.1;

1.1
date	94.12.16.02.51.07;	author monica;	state Exp;
branches;
next	;


desc
@@


1.2
log
@*** empty log message ***
@
text
@// Emacs: -*- C++ -*-
static char rcsid[] = "$Id: test004.c,v 1.1 1994/12/16 02:51:07 monica Exp monica $";

//
// $Log: test004.c,v $
// * Revision 1.1  1994/12/16  02:51:07  monica
// * Initial revision
// *
// Revision 1.12  1994/11/21  20:17:28  thoth
// Added tests for reflection through origin (operator-() )
//
// Revision 1.11  1994/11/09  20:25:21  monica
// removed include devfrags & any debugging calls to malloc
//
// Revision 1.10  1994/10/06  01:07:08  monica
// updated for DOS file naming
//
// Revision 1.9  1994/08/17  04:12:11  monica
// added int main & return 0
//
// Revision 1.8  1993/07/15  11:50:24  thoth
// IA_ prefix for most classes now necessary.
//
// Revision 1.7  92/12/16  14:50:10  thoth
// conversion to IA_ mostly complete
// 
// Revision 1.6  92/10/07  23:16:21  thoth
// minkowski test takes too long.
// put it in a separate program some day.
// 
// Revision 1.5  92/09/20  17:42:54  thoth
// added minkowski test.
// 
// Revision 1.4  92/09/14  21:58:22  thoth
// new cardinality consistency checks.
// 
// Revision 1.3  92/09/07  13:25:35  thoth
// moved generic code into modules so that others could use it.
// 
// Revision 1.2  92/08/25  15:38:43  thoth
// set difference is operator/, not -
// superficial testing of lattice operations.
// 
// Revision 1.1  92/08/23  13:30:39  thoth
// Initial revision
// 
//

#include <stdlib.h>

#include "IntPoint.h"
#include "IntPS.h"
//#include "YoderIPS.h"
#include "PSIter.h"

//#include "with-ia-pointset.h"

#include "gen-test.h"
#include "pt-util.h"


void cmp3(ostream& o, IA_Set<IA_Point<int> > a, IA_Set<IA_Point<int> > b, IA_Set<IA_Point<int> > c)
{
    o << compare(a,a) << ' ' << compare(a,b) << ' ' << compare(a,c) << '\n';
    o << compare(b,a) << ' ' << compare(b,b) << ' ' << compare(b,c) << '\n';
    o << compare(c,a) << ' ' << compare(c,b) << ' ' << compare(c,c) << '\n';
    o << flush;
}

int main(int argc, char**argv)
{
    unsigned size;
    size = (argc<2) ? 2 : atoi(argv[1]);
    
    unsigned l1, l2;
    l1 = (argc<3) ? 40 : atoi(argv[2]);
    l2 = (argc<4) ? 40 : atoi(argv[3]);
    
    IA_Point<int>	*a1 = new IA_Point<int>[l1];
    IA_Point<int>	*a2 = new IA_Point<int>[l2];
    
    cout << "ready to fill the arrays\n" << flush;
    
    unsigned i;
    for (i=0; i<l1; i++)
	a1[i] = make_random_point(size, 0, 9 );
    cout << "array 1 filled\n" << flush;
    for (i=0; i<l2; i++)
	a2[i] = make_random_point(size, 0, 9 );
    cout << "array 2 filled\n" << flush;
    
#if 0
    // this uses a private constructor which is illegal, but g++ lets it slide
    IA_Set<IA_Point<int> >	ps1(YoderIPS(a1,l1));
    cout << "ips 1 constructed\n" <<flush;
    IA_Set<IA_Point<int> >	ps2(YoderIPS(a2,l2));
    cout << "ips 2 constructed\n" <<flush;
#else
    IA_Set<IA_Point<int> >	ps1(size, a1,l1);
    IA_Set<IA_Point<int> >	ps2(size, a2,l2);
#endif
    
    SortIntPointArray(a1, l1);
    cout << "array 1 sorted\n" << flush;
    SortIntPointArray(a2, l2);
    cout << "array 2 sorted\n" << flush;
    
    test_arr_ps(ps1, a1, l1);
    cout << "ips 1 tested\n"<< flush;
    test_arr_ps(ps2, a2, l2);
    cout << "ips 2 tested\n"<< flush;
    
#if 0
    cout << "outputting ips 1\n";
    ps1.output(cout);
    cout << "outputting ips 2\n";
    ps2.output(cout);
#endif
    
    test_iter(ps1);
    test_iter(ps2);
    
    // list_ips(cout << "ps1: ",ps1);
    // list_ips(cout << "ps2: ",ps2);

    unsigned	c1, c2, only1, only2, overlap;
    c1 = ps1.card();
    c2 = ps2.card();

    IA_Set<IA_Point<int> > temp;

    temp = ps1|ps2;
    // list_ips(cout << "ps1|ps2: ",temp);
    test_union(ps1,ps2,temp);
    test_iter(temp);

    cmp3(cout, ps1, ps2, temp);

    overlap = c1+c2 - temp.card();
    only1 = c1-overlap;
    only2 = c2-overlap;
    cout << c1 << " = " << only1 << " + " << overlap << '\n';
    cout << c2 << " = " << only2 << " + " << overlap << '\n';
    
    temp = ps1&ps2;
    // list_ips(cout << "ps1&ps2: ",temp);
    test_intersection(ps1,ps2,temp);
    test_iter(temp);

    cmp3(cout, ps1, ps2, temp);

    if (temp.card()!=overlap) {
	cout << "cardinality inconsistency: " << temp.card() << " != "
	    << overlap << '\n';
    }
    
    temp = ps1^ps2;
    // list_ips(cout << "ps1^ps2: ",temp);
    test_XOR(ps1,ps2,temp);
    test_iter(temp);

    cmp3(cout, ps1, ps2, temp);
    
    if (temp.card()!=only1+only2) {
	cout << "cardinality inconsistency: " << temp.card() << " != "
	    << (only1+only2) << '\n';
    }
    
    temp = ps1/ps2;
    // list_ips(cout << "ps1/ps2: ",temp);
    test_minus(ps1,ps2,temp);
    test_iter(temp);

    cmp3(cout, ps1, ps2, temp);
    
    if (temp.card()!=only1) {
	cout << "cardinality inconsistency: " << temp.card() << " != "
	    << only1 << '\n';
    }

    IA_Point<int>	p = ps2.choice();
    temp = ps1 + p;
    test_offset(ps1, p, temp);
    test_iter(temp);
    
    if (temp.card()!=c1) {
	cout << "cardinality inconsistency: " << temp.card() << " != "
	    << c1 << '\n';
    }

#if 0

    cout << "this could take a few days:"<<flush;
    temp = ps1 + ps2;
    cout << "\n" << flush;
    test_minkowski(ps1, ps2, temp);
    test_iter(temp);

    cmp3(cout, ps1, ps2, temp);

#endif

    temp = -ps1;
    test_oreflect(ps1, temp);
    test_iter(temp);

    if (temp.card()!=c1) {
	cout << "cardinality inconsistency: " << temp.card() << " != "
	    << c1 << '\n';
    }

    return 0;
}
@


1.1
log
@Initial revision
@
text
@d2 1
a2 1
static char rcsid[] = "$Id: test004.c,v 1.12 1994/11/21 20:17:28 thoth Exp monica $";
d6 3
@
