-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack_test.c
More file actions
58 lines (45 loc) · 1.46 KB
/
Copy pathstack_test.c
File metadata and controls
58 lines (45 loc) · 1.46 KB
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
#include "stack.h"
#include <stdio.h>
int test_push() {
Stack s;
if (init(&s) != SUCCESS) return FAIL;
if (push(&s, 10) != SUCCESS) return FAIL;
if (push(&s, 20) != SUCCESS) return FAIL;
if (push(&s, 30) != SUCCESS) return FAIL;
if (push(&s, 40) != SUCCESS) return FAIL;
if (push(&s, 50) != SUCCESS) return FAIL; // Проверка расширения
destroy(&s);
return SUCCESS;
}
int test_pop() {
Stack s;
if (init(&s) != SUCCESS) return FAIL;
if (push(&s, 10) != SUCCESS) return FAIL;
if (push(&s, 20) != SUCCESS) return FAIL;
int val;
if (pop(&s, &val) != SUCCESS) return FAIL;
if (val != 20) return FAIL;
if (pop(&s, &val) != SUCCESS) return FAIL;
if (val != 10) return FAIL;
if (pop(&s, &val) != FAIL) return FAIL; // Попытка удалить из пустого стека
destroy(&s);
return SUCCESS;
}
int main() {
int result = SUCCESS;
printf("=== Тестирование функции push ===\n");
if (test_push() != SUCCESS) {
printf("Тест push провален\n");
result = FAIL;
} else {
printf("Тест push пройден успешно\n");
}
printf("=== Тестирование функции pop ===\n");
if (test_pop() != SUCCESS) {
printf("Тест pop провален\n");
result = FAIL;
} else {
printf("Тест pop пройден успешно\n");
}
return result;
}