1 /* Test of the type-safe stack data type.
2 Copyright (C) 2020 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 /* Written by Marc Nieper-Wißkirchen <marc@nieper-wisskirchen.de>, 2020. */
29 #define GL_STACK_ELEMENT int
30 #define GL_STACK_STORAGECLASS static
33 #define GL_STACK_ELEMENT const char *
34 #define GL_STACK_STORAGECLASS static
35 #define GL_STACK_NAME string_stack
42 stack_init (&int_stack
);
43 ASSERT (stack_size (&int_stack
) == 0);
44 ASSERT (stack_empty (&int_stack
));
45 stack_push (&int_stack
, 0);
46 stack_push (&int_stack
, 1);
47 stack_push (&int_stack
, 2);
48 stack_push (&int_stack
, 3);
49 stack_push (&int_stack
, 4);
50 stack_push (&int_stack
, 5);
51 stack_push (&int_stack
, 6);
52 stack_push (&int_stack
, 7);
53 stack_push (&int_stack
, 8);
54 stack_push (&int_stack
, 9);
55 ASSERT (stack_size (&int_stack
) == 10);
56 ASSERT (!stack_empty (&int_stack
));
57 ASSERT (stack_top (&int_stack
) == 9);
58 ASSERT (stack_size (&int_stack
) == 10);
59 ASSERT (stack_pop (&int_stack
) == 9);
60 ASSERT (stack_size (&int_stack
) == 9);
61 stack_discard (&int_stack
);
62 ASSERT (stack_size (&int_stack
) == 8);
63 ASSERT (stack_top (&int_stack
) == 7);
64 stack_destroy (&int_stack
);
66 string_stack_type string_stack
[1];
67 string_stack_init (string_stack
);
68 string_stack_push (string_stack
, "foo");
69 ASSERT (STREQ (string_stack_pop (string_stack
), "foo"));
70 ASSERT (string_stack_empty (string_stack
));
71 string_stack_destroy (string_stack
);