]>
Commit | Line | Data |
---|---|---|
885824d3 | 1 | /* Part of a driver used to test dbase */ |
2 | ||
3 | /* Include those modules that export things that are used explicitly here */ | |
4 | ||
5 | # include <stdio.h> | |
6 | # include <assert.h> | |
7 | # include "bool.h" | |
8 | # include "employee.h" | |
9 | # include "empset.h" | |
10 | # include "dbase.h" | |
11 | ||
12 | int main (int argc, /*@unused@*/ char *argv[]) | |
13 | /*@globals internalState@*/ /*@modifies internalState@*/ | |
14 | { | |
15 | employee e; | |
16 | empset em1, em2, em3; | |
17 | char na[10000]; | |
18 | char * sprintResult; | |
19 | int i; | |
20 | db_status status; | |
21 | db_q q; | |
22 | ||
23 | /* Initialize all of the LCL-specified modules that were included */ | |
24 | bool_initMod(); | |
25 | employee_initMod(); | |
26 | empset_initMod(); | |
27 | db_initMod(); | |
28 | ||
29 | if (argc != 1) | |
30 | { | |
31 | printf ("FormatPos: Wrong number of arguments. Given %d needs 0.\n", | |
32 | argc - 1); | |
33 | return 1; | |
34 | } | |
35 | ||
36 | /* Unit test empset */ | |
37 | em1 = empset_create(); | |
38 | ||
39 | if (!(empset_size(em1) == 0)) | |
40 | { | |
41 | printf("Size should be 0.\n"); | |
42 | } | |
43 | ||
44 | for (i = 0; i < 500; i++) | |
45 | { | |
46 | e.ssNum = i; | |
47 | e.salary = 100000; | |
48 | e.gen = MALE; | |
49 | e.j = MGR; | |
50 | (void) sprintf(na, "S.S. Doe %d", i); | |
51 | check (employee_setName(&e, na)); | |
52 | empset_insert(em1, e); | |
53 | } | |
54 | ||
55 | if (!(empset_size(em1) == 500)) | |
56 | { | |
57 | printf("Size should be 500.\n"); | |
58 | } | |
59 | ||
60 | for (i = 0; i < 250; i++) | |
61 | { | |
62 | e.ssNum = i; | |
63 | e.salary = 100000; | |
64 | e.gen = MALE; | |
65 | e.j = MGR; | |
66 | (void) sprintf(na, "S.S. Doe %d", i); | |
67 | check (employee_setName(&e, na)); | |
68 | empset_delete(em1, e); | |
69 | } | |
70 | ||
71 | if (!(empset_size(em1) == 250)) | |
72 | { | |
73 | printf("Size should be 250.\n"); | |
74 | } | |
75 | ||
76 | em2 = empset_create(); | |
77 | ||
78 | for (i = 0; i < 100; i++) | |
79 | { | |
80 | e.ssNum = i; | |
81 | e.salary = 100000; | |
82 | e.gen = MALE; | |
83 | e.j = MGR; | |
84 | (void) sprintf(na, "S.S. Doe %d", i); | |
85 | check (employee_setName(&e, na)); | |
86 | empset_insert(em2, e); | |
87 | } | |
88 | ||
89 | em3 = empset_union(em1, em2); | |
90 | ||
91 | if (!(empset_size(em3) == 350)) | |
92 | { | |
93 | printf("Size should be 350.\n"); | |
94 | } | |
95 | ||
96 | empset_intersect(em3, em3); | |
97 | ||
98 | if (!(empset_size(em3) == 350)) | |
99 | { | |
100 | printf("Size should be 350.\n"); | |
101 | } | |
102 | ||
103 | printf("Print two different employees:\n"); | |
104 | ||
105 | for (i = 0; i < 2; i++) | |
106 | { | |
107 | e = empset_choose(em3); | |
108 | employee_sprint(na, e); | |
109 | printf("%s\n", &(na[0])); | |
110 | empset_delete(em3, e); | |
111 | } | |
112 | ||
113 | /* Test dbase */ | |
114 | ||
115 | for (i = 0; i < 20; i++) | |
116 | { | |
117 | e.ssNum = i; | |
118 | e.salary = 10 * i; | |
119 | ||
120 | if (i < 10) | |
121 | { | |
122 | e.gen = MALE; | |
123 | } | |
124 | else | |
125 | { | |
126 | e.gen = FEMALE; | |
127 | } | |
128 | ||
129 | if (i < 15) | |
130 | { | |
131 | e.j = NONMGR; | |
132 | } | |
133 | else | |
134 | { | |
135 | e.j = MGR; | |
136 | } | |
137 | ||
138 | (void) sprintf(na, "J. Doe %d", i); | |
139 | check (employee_setName(&e, na)); | |
140 | ||
141 | if ((i/2)*2 == i) | |
142 | { | |
143 | check (db_hire(e) == DBS_OK); | |
144 | } | |
145 | else | |
146 | { | |
147 | db_uncheckedHire(e); status = db_hire(e); | |
148 | } | |
149 | } | |
150 | ||
151 | printf("Should print true: %s\n", | |
152 | bool_unparse (/*@-usedef@*/ status == DBS_DUPLERR /*@=usedef@*/)); | |
153 | ||
154 | printf("Employees 0 - 19\n"); | |
155 | db_print(); | |
156 | check (db_fire(17)); | |
157 | q.g = FEMALE; q.j = JOB_UNKNOWN; q.l = 158; q.h = 185; | |
158 | printf("Employees 0 - 16, 18 - 19\n"); | |
159 | db_print(); | |
160 | ||
161 | empset_final (em1); | |
162 | i = db_query(q, em1 = empset_create()); | |
163 | sprintResult = empset_sprint(em1); | |
164 | printf("Should get two females: %d\n%s\n", i, sprintResult); | |
165 | free(sprintResult); | |
166 | ||
167 | q.g = MALE; q.j = NONMGR; q.l = 0; q.h = 185; | |
168 | empset_final (em2); | |
169 | i = db_query(q, em2 = empset_create()); | |
170 | empset_final (em3); | |
171 | em3 = empset_disjointUnion(em2, em1); | |
172 | sprintResult = empset_sprint(em3); | |
173 | i = empset_size(em3); | |
174 | printf("Should get two females and ten males: %d\n%s\n", i, sprintResult); | |
175 | free(sprintResult); | |
176 | ||
177 | empset_intersect(em1, em3); | |
178 | sprintResult = empset_sprint(em1); | |
179 | i = empset_size(em1); | |
180 | printf("Should get two females: %d\n%s\n", i, sprintResult); | |
181 | free(sprintResult); | |
182 | ||
183 | check (db_fire(empset_choose(em3).ssNum)); | |
184 | printf("Should get 18 employees\n"); | |
185 | db_print(); | |
186 | ||
187 | empset_final (em1); | |
188 | empset_final (em2); | |
189 | empset_final (em3); | |
190 | return 0; | |
191 | } |