|
From: Bob T. <bt...@us...> - 2003-11-28 23:18:42
|
Update of /cvsroot/benson/benson3/src/tests
In directory sc8-pr-cvs1:/tmp/cvs-serv22733
Added Files:
stacktest.c
Log Message:
Added the stacktest.c dangnabbit
--- NEW FILE: stacktest.c ---
#include <stdio.h>
#include "stack.h"
typedef struct test_context {
int last_test;
int rc[20];
} test_ctx;
test_succeed(test_ctx *tests)
{
tests->rc[tests->last_test++] = 1;
}
test_status(test_ctx *tests)
{
int ctr;
int success = 0;
int total_tests = tests->last_test;
for(ctr=0;ctr<=total_tests;ctr++) {
if(tests->rc[ctr] == 1) {
success++;
}
}
printf("%i/%i", success, total_tests);
if(total_tests == success) {
return 0;
}
return 1;
}
int main (int argc, char *argv[])
{
stack_ctx *this;
test_ctx tests;
int rc = 0;
int ctr = 0;
int c = 0;
tests.last_test = 0;
while((c = getopt(argc, argv, "cdou")) != -1) {
switch(c)
{
case 'c':
if((this = stack_create(50)) != NULL) {
test_succeed(&tests);
}
if((rc = stack_destroy(this)) == 0) {
test_succeed(&tests);
}
exit(test_status(&tests));
break;
case 'd':
if((this = stack_create(50)) != NULL) {
test_succeed(&tests);
}
if(stack_push(this, "testing1") == 0) {
test_succeed(&tests);
}
if(stack_push(this, "testing2") == 0) {
test_succeed(&tests);
}
if(stack_push(this, "testing3") == 0) {
test_succeed(&tests);
}
if((rc = stack_destroy(this)) == 0) {
test_succeed(&tests);
}
exit(test_status(&tests));
break;
case 'o':
if((this = stack_create(3)) != NULL) {
test_succeed(&tests);
}
if(stack_push(this, "testing1") == 0) {
test_succeed(&tests);
}
if(stack_push(this, "testing2") == 0) {
test_succeed(&tests);
}
if(stack_push(this, "testing3") == 0) {
test_succeed(&tests);
}
if(stack_push(this, "testing4") == -1) {
test_succeed(&tests);
}
if((rc = stack_destroy(this)) == 0) {
test_succeed(&tests);
}
exit(test_status(&tests));
break;
case 'u':
if((this = stack_create(3)) != NULL) {
test_succeed(&tests);
}
if(stack_push(this, "testing1") == 0) {
test_succeed(&tests);
}
if(stack_push(this, "testing2") == 0) {
test_succeed(&tests);
}
if(stack_push(this, "testing3") == 0) {
test_succeed(&tests);
}
if(stack_pop(this) != NULL) {
test_succeed(&tests);
}
if(stack_pop(this) != NULL) {
test_succeed(&tests);
}
if(stack_pop(this) != NULL) {
test_succeed(&tests);
}
if(stack_pop(this) == NULL) {
test_succeed(&tests);
}
if((rc = stack_destroy(this)) == 0) {
test_succeed(&tests);
}
exit(test_status(&tests));
break;
}
}
return 1;
}
|