mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-09-27 17:52:58 +02:00
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:
@@ -33,3 +33,5 @@ tree-test
|
||||
dirname-test
|
||||
type-test
|
||||
strfunc-test
|
||||
queue-test
|
||||
stack-test
|
||||
|
@@ -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
83
tests/queue-test.c
Normal 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
51
tests/stack-test.c
Normal 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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user