stack_u64

Stack for uin64_t's
git clone git://www.tkruger.se/stack_u64.git
Log | Files | Refs | README

test_stack_u64.c (1558B)


      1 #include <stdlib.h>
      2 #include <stdio.h>
      3 #include <assert.h>
      4 #include "stack_u64.h"
      5 
      6 static void test_stack_u64_init() {
      7   stack_u64_t t;
      8   stack_u64_init(&t);
      9 
     10   assert(t.nmemb == 0);
     11   assert(t.alloc > 0);
     12   assert(t.data != NULL);
     13 
     14   stack_u64_clear(&t);
     15 }
     16 
     17 static void test_stack_u64_push() {
     18   stack_u64_t t;
     19   stack_u64_init(&t);
     20 
     21   uint64_t i;
     22   for (i = 0; i < 2 * BASE_STACK_SIZE; i++) {
     23     stack_u64_push(&t, i);
     24   }
     25 
     26   assert(t.alloc == 2 * BASE_STACK_SIZE);
     27   assert(t.nmemb == 2 * BASE_STACK_SIZE);
     28   for (i = 0; i < 2 * BASE_STACK_SIZE; i++) {
     29     assert(t.data[i] == i);
     30   }
     31 
     32   stack_u64_clear(&t);
     33 }
     34 
     35 static void test_stack_u64_get_getlast() {
     36   stack_u64_t t;
     37   stack_u64_init(&t);
     38 
     39   uint64_t i;
     40   for (i = 0; i < 2 * BASE_STACK_SIZE; i++) {
     41     stack_u64_push(&t, i);
     42   }
     43 
     44   for (i = 0; i < t.nmemb; i++) {
     45     assert(stack_u64_get(&t, i) == i);
     46   }
     47   assert(stack_u64_getlast(&t) == 2 * BASE_STACK_SIZE - 1);
     48 
     49   stack_u64_clear(&t);
     50 }
     51 
     52 static void test_stack_u64_pop() {
     53   stack_u64_t t;
     54   stack_u64_init(&t);
     55 
     56   stack_u64_push(&t, 13);
     57   stack_u64_push(&t, 16);
     58   stack_u64_push(&t, 17);
     59 
     60   assert(t.nmemb == 3);
     61   assert(stack_u64_pop(&t) == 17);
     62   assert(t.nmemb == 2);
     63   assert(stack_u64_pop(&t) == 16);
     64   assert(t.nmemb == 1);
     65   assert(stack_u64_pop(&t) == 13);
     66   assert(t.nmemb == 0);
     67   assert(stack_u64_pop(&t) == STACK_U64_EMPTY_POP);
     68   assert(t.nmemb == 0);
     69 
     70   stack_u64_clear(&t);
     71 }
     72 
     73 int main() {
     74   test_stack_u64_init();
     75   test_stack_u64_push();
     76   test_stack_u64_pop();
     77   test_stack_u64_get_getlast();
     78 
     79   printf("test ok\n");
     80 }