-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsuper_array_test.c
73 lines (66 loc) · 2.38 KB
/
super_array_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
#include "super_array.h"
int main()
{
int rtn;
int index;
int data;
int tmp;
int dtmp;
super_array_header header;
p_super_array_header pheader = &header;
printf("==============testcase1=================\n");
//插入、获取数据,并进行对比测试
rtn = super_array_init(pheader);
if(rtn != 0) {
printf("super_array_init failed\n");
}
tmp = 2;
rtn = insert_node(pheader, (void*)&tmp, &index, NULL);
if(rtn !=0 ) {
printf("super_array insert_node failed , error:%d\n",rtn);
}
rtn = get_data_by_index(pheader, (void*)(&data), index, NULL);
if(rtn != 0) {
printf("super_array get_data_by_index failed , error:%d\n", rtn);
}
printf("testcase 1: insert position:%d write_data=%d read_data:%d\n", \
index, tmp, data);
if(rtn != 0 || tmp != data) {
printf("testcase1 test failed\n");
}
printf("\n\n");
printf("===============testcase2=====================\n");
//test case 2:测试super_array的增删是否正确,插入3、5三个数据
printf("len of super_array before insert : %d\n", get_super_array_len(pheader));
tmp = 3;
rtn = insert_node(pheader, (void*)&tmp, &index, NULL);
tmp = 5;
rtn = insert_node(pheader, (void*)&tmp, &index, NULL);
printf("len of super_array after insert : %d\n", get_super_array_len(pheader));
if(rtn != 0 ) {
printf("testcase2 test failed\n");
}
printf("显示supper_array数据:\n");
get_datas_by_list(pheader, NULL);
printf("\n\n");
printf("===============testcase3=====================\n");
//testcase 3:查找并删除中的节点
printf("显示supper_array数据 before 删除数据2:\n");
get_datas_by_list(pheader, NULL);
tmp = 2;
rtn = delete_node_by_match(pheader, NULL, &tmp, NULL);
printf("显示supper_array数据 after 删除数据2:\n");
get_datas_by_list(pheader, NULL);
printf("\n\n");
printf("===============testcase4=====================\n");
//testcase4: 查找并修改节点
printf("显示supper_array数据 before 修数据3为7:\n");
get_datas_by_list(pheader, NULL);
tmp = 3;
dtmp = 7;
rtn = modify_node_by_match(pheader, NULL, &tmp, (void*)&dtmp, NULL);
printf("显示supper_array数据 after 删除数据3为7:\n");
get_datas_by_list(pheader, NULL);
printf("\n\n");
return 0;
}