master
 1#include "stack.h"
 2#include <cgreen/cgreen.h>
 3#include <math.h>
 4
 5Describe(Stack);
 6BeforeEach(Stack) {}
 7AfterEach(Stack) {}
 8
 9Ensure(Stack, push_onto_stack) {
10  Stack *stack = initialize();
11
12  push(stack, 1);
13  assert_that(size(stack), is_equal_to(1));
14
15  push(stack, 2);
16  assert_that(size(stack), is_equal_to(2));
17
18  destroy(stack);
19}
20
21Ensure(Stack, pop_single_item) {
22  Stack *stack = initialize();
23
24  push(stack, 1);
25
26  assert_that(pop(stack), is_equal_to(1));
27  destroy(stack);
28}
29
30Ensure(Stack, pop_successive_items) {
31  Stack *stack = initialize();
32
33  push(stack, 1);
34  push(stack, 2);
35
36  assert_that(pop(stack), is_equal_to(2));
37  assert_that(pop(stack), is_equal_to(1));
38
39  destroy(stack);
40}
41
42Ensure(Stack, when_popping_an_item_off_an_empty_stack) {
43  Stack *stack = initialize();
44
45  assert_that(pop(stack), is_equal_to(NULL));
46
47  destroy(stack);
48}
49
50Ensure(Stack, when_pushing_an_item_on_to_a_full_stack) {
51  Stack *stack = initialize();
52  int max = 2147483647;
53
54  for (int i = 0; i < max; i++)
55    push(stack, 1);
56
57  push(stack, 1);
58
59  assert_that(size(stack), is_equal_to(max));
60  destroy(stack);
61}
62
63TestSuite *stack_tests() {
64  TestSuite *suite = create_test_suite();
65
66  add_test_with_context(suite, Stack, pop_single_item);
67  add_test_with_context(suite, Stack, pop_successive_items);
68  add_test_with_context(suite, Stack, push_onto_stack);
69  add_test_with_context(suite, Stack, when_popping_an_item_off_an_empty_stack);
70  add_test_with_context(suite, Stack, when_pushing_an_item_on_to_a_full_stack);
71
72  return suite;
73}
74
75int main(int argc, char **argv) {
76  TestSuite *suite = create_test_suite();
77  add_suite(suite, stack_tests());
78  return run_test_suite(suite, create_text_reporter());
79}