/*
 * test automatically generated "intlist" data type
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "datatypes.h"

void test( int condition, char *string )
{
	if( condition )
	{
		printf( "%s: ok\n", string );
	} else
	{
		printf( "%s: fail\n", string );
	}
}


int main( void )
{
	intlist l = intlist_nil();
	test( intlist_kind( l ) == intlist_is_nil,
		"kind(nil) == nil" );

	l = intlist_cons( 100, l );

	test( intlist_kind( l ) == intlist_is_cons,
		"kind([100]) == cons" );

	intlist tail;
	int head;
	get_intlist_cons( l, &head, &tail );
	test( head == 100, "head([100]) == 100" );
	test( intlist_kind( tail ) == intlist_is_nil,
		"kind(tail([100])) == nil" );

	l = intlist_cons( 200, l );
	get_intlist_cons( l, &head, &tail );
	test( head == 200, "head([200,100]) == 200" );
	get_intlist_cons( tail, &head, &tail );
	test( head == 100, "head(tail([200,100])) == 100" );

	l = intlist_cons( 300, l );
	l = intlist_cons( 400, l );

	int sum = 0;
	intlist p = l;
	while( intlist_kind(p) == intlist_is_cons )
	{
		int head;
		intlist tail;
		get_intlist_cons( p, &head, &tail );
		sum += head;
		p = tail;
	}
	test( sum == 1000, "sum 1000" );

	exit(0);
	return(0);
}
