-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_int.c
More file actions
41 lines (35 loc) · 841 Bytes
/
test_int.c
File metadata and controls
41 lines (35 loc) · 841 Bytes
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
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include "stack_int.h"
int main(void)
{
stack_t *s = stack_new((stack_params_t){
.clone = NULL,
.free = NULL
});
int data[] = {3, 4, 5, 6};
int temp;
for (size_t i = 0; i < 4; i++) {
if (!stack_push(s, data[i])) {
perror("Failed to push data\n");
goto FREE;
}
temp = stack_peek(s);
if (temp != data[i]) {
fprintf(stderr, "Wrong data: %d\n", temp);
goto FREE;
}
}
int data1[] = {6, 5, 4, 3};
for (size_t i = 0; i < 4; i++) {
temp = stack_pop(s);
if (temp != data1[i]) {
fprintf(stderr, "Wrong data: %d\n", temp);
goto FREE;
}
}
FREE:
stack_free(s);
return 0;
}