summaryrefslogtreecommitdiffstats
path: root/04_exercise/arena/arena_test.c
blob: 51a9b0c0acbe1bea64db6b566fbf54fdcdfc04c4 (plain) (blame)
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
//
// Created by stefan on 10.06.20.
//
#include "arena_list.h"
#include <stdio.h>
#include <assert.h>
bool isEqualTo3(void const *data) {
    int *value = (void *)data;
    return *value == 3;
}
int main() {
    Node arena[5];
    AtomicArenaList al = alInit(arena, 5);
    int data[5] = {1, 2, 3, 4, 5};
    for (int i = 0; i < 5; ++i) {
        alPush(&al, &data[4 - i]);
    }

    for (Node *cur = al.activeList.first; cur != NULL; cur = cur->next) {
        printf("Got digit %d \n", *(int *)cur->value);
    }
    Node const * node = alFindLastElem(&al, &isEqualTo3);
    int * value = (int *) node->value;
    printf("The value was actually %d \n", *value);
    assert(*value == 3);
    for (int i = 0; i < 5; ++i) {
        alRemoveElem(&al, &data[4 - i]);
    }

}