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"
28 int wrapper_exit_code = 2;
31 cmp(void const *lhs_v, void const *rhs_v)
33 int const * const lhs = lhs_v;
34 int const * const rhs = rhs_v;
41 static void I(int val)
43 *(int *)Vector_insert(&v, &val, cmp) = val;
46 static void P(int val)
48 *(int *)Vector_pushback(&v) = val;
51 static int E(size_t idx)
53 return ((int const *)Vector_begin_const(&v))[idx];
56 static int const * S(int val)
58 return Vector_search_const(&v, &val, cmp);
61 static int const * S_F(int val)
63 return Vector_searchSelfOrg(&v, &val, cmp, vecMOVE_FRONT);
66 static int const * S_S(int val)
68 return Vector_searchSelfOrg(&v, &val, cmp, vecSHIFT_ONCE);
71 static bool CMP(int const *lhs, int val)
73 return (lhs!=0 && val==*lhs) || (lhs==0 && val==-1);
78 Vector_init(&v, sizeof(int));
80 I(0); I(1); I(2); I(3);
81 assert(Vector_count(&v)==4);
82 assert(E(0)==0 && E(1)==1 && E(2)==2 && E(3)==3);
86 assert(Vector_count(&v)==0);
88 assert(Vector_count(&v)==1);
93 I(3); I(0); I(2); I(1); I(5); I(4); I(7); I(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));
98 assert(S(0) && *S(0)==0);
102 assert(Vector_count(&v)==0);
104 P(3); P(0); P(2); P(1); P(5); P(4); P(7); P(6);
105 assert(Vector_count(&v)==8);
106 assert((E(0)==3 && E(1)==0 && E(2)==2 && E(3)==1 &&
107 E(4)==5 && E(5)==4 && E(6)==7 && E(7)==6));
109 Vector_sort(&v, cmp);
110 assert(Vector_count(&v)==8);
111 assert((E(0)==0 && E(1)==1 && E(2)==2 && E(3)==3 &&
112 E(4)==4 && E(5)==5 && E(6)==6 && E(7)==7));
115 assert(Vector_count(&v)==7);
116 assert((E(0)==0 && E(1)==1 && E(2)==2 && E(3)==3 &&
117 E(4)==4 && E(5)==5 && E(6)==6));
119 Vector_unique(&v, cmp);
120 assert(Vector_count(&v)==7);
121 assert((E(0)==0 && E(1)==1 && E(2)==2 && E(3)==3 &&
122 E(4)==4 && E(5)==5 && E(6)==6));
125 assert(Vector_count(&v)==0);
128 P(3); P(7); P(0); P(2); P(1); P(2); P(5); P(4); P(5); P(7); P(6);
129 assert(Vector_count(&v)==11);
130 Vector_sort(&v, cmp);
131 assert(Vector_count(&v)==11);
132 assert((E(0)==0 && E(1)==1 && E(2)==2 && E(3)==2 &&
133 E(4)==3 && E(5)==4 && E(6)==5 && E(7)==5 &&
134 E(8)==6 && E(9)==7 && E(10)==7));
136 Vector_unique(&v, cmp);
137 assert(Vector_count(&v)==8);
138 assert((E(0)==0 && E(1)==1 && E(2)==2 && E(3)==3 &&
139 E(4)==4 && E(5)==5 && E(6)==6 && E(7)==7));
141 assert(CMP(S_F(0),0));
142 assert((E(0)==0 && E(1)==1 && E(2)==2 && E(3)==3 && E(4)==4 && E(5)==5 && E(6)==6 && E(7)==7));
144 assert(CMP(S_F(1),1));
145 assert((E(0)==1 && E(1)==0 && E(2)==2 && E(3)==3 && E(4)==4 && E(5)==5 && E(6)==6 && E(7)==7));
147 assert(CMP(S_F(7),7));
148 assert((E(0)==7 && E(1)==1 && E(2)==0 && E(3)==2 && E(4)==3 && E(5)==4 && E(6)==5 && E(7)==6));
150 assert(CMP(S_F(3),3));
151 assert((E(0)==3 && E(1)==7 && E(2)==1 && E(3)==0 && E(4)==2 && E(5)==4 && E(6)==5 && E(7)==6));
153 assert(CMP(S_F(3),3));
154 assert((E(0)==3 && E(1)==7 && E(2)==1 && E(3)==0 && E(4)==2 && E(5)==4 && E(6)==5 && E(7)==6));
156 assert(CMP(S_F(42), -1));
157 assert((E(0)==3 && E(1)==7 && E(2)==1 && E(3)==0 && E(4)==2 && E(5)==4 && E(6)==5 && E(7)==6));
160 assert(CMP(S_S(6), 6));
161 assert((E(0)==3 && E(1)==7 && E(2)==1 && E(3)==0 && E(4)==2 && E(5)==4 && E(6)==6 && E(7)==5));
163 assert(CMP(S_S(6), 6));
164 assert((E(0)==3 && E(1)==7 && E(2)==1 && E(3)==0 && E(4)==2 && E(5)==6 && E(6)==4 && E(7)==5));
166 assert(CMP(S_S(6), 6));
167 assert((E(0)==3 && E(1)==7 && E(2)==1 && E(3)==0 && E(4)==6 && E(5)==2 && E(6)==4 && E(7)==5));
169 assert(CMP(S_S(7), 7));
170 assert((E(0)==7 && E(1)==3 && E(2)==1 && E(3)==0 && E(4)==6 && E(5)==2 && E(6)==4 && E(7)==5));
172 assert(CMP(S_S(7), 7));
173 assert((E(0)==7 && E(1)==3 && E(2)==1 && E(3)==0 && E(4)==6 && E(5)==2 && E(6)==4 && E(7)==5));
175 assert(CMP(S_S(42), -1));
176 assert((E(0)==7 && E(1)==3 && E(2)==1 && E(3)==0 && E(4)==6 && E(5)==2 && E(6)==4 && E(7)==5));