/* 
 * Vmisctst.c - Test program for miscellaneous support routines.
 * 
 * Author:    L. Van Warren
 * Date:      Nov 1995
 * Copyright (c) 1995 L. Van Warren * All Rights Reserved
 *
 */
#include "Van.h"

#define HASHSIZE 10

int hist[HASHSIZE];

char string[20][32] =
{
	"My",
	"and",
	"Mother",
	"should",
	"hash",
	"to",
	"different",
	"places",
	"right",
	"right", /* check for duplicate rejection */
	"There",
	"was",
	"once",
	"a",
	"young",
	"boy",
	"who",
	"was",
	"4",
	"(four)",
};


extern void testVmisc(void);

void testVmisc(void)
{
    int i;
	Boolean b;
	String32 name;
	
	b = NIL;
	fprintf(stdout, "Boolean b =   NIL: b?\"ERROR\":  \"NIL\": %s\n", b?"ERROR":"NIL");

	b = TRUE;
	fprintf(stdout, "Boolean b =  TRUE: b?\"TRUE\" :\"ERROR\": %s\n", b?"TRUE":"ERROR");

	b = FALSE;
	fprintf(stdout, "Boolean b = FALSE: b?\"ERROR\":\"FALSE\": %s\n", b?"ERROR":"FALSE");

    /* **************** */
    /* Check entabbing. */
    /* **************** */
    for(i = 0; i < 5; i++)
    {
        entab(stdout, i);
        fprintf(stdout, "%d tabs.\n", i);
    }

    /* ************** */
    /* Check error(). */
    /* ************** */

    error("Test of error().");

	fprintf(stdout, "Assigning legal name:\n");
	name = asnString32("This is a test name");
	fprintString32(stdout, name);
	
	fprintf(stdout, "Assigning longer name:\n");
	name = asnString32("This is a test name that is too long for 32 chars");
	fprintString32(stdout, name);

	/* Test hash function. */
	fprintf(stdout, "Testing hash function.\n");
	for(i = 0; i < 20; i++)
	{
	    fprintf(stdout, "%s hashes to %d\n",
		    string[i], hashString32(asnString32(string[i]), HASHSIZE));
	    hist[hashString32(asnString32(string[i]), HASHSIZE)]++;
	}

	for(i = 0; i < HASHSIZE; i++)
	{
		fprintf(stdout, "hist[%d]: %d\n", i, hist[i]);
	}
	
	fprintf(stdout, "Hashing generated names:\n");

	for(i = 0; i < 10; i++)
	{
		name = genString32();
		fprintf(stdout, "%d is the hash of: ", hashString32(name, HASHSIZE));
		fprintString32(stdout, name);
	}

	/* Test name comparison. */
	printf
	(
		"Are bob and bill the same? %s.\n",
		isSameString32(asnString32("bob"), asnString32("bill"))?"YES":"NO"
	);

	printf
	(
		"Are bill and bill the same? %s.\n",
		isSameString32(asnString32("bill"), asnString32("bill"))?"YES":"NO"
	);
}

