Added stack, queue ADTs and related tests.

Tue Mar  9 14:37:32 1999  Jeff Garzik  <jgarzik@pobox.com>

        * Makefile.am, glib.h, gstack.c, gqueue.c,
          tests/Makefile.am, tests/queue-test.c, tests/stack-test.c:
        Added stack, queue ADTs and related tests.

        * glib.h, glist.c:
        New g_list_delete() function.
This commit is contained in:
Jeff Garzik
1999-03-09 19:41:19 +00:00
committed by Jeff Garzik
parent 0ecd369530
commit fd7ba69e32
21 changed files with 751 additions and 10 deletions

View File

@@ -33,3 +33,5 @@ tree-test
dirname-test
type-test
strfunc-test
queue-test
stack-test

View File

@@ -7,8 +7,10 @@ TESTS = \
hash-test \
list-test \
node-test \
queue-test \
relation-test \
slist-test \
stack-test \
string-test \
strfunc-test \
tree-test \
@@ -21,8 +23,10 @@ dirname_test_LDADD = $(top_builddir)/libglib.la
hash_test_LDADD = $(top_builddir)/libglib.la
list_test_LDADD = $(top_builddir)/libglib.la
node_test_LDADD = $(top_builddir)/libglib.la
queue_test_LDADD = $(top_builddir)/libglib.la
relation_test_LDADD = $(top_builddir)/libglib.la
slist_test_LDADD = $(top_builddir)/libglib.la
stack_test_LDADD = $(top_builddir)/libglib.la
string_test_LDADD = $(top_builddir)/libglib.la
strfunc_test_LDADD = $(top_builddir)/libglib.la
tree_test_LDADD = $(top_builddir)/libglib.la

83
tests/queue-test.c Normal file
View File

@@ -0,0 +1,83 @@
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <glib.h>
int main()
{
GQueue *q;
q = g_queue_new ();
g_assert (g_queue_empty (q) == TRUE);
g_queue_push (q, GINT_TO_POINTER (1));
g_assert (g_list_length (q->list) == 1);
g_queue_push (q, GINT_TO_POINTER (2));
g_assert (g_list_length (q->list) == 2);
g_queue_push (q, GINT_TO_POINTER (3));
g_assert (g_list_length (q->list) == 3);
g_queue_push (q, GINT_TO_POINTER (4));
g_assert (g_list_length (q->list) == 4);
g_queue_push (q, GINT_TO_POINTER (5));
g_assert (g_list_length (q->list) == 5);
g_assert (g_queue_empty (q) == FALSE);
g_assert (g_queue_index (q, GINT_TO_POINTER (2)) == 1);
g_assert (g_queue_index (q, GINT_TO_POINTER (142)) == -1);
g_assert (g_queue_peek (q) == GINT_TO_POINTER (1));
g_assert (g_queue_peek_front (q) == GINT_TO_POINTER (1));
g_assert (g_queue_peek_back (q) == GINT_TO_POINTER (5));
g_assert (g_queue_pop (q) == GINT_TO_POINTER (1));
g_assert (g_list_length (q->list) == 4);
g_assert (g_queue_pop (q) == GINT_TO_POINTER (2));
g_assert (g_list_length (q->list) == 3);
g_assert (g_queue_pop (q) == GINT_TO_POINTER (3));
g_assert (g_list_length (q->list) == 2);
g_assert (g_queue_pop (q) == GINT_TO_POINTER (4));
g_assert (g_list_length (q->list) == 1);
g_assert (g_queue_pop (q) == GINT_TO_POINTER (5));
g_assert (g_list_length (q->list) == 0);
g_assert (g_queue_pop (q) == NULL);
g_assert (g_list_length (q->list) == 0);
g_assert (g_queue_pop (q) == NULL);
g_assert (g_list_length (q->list) == 0);
g_assert (g_queue_empty (q) == TRUE);
/************************/
g_queue_push_front (q, GINT_TO_POINTER (1));
g_assert (g_list_length (q->list) == 1);
g_queue_push_front (q, GINT_TO_POINTER (2));
g_assert (g_list_length (q->list) == 2);
g_queue_push_front (q, GINT_TO_POINTER (3));
g_assert (g_list_length (q->list) == 3);
g_queue_push_front (q, GINT_TO_POINTER (4));
g_assert (g_list_length (q->list) == 4);
g_queue_push_front (q, GINT_TO_POINTER (5));
g_assert (g_list_length (q->list) == 5);
g_assert (g_queue_pop_front (q) == GINT_TO_POINTER (5));
g_assert (g_list_length (q->list) == 4);
g_assert (g_queue_pop_front (q) == GINT_TO_POINTER (4));
g_assert (g_list_length (q->list) == 3);
g_assert (g_queue_pop_front (q) == GINT_TO_POINTER (3));
g_assert (g_list_length (q->list) == 2);
g_assert (g_queue_pop_front (q) == GINT_TO_POINTER (2));
g_assert (g_list_length (q->list) == 1);
g_assert (g_queue_pop_front (q) == GINT_TO_POINTER (1));
g_assert (g_list_length (q->list) == 0);
g_assert (g_queue_pop_front (q) == NULL);
g_assert (g_list_length (q->list) == 0);
g_assert (g_queue_pop_front (q) == NULL);
g_assert (g_list_length (q->list) == 0);
g_queue_free (q);
return 0;
}

51
tests/stack-test.c Normal file
View File

@@ -0,0 +1,51 @@
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <glib.h>
int main()
{
GStack *s;
s = g_stack_new ();
g_assert (g_stack_empty (s) == TRUE);
g_stack_push (s, GINT_TO_POINTER (1));
g_assert (g_list_length (s->list) == 1);
g_stack_push (s, GINT_TO_POINTER (2));
g_assert (g_list_length (s->list) == 2);
g_stack_push (s, GINT_TO_POINTER (3));
g_assert (g_list_length (s->list) == 3);
g_stack_push (s, GINT_TO_POINTER (4));
g_assert (g_list_length (s->list) == 4);
g_stack_push (s, GINT_TO_POINTER (5));
g_assert (g_list_length (s->list) == 5);
g_assert (g_stack_index (s, GINT_TO_POINTER (2)) == 3);
g_assert (g_stack_empty (s) == FALSE);
g_assert (g_stack_peek (s) == GINT_TO_POINTER (5));
g_assert (g_stack_pop (s) == GINT_TO_POINTER (5));
g_assert (g_list_length (s->list) == 4);
g_assert (g_stack_pop (s) == GINT_TO_POINTER (4));
g_assert (g_list_length (s->list) == 3);
g_assert (g_stack_pop (s) == GINT_TO_POINTER (3));
g_assert (g_list_length (s->list) == 2);
g_assert (g_stack_pop (s) == GINT_TO_POINTER (2));
g_assert (g_list_length (s->list) == 1);
g_assert (g_stack_pop (s) == GINT_TO_POINTER (1));
g_assert (g_list_length (s->list) == 0);
g_assert (g_stack_pop (s) == NULL);
g_assert (g_list_length (s->list) == 0);
g_assert (g_stack_pop (s) == NULL);
g_assert (g_list_length (s->list) == 0);
g_stack_free (s);
return 0;
}