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.
25 #include "ensc_vector/list.h"
26 #include "ensc_vector/list-internal.h"
32 int wrapper_exit_code = 2;
35 cmp(void const *lhs_v, void const *rhs_v)
37 int const * const lhs = lhs_v;
38 int const * const rhs = rhs_v;
46 static void A(int val)
48 int * res = List_add(&l, &val);
53 static int const * S(int val)
55 return List_search(&l, &val, cmp);
58 static int const * SSO_F(int val)
60 return List_searchSelfOrg(&l, &val, cmp, listMOVE_FRONT);
63 static int const * SSO_S(int val)
65 return List_searchSelfOrg(&l, &val, cmp, listSHIFT_ONCE);
68 static int P(size_t idx)
70 int const *res = List_at_const(&l, idx);
76 static bool P0(size_t idx)
78 return List_at_const(&l, idx) == 0;
81 static bool CMP(int const *lhs, int rhs)
83 return (lhs!=0 && *lhs==rhs) || (lhs==0 && rhs==-1);
89 List_init(&l, sizeof(int));
91 A(5); A(4); A(3); A(2); A(1); A(0);
92 assert(P(0)==0 && P(1)==1 && P(2)==2 && P(3)==3 && P(4)==4 && P(5)==5 && P0(6));
94 assert(CMP(S(5), 5) && CMP(S(2), 2) && CMP(S(0), 0));
95 assert(CMP(S(42),-1));
97 assert(CMP(SSO_F(5), 5));
98 assert(P(0)==5 && P(1)==0 && P(2)==1 && P(3)==2 && P(4)==3 && P(5)==4 && P0(6));
100 assert(CMP(SSO_F(5), 5));
101 assert(P(0)==5 && P(1)==0 && P(2)==1 && P(3)==2 && P(4)==3 && P(5)==4 && P0(6));
103 assert(CMP(SSO_F(0), 0));
104 assert(P(0)==0 && P(1)==5 && P(2)==1 && P(3)==2 && P(4)==3 && P(5)==4 && P0(6));
106 assert(CMP(SSO_F(4), 4));
107 assert(P(0)==4 && P(1)==0 && P(2)==5 && P(3)==1 && P(4)==2 && P(5)==3 && P0(6));
109 assert(CMP(SSO_F(5), 5));
110 assert(P(0)==5 && P(1)==4 && P(2)==0 && P(3)==1 && P(4)==2 && P(5)==3 && P0(6));
112 assert(CMP(SSO_F(42),-1));
113 assert(P(0)==5 && P(1)==4 && P(2)==0 && P(3)==1 && P(4)==2 && P(5)==3 && P0(6));
117 assert(CMP(SSO_S(3), 3));
118 assert(P(0)==5 && P(1)==4 && P(2)==0 && P(3)==1 && P(4)==3 && P(5)==2 && P0(6));
120 assert(CMP(SSO_S(3), 3));
121 assert(P(0)==5 && P(1)==4 && P(2)==0 && P(3)==3 && P(4)==1 && P(5)==2 && P0(6));
123 assert(CMP(SSO_S(5), 5));
124 assert(P(0)==5 && P(1)==4 && P(2)==0 && P(3)==3 && P(4)==1 && P(5)==2 && P0(6));
126 assert(CMP(SSO_S(4), 4));
127 assert(P(0)==4 && P(1)==5 && P(2)==0 && P(3)==3 && P(4)==1 && P(5)==2 && P0(6));
129 assert(CMP(SSO_S(0), 0));
130 assert(P(0)==4 && P(1)==0 && P(2)==5 && P(3)==3 && P(4)==1 && P(5)==2 && P0(6));
132 assert(CMP(SSO_S(0), 0));
133 assert(P(0)==0 && P(1)==4 && P(2)==5 && P(3)==3 && P(4)==1 && P(5)==2 && P0(6));
135 assert(CMP(SSO_S(0), 0));
136 assert(P(0)==0 && P(1)==4 && P(2)==5 && P(3)==3 && P(4)==1 && P(5)==2 && P0(6));
138 assert(CMP(SSO_S(42), -1));
139 assert(P(0)==0 && P(1)==4 && P(2)==5 && P(3)==3 && P(4)==1 && P(5)==2 && P0(6));