glib/tests/stack-test.c
Jeff Garzik fd7ba69e32 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.
1999-03-09 19:41:19 +00:00

52 lines
1.4 KiB
C

#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;
}