-
Notifications
You must be signed in to change notification settings - Fork 5
/
dict_test.c
101 lines (71 loc) · 1.95 KB
/
dict_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
89
90
91
92
93
94
95
96
97
98
99
100
101
#include "dict.h"
#include <stdio.h>
#include <assert.h>
#include <string.h>
void testDictErrorHandling() {
struct dict *d = NULL;
int e = dict_set(d, "hallo", "1");
assert(e == -1);
e = dict_del(d, "hallo");
assert(e == -1);
e = dict_has(d, "halo");
assert(e == 0);
const char *item = dict_get(d, "hallo");
assert(item == NULL);
d = dict_create();
dict_set(d, "hallo", "1");
dict_set(d, "hallo2", "1");
dict_set(d, "hallo3", "2");
e = dict_del(d, "halo");
assert(e == -1);
item = dict_get(d, "halo");
assert(item == NULL);
dict_free(d);
}
void testBasicDict() {
struct dict *d = dict_create();
dict_set(d, "name", "drmaa2");
dict_del(d, "name");
dict_set(d, "name", "drmaa2");
assert(dict_has(d, "name") != 0);
assert(dict_has(d, "language") == 0);
const char *v = dict_get(d, "name");
assert(strcmp(v, "drmaa2") == 0);
dict_set(d, "language", "c");
assert(dict_has(d, "language") != 0);
dict_del(d, "name");
assert(dict_has(d, "name") == 0);
v = dict_get(d, "language");
assert(strcmp(v, "c") == 0);
dict_free(d);
}
void testDict() {
struct dict *d = dict_create(NULL);
dict_set(d, "name", "drmaa2");
dict_set(d, "language", "c");
dict_set(d, "version", "2");
dict_set(d, "age", "2 weeks");
assert(dict_has(d, "language") != 0);
dict_del(d, "age");
dict_del(d, "language");
assert(dict_has(d, "version") != 0);
dict_del(d, "name");
dict_set(d, "version", "3");
const char *v = dict_get(d, "version");
assert(strcmp(v, "3") == 0);
dict_del(d, "version");
dict_set(d, "new_version", "4");
assert(dict_has(d, "version") == 0);
assert(dict_has(d, "new_version") != 0);
dict_free(d);
}
int main() {
return 0;
struct dict *d = dict_create();
assert(d != NULL);
assert(d->head == NULL);
testDictErrorHandling();
testBasicDict();
testDict();
return 0;
}