#include <gpklib.h>
#include <assert.h>

#define N 370

# include <stdio.h>
# define P(x)	fprintf(stderr, "%s", (x))

main()
{
 {
 fprintf(stderr, "[1z]\n");
 double *p = double1alloc(0);
 assert(p);
 assert(double1test(p) == 0);
 assert(double1size(p) == 0);
 double1free(p);
 }
 {
 fprintf(stderr, "[2z]\n");
 double **p = double2alloc(1, 1);
 double2set(p, 0.0);
 assert(p);
 assert(p[0]);
 assert(p[0][0] == 0.0);
 assert(double2test(p) == 0);
 struct alloc_size q = double2size(p);
 assert(q.rows==1 && q.cols==1);
 double2free(p);
 }
 {
 fprintf(stderr, "[2z]\n");
 double **p = double2alloc(0, 0);
 assert(p);
 assert(p[0] == 0);
 printf("double2test(p)=%d\n", double2test(p));
 assert(double2test(p) == 0);
 struct alloc_size q = double2size(p);
 assert(q.rows==0 && q.cols==0);
 double2free(p);
 }
 {
 double **p[N];
 int i;
 P(">"); P("\n");
 for(i=0;i<N;i++)	{
	double **q;
	q = double2alloc(N+5-i%9, 1+i/9);
	P("a");
	assert(q);
	double2free(q);
	P("f");
	}
 P("\n");

 for(i=0;i<N;i++)	{
	p[i] = double2alloc(1+i, 1+7*(i%10));
	P("a");
	assert(p[i]);
	}

 for(i=0;i<N;i++)	{
	double **q;
	q = double2alloc(N+5-i%9, 1+i/9);
	assert(q);
	double2free(q);
	P("X");
	}
 P("\n");
 
 for(i=0;i<N;i++)	{
	double2free(p[i]);
	P("f");
	}
 P("\n");

 for(i=0;i<N;i++)	{
	p[i] = double2alloc(1+i, 1+7*(i%10));
	{
	int j;
	for(j=0;j<1+7*(i%10) && j<1+i;j++)
		p[i][j][j] = i*j;
	}
	P("A");
	assert(p[i]);
	}

 for(i=N-1;i>=0;i--)	{
	{
	int j;
	for(j=0;j<1+7*(i%10)&& j<1+i;j++)
		assert(p[i][j][j] == i*j);
	}
	double2free(p[i]);
	P("F");
	}
 P("\n");
}
{
 short **p[N];
 int i;
 P(">"); P("\n");
 for(i=0;i<N;i++)	{
	short **q;
	q = short2alloc(N+5-i%9, 1+i/9);
	P("a");
	assert(q);
	short2free(q);
	P("f");
	}
 P("\n");

 for(i=0;i<N;i++)	{
	p[i] = short2alloc(1+i, 1+7*(i%10));
	P("a");
	assert(p[i]);
	}

 for(i=0;i<N;i++)	{
	short **q;
	q = short2alloc(N+5-i%9, 1+i/9);
	assert(q);
	short2free(q);
	P("X");
	}
 P("\n");
 
 for(i=0;i<N;i++)	{
	short2free(p[i]);
	P("f");
	}
 P("\n");

 for(i=0;i<N;i++)	{
	p[i] = short2alloc(1+i, 1+7*(i%10));
	{
	int j;
	for(j=0;j<1+7*(i%10);j++)	{
		int k;
		for(k=0;k<1+i;k++)
			p[i][k][j] = i*j-k;
		}
	}
	P("A");
	assert(p[i]);
	}

 for(i=N-1;i>=0;i--)	{
	{
	int j;
	for(j=0;j<1+7*(i%10);j++)	{
		int k;
		for(k=0;k<1+i;k++)
			assert(p[i][k][j] == i*j-k);
		}
	}
	short2free(p[i]);
	P("F");
	}
 P("\n");
}
}
