This repository has been archived by the owner on Feb 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdl_list_test.c
88 lines (79 loc) · 2.13 KB
/
dl_list_test.c
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
INFORMATION
****************************
Functions for testing struct list
*/
#ifdef LIST_TEST
#include <assert.h>
#include <stdio.h>
#include "dl_list.h"
static struct list_t* fill_list_with_cells(struct list_t* l, int n);
static void reverse_cells(struct list_t* l, struct list_t* m, int n);
static void delete_cells(struct list_t* l, int n);
void dl_list_test() {
const int n = 10000;
struct list_t *l, *m;
l = make_list();
assert(l != NULL);
l = fill_list_with_cells(l, n);
printf("dl_list test level 1 complete\n");
m = make_list();
assert(m != NULL);
reverse_cells(l, m, n);
printf("dl_list test level 2 complete\n");
delete_cells(m, n);
destroy_list(l);
destroy_list(m);
printf("dl_list test level 3 complete\n");
printf("dl_list test complete\n");
}
static struct list_t* fill_list_with_cells(struct list_t* l, int n) {
int i;
struct cell* c;
assert(l != NULL);
for(i = 0; i < n; i++) {
c = make_cell_n((long long int) i);
insert_to_head(l, c);
}
assert(l->length == (unsigned long long) n);
c = l->head;
for(i = 0; i < n - 1; i++) {
assert(c != NULL);
assert(cell_name(c) - 1 == cell_name(next_cell(c)));
c = next_cell(c);
}
assert(c == l->end);
return l;
}
static void reverse_cells(struct list_t* l, struct list_t* m, int n) {
int i;
struct cell* c;
assert(l != NULL);
assert(m != NULL);
while(l->length != 0) {
replace_lf_to_head(l, m, l->head);
}
assert(m->length == (unsigned long long) n);
c = m->head;
for(i = 0; i < n - 1; i++) {
assert(c != NULL);
assert(cell_name(c) + 1 == cell_name(next_cell(c)));
c = next_cell(c);
}
assert(c == m->end);
}
static void delete_cells(struct list_t* l, int n) {
assert(l != NULL);
assert(l->length == (unsigned long long) n);
while(n != 0) {
assert(l->head != NULL);
assert(l->end != NULL);
assert(l->length > 0);
delete_last_elem(l);
n--;
}
assert(l->length == 0);
assert(l->head == NULL);
assert(l->end == NULL);
}
#endif