3 // Copyright (C) 2005 Enrico Scholz <enrico.scholz@sigma-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.
23 #include "ensc_vector/list.h"
24 #include "ensc_vector/list-internal.h"
30 int wrapper_exit_code = 2;
33 cmp(void const *lhs_v, void const *rhs_v)
35 int const * const lhs = lhs_v;
36 int const * const rhs = rhs_v;
44 static void A(int val)
46 int * res = List_add(&l, &val);
51 static int const * S(int val)
53 return List_search(&l, &val, cmp);
56 static int const * SSO_F(int val)
58 return List_searchSelfOrg(&l, &val, cmp, listMOVE_FRONT);
61 static int const * SSO_S(int val)
63 return List_searchSelfOrg(&l, &val, cmp, listSHIFT_ONCE);
66 static int P(size_t idx)
68 int const *res = List_at_const(&l, idx);
74 static bool P0(size_t idx)
76 return List_at_const(&l, idx) == 0;
79 static bool CMP(int const *lhs, int rhs)
81 return (lhs!=0 && *lhs==rhs) || (lhs==0 && rhs==-1);
87 List_init(&l, sizeof(int));
89 A(5); A(4); A(3); A(2); A(1); A(0);
90 assert(P(0)==0 && P(1)==1 && P(2)==2 && P(3)==3 && P(4)==4 && P(5)==5 && P0(6));
92 assert(CMP(S(5), 5) && CMP(S(2), 2) && CMP(S(0), 0));
93 assert(CMP(S(42),-1));
95 assert(CMP(SSO_F(5), 5));
96 assert(P(0)==5 && P(1)==0 && P(2)==1 && P(3)==2 && P(4)==3 && P(5)==4 && P0(6));
98 assert(CMP(SSO_F(5), 5));
99 assert(P(0)==5 && P(1)==0 && P(2)==1 && P(3)==2 && P(4)==3 && P(5)==4 && P0(6));
101 assert(CMP(SSO_F(0), 0));
102 assert(P(0)==0 && P(1)==5 && P(2)==1 && P(3)==2 && P(4)==3 && P(5)==4 && P0(6));
104 assert(CMP(SSO_F(4), 4));
105 assert(P(0)==4 && P(1)==0 && P(2)==5 && P(3)==1 && P(4)==2 && P(5)==3 && P0(6));
107 assert(CMP(SSO_F(5), 5));
108 assert(P(0)==5 && P(1)==4 && P(2)==0 && P(3)==1 && P(4)==2 && P(5)==3 && P0(6));
110 assert(CMP(SSO_F(42),-1));
111 assert(P(0)==5 && P(1)==4 && P(2)==0 && P(3)==1 && P(4)==2 && P(5)==3 && P0(6));
115 assert(CMP(SSO_S(3), 3));
116 assert(P(0)==5 && P(1)==4 && P(2)==0 && P(3)==1 && P(4)==3 && P(5)==2 && P0(6));
118 assert(CMP(SSO_S(3), 3));
119 assert(P(0)==5 && P(1)==4 && P(2)==0 && P(3)==3 && P(4)==1 && P(5)==2 && P0(6));
121 assert(CMP(SSO_S(5), 5));
122 assert(P(0)==5 && P(1)==4 && P(2)==0 && P(3)==3 && P(4)==1 && P(5)==2 && P0(6));
124 assert(CMP(SSO_S(4), 4));
125 assert(P(0)==4 && P(1)==5 && P(2)==0 && P(3)==3 && P(4)==1 && P(5)==2 && P0(6));
127 assert(CMP(SSO_S(0), 0));
128 assert(P(0)==4 && P(1)==0 && P(2)==5 && P(3)==3 && P(4)==1 && P(5)==2 && P0(6));
130 assert(CMP(SSO_S(0), 0));
131 assert(P(0)==0 && P(1)==4 && P(2)==5 && P(3)==3 && P(4)==1 && P(5)==2 && P0(6));
133 assert(CMP(SSO_S(0), 0));
134 assert(P(0)==0 && P(1)==4 && P(2)==5 && P(3)==3 && P(4)==1 && P(5)==2 && P0(6));
136 assert(CMP(SSO_S(42), -1));
137 assert(P(0)==0 && P(1)==4 && P(2)==5 && P(3)==3 && P(4)==1 && P(5)==2 && P0(6));