1 /* vector_test.c .... Test the vector package.
2 * C. Scott Ananian <cananian@alumni.princeton.edu>
4 * $Id: vector_test.c,v 1.2 2003/06/17 17:25:47 reink Exp $
16 VECTOR
*v
= vector_create();
18 assert(vector_size(v
)==0);
19 for (i
=0; i
<=MAX
; i
++) {
20 assert(!vector_contains(v
, i
));
21 assert(!vector_remove(v
, i
));
22 assert(!vector_search(v
, i
, (PPTP_CALL
**)&j
));
23 retval
= vector_scan(v
, i
, MAX
*2, &j
);
28 for (i
=1; i
<=MAX
; i
++) {
29 retval
= vector_insert(v
, i
, (PPTP_CALL
*)i
);
31 assert(vector_size(v
)==i
);
33 for (i
=1; i
<MAX
; i
++) {
34 retval
= vector_search(v
, i
, (PPTP_CALL
**)&j
);
37 retval
= vector_contains(v
, i
);
40 assert(vector_size(v
)==MAX
);
41 retval
= vector_contains(v
, MAX
+1);
43 retval
= vector_search(v
, MAX
+1, (PPTP_CALL
**)&j
);
46 retval
= vector_scan(v
, 0, MAX
, &j
);
49 retval
= vector_scan(v
, 1, MAX
, &j
);
51 retval
= vector_scan(v
, 1, MAX
+1, &j
);
54 retval
= vector_scan(v
, 1, MAX
+MAX
, &j
);
58 for (i
=0; i
<(MAX
*10); i
++) {
59 int k
= (random() % MAX
) + 1;
60 assert(vector_contains(v
, k
));
61 assert(!vector_scan(v
, 1, k
, &j
));
62 assert(!vector_scan(v
, k
, MAX
, &j
));
63 retval
= vector_remove(v
, k
);
65 assert(vector_size(v
)==MAX
-1);
66 assert(!vector_contains(v
, k
));
67 assert(!vector_search(v
, k
, (PPTP_CALL
**) &j
));
68 retval
= vector_scan(v
, 1, MAX
, &j
);
71 retval
= vector_insert(v
, k
, (PPTP_CALL
*) k
);
73 assert(vector_size(v
)==MAX
);
74 assert(vector_contains(v
, k
));
75 assert(!vector_scan(v
, 1, MAX
, &j
));
76 retval
= vector_search(v
, k
, (PPTP_CALL
**) &j
);
81 for (i
=1; i
<=MAX
; i
++) {
82 assert(vector_size(v
)==MAX
-(i
-1));
84 assert(vector_size(v
)==MAX
-i
);
85 assert(!vector_contains(v
, i
));
86 retval
= vector_search(v
, i
, (PPTP_CALL
**) &j
);
88 retval
= vector_scan(v
, 1, MAX
, &j
);
92 assert(vector_size(v
)==0);