3 // Copyright (C) 2004 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; version 2 of the License.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #include "ensc_vector/vector.h"
27 int wrapper_exit_code = 2;
30 cmp(void const *lhs_v, void const *rhs_v)
32 int const * const lhs = lhs_v;
33 int const * const rhs = rhs_v;
40 static void I(int val)
42 *(int *)Vector_insert(&v, &val, cmp) = val;
45 static void P(int val)
47 *(int *)Vector_pushback(&v) = val;
50 static int E(size_t idx)
52 return ((int const *)Vector_begin_const(&v))[idx];
55 static int const * S(int val)
57 return Vector_search_const(&v, &val, cmp);
62 Vector_init(&v, sizeof(int));
64 I(0); I(1); I(2); I(3);
65 assert(Vector_count(&v)==4);
66 assert(E(0)==0 && E(1)==1 && E(2)==2 && E(3)==3);
70 assert(Vector_count(&v)==0);
72 assert(Vector_count(&v)==1);
77 I(3); I(0); I(2); I(1); I(5); I(4); I(7); I(6);
78 assert(Vector_count(&v)==8);
79 assert((E(0)==0 && E(1)==1 && E(2)==2 && E(3)==3 &&
80 E(4)==4 && E(5)==5 && E(6)==6 && E(7)==7));
82 assert(S(0) && *S(0)==0);
86 assert(Vector_count(&v)==0);
88 P(3); P(0); P(2); P(1); P(5); P(4); P(7); P(6);
89 assert(Vector_count(&v)==8);
90 assert((E(0)==3 && E(1)==0 && E(2)==2 && E(3)==1 &&
91 E(4)==5 && E(5)==4 && E(6)==7 && E(7)==6));
94 assert(Vector_count(&v)==8);
95 assert((E(0)==0 && E(1)==1 && E(2)==2 && E(3)==3 &&
96 E(4)==4 && E(5)==5 && E(6)==6 && E(7)==7));
99 assert(Vector_count(&v)==7);
100 assert((E(0)==0 && E(1)==1 && E(2)==2 && E(3)==3 &&
101 E(4)==4 && E(5)==5 && E(6)==6));
103 Vector_unique(&v, cmp);
104 assert(Vector_count(&v)==7);
105 assert((E(0)==0 && E(1)==1 && E(2)==2 && E(3)==3 &&
106 E(4)==4 && E(5)==5 && E(6)==6));
109 assert(Vector_count(&v)==0);
112 P(3); P(7); P(0); P(2); P(1); P(2); P(5); P(4); P(5); P(7); P(6);
113 assert(Vector_count(&v)==11);
114 Vector_sort(&v, cmp);
115 assert(Vector_count(&v)==11);
116 assert((E(0)==0 && E(1)==1 && E(2)==2 && E(3)==2 &&
117 E(4)==3 && E(5)==4 && E(6)==5 && E(7)==5 &&
118 E(8)==6 && E(9)==7 && E(10)==7));
120 Vector_unique(&v, cmp);
121 assert(Vector_count(&v)==8);
122 assert((E(0)==0 && E(1)==1 && E(2)==2 && E(3)==3 &&
123 E(4)==4 && E(5)==5 && E(6)==6 && E(7)==7));