File: stack_test.h

package info (click to toggle)
0ad 0.0.23.1-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 78,292 kB
  • sloc: cpp: 245,166; ansic: 200,249; python: 13,754; sh: 6,104; perl: 4,620; makefile: 977; xml: 810; java: 533; ruby: 229; erlang: 46; pascal: 30; sql: 21; tcl: 4
file content (71 lines) | stat: -rw-r--r-- 1,547 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#ifndef STACK_TEST_H
#define STACK_TEST_H

#include <cxxtest/TestSuite.h>
#include <stack.h>

class stack_test : public CxxTest::TestSuite
{
    
  private:
    stack_t* stack;
  public:

    void setUp() {
      stack = stack_create();
    }

    void tearDown() {
      stack_free(stack);
    }

    void test_create_stack() {
      TS_ASSERT_DIFFERS((stack_t*)0, stack);
    }

    void test_new_stack_is_empty() {
      TS_ASSERT_EQUALS(0, stack_size(stack));
    }

    void test_one_push_add_one_to_size() {
      stack_push(stack, 1);
      TS_ASSERT_EQUALS(1, stack_size(stack));
    }
   
    void test_push_pop_doesnt_change_size() {
      stack_push(stack, 1);
      (void)stack_pop(stack);
      TS_ASSERT_EQUALS(0, stack_size(stack));      
    }

    void test_peak_after_push() {
      stack_push(stack, 1);
      TS_ASSERT_EQUALS(1, stack_peak(stack))
    }

    void test_initial_capacity_is_positive() {
      TS_ASSERT(stack_capacity(stack) > 0);
    }

    void test_pop_on_empty() {
      TS_ASSERT_EQUALS(0, stack_pop(stack));
      TS_ASSERT_EQUALS(0, stack_size(stack));
    }

    void test_peak_on_empty() {
      TS_ASSERT_EQUALS(0, stack_peak(stack));
    }

    void test_capacity_gte_size() {
      TS_ASSERT_LESS_THAN_EQUALS(stack_size(stack), stack_capacity(stack));
      int init_capacity = stack_capacity(stack);
      for (int i=0; i < init_capacity + 1; i++) {
        stack_push(stack, i);
      }
      TS_ASSERT_LESS_THAN_EQUALS(stack_size(stack), stack_capacity(stack));
    }

};

#endif // STACK_TEST_H