Table of Contents

Project: library tester

A project for C/C++, Data Structures, and System Programming by Karl Krauss for fall 2011.

Approximately 1 hour for just the tester, then several more for all the libraries.

Objectives

I had spent a lot of time writing various libraries, this program was written as a way to test them all with subtle changes.

Prerequisites

In order to successfully accomplish/perform this project, the listed resources/experiences need to be consulted/achieved:

Background

This was the simplest way I could think of to test all of my libraries.

Attributes

Cprog attributes

Data Structures

Systems programming

Code

This is the code:

#include <stdio.h>
#include <stdlib.h>
#include "queue.h"// this incarnation tested queues/ but can test any of my 3 core libraries
 
int main()
{
	char selection;
	int input;
 
	Node *tmp;
	Queue *myQueue;
 
 
	myQueue=(Queue *)malloc(sizeof(Queue));
 
	myQueue->start = myQueue->end = tmp = NULL;	
	printf("Press '1' if you wish to create or add to Queue.\n\n");
	printf("Press '2' if you wish to delete start of a Queue.\n\n");
	printf("Press '3' if you wish to peek start of Queue\n\n");
	printf("Press 'q' if you wish to quit: ");
 
	scanf("%c", &selection);
 
	while (selection != 'q')
	{
		if (selection == '1')
		{
			printf("What value would you like to store at top of stack: ");//add to top of stack
			scanf("%d", &input);
			myQueue = enqueue(myQueue, input);
		}
		else if(selection == '2')//delete beginning of queue
		{
 
			tmp = dequeue(myQueue);
			if (tmp == NULL)
			{
				printf("Empty Queue.\n");
			}
			else
			{
				printf("%d\n", tmp->value);
			}
		}
		else if(selection == '3')//view beginning of queue without deleting
		{
 
			tmp = peek(myQueue);
			if (tmp == NULL)
			{
				printf("Empty queue1.\n");
			}
			else
			{
				printf("%d\n", tmp->value);
			}
		}
 
		else 
		{
			printf("Improper selection please try again.\n\n");
		}
 
		//printf("Press '1' if you wish to create or append a new node.\n\n");
		//printf("Press '2' if you wish to insert a node.\n\n");
		//printf("Press '3' if you wish to delete a node\n\n");
		//printf("press '4' if you wish to print current list\n\n");
		//printf("Press '-1' if you wish to quit: ");
		printf("enter a selection: ");
		getchar();
		scanf("%c", &selection);
	}	
 
	return 0;
}