File: teststack.c

package info (click to toggle)
kissat 4.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,068 kB
  • sloc: ansic: 39,201; sh: 1,226; makefile: 91
file content (74 lines) | stat: -rw-r--r-- 1,698 bytes parent folder | download | duplicates (2)
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
72
73
74
#include "../src/allocate.h"

#include "test.h"

static void test_stack_basic (void) {
  DECLARE_AND_INIT_SOLVER (solver);
  STACK (unsigned) stack;
  assert (sizeof stack == 3 * sizeof (void *));
  INIT_STACK (stack);
  assert (EMPTY_STACK (stack));
  assert (FULL_STACK (stack));
  const unsigned n = 100;
  for (unsigned i = 0; i < n; i++) {
    assert (SIZE_STACK (stack) == i);
    PUSH_STACK (stack, i);
  }
#ifdef METRICS
  assert (solver->statistics.allocated_current == 128 * sizeof (unsigned));
#endif
  {
    unsigned i = 0;
    for (all_stack (unsigned, e, stack))
      assert (e == i++);
    assert (i == n);
  }
  {
    unsigned i = n - 1;
    while (!EMPTY_STACK (stack)) {
      unsigned tmp = TOP_STACK (stack);
      assert (tmp == i);
      tmp = POP_STACK (stack);
      assert (tmp == i);
      i--;
    }
    assert (i == 0u - 1);
  }
  RELEASE_STACK (stack);
#ifdef METRICS
  assert (!solver->statistics.allocated_current);
#endif
}

typedef struct odd_sized odd_sized;

struct odd_sized {
  unsigned a, b, c;
};

// clang-format off
typedef STACK (odd_sized) odd_sized_stack;
// clang-format on

static void test_shrink_stack (void) {
  DECLARE_AND_INIT_SOLVER (solver);
  odd_sized element;
  memset (&element, 0, sizeof element);
  odd_sized_stack stack;
  INIT_STACK (stack);
  PUSH_STACK (stack, element);
  PUSH_STACK (stack, element);
  PUSH_STACK (stack, element);
  PUSH_STACK (stack, element);
  RESIZE_STACK (stack, 1);
  SHRINK_STACK (stack);
  RELEASE_STACK (stack);
#ifdef METRICS
  assert (!solver->statistics.allocated_current);
#endif
}

void tissat_schedule_stack (void) {
  SCHEDULE_FUNCTION (test_stack_basic);
  SCHEDULE_FUNCTION (test_shrink_stack);
}