1 // Copyright (C) 2005 Free Software Foundation, Inc.
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 2, or (at your option)
9 // This library 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 along
15 // with this library; see the file COPYING. If not, write to the Free
16 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19 // 25.1.5 [lib.alg.search]
22 #include <testsuite_hooks.h>
23 #include <testsuite_iterators.h>
25 using __gnu_test::test_container
;
26 using __gnu_test::forward_iterator_wrapper
;
27 using __gnu_test::random_access_iterator_wrapper
;
30 typedef test_container
<int, forward_iterator_wrapper
> Container
;
31 typedef test_container
<int, random_access_iterator_wrapper
> RAcontainer
;
32 int array1
[] = {0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1};
33 int array2
[] = {0, 0, 0};
38 bool test
__attribute__((unused
)) = true;
39 Container
con1(array1
, array1
);
40 Container
con2(array1
, array1
+ 1);
41 VERIFY(search(con1
.begin(), con1
.end(), con2
.begin(), con2
.end()).ptr
== array1
);
42 VERIFY(search(con2
.begin(), con2
.end(), con1
.begin(), con1
.end()).ptr
== array1
);
48 bool test
__attribute__((unused
)) = true;
49 Container
con1(array1
, array1
+ 3);
50 Container
con2(array2
, array2
+ 3);
51 VERIFY(search(con1
.begin(), con1
.end(), con2
.begin(), con2
.end()).ptr
58 bool test
__attribute__((unused
)) = true;
59 Container
con1(array1
+ 3, array1
+ 10);
60 Container
con2(array2
, array2
+ 3);
61 VERIFY(search(con1
.begin(), con1
.end(), con2
.begin(), con2
.end()).ptr
68 bool test
__attribute__((unused
)) = true;
69 Container
con1(array1
, array1
+ 10);
70 Container
con2(array2
, array2
+ 1);
71 VERIFY(search(con1
.begin(), con1
.end(), con2
.begin(), con2
.end()).ptr
78 bool test
__attribute__((unused
)) = true;
79 Container
con1(array1
+ 6, array1
+ 10);
80 Container
con2(array2
, array2
+ 1);
81 VERIFY(search(con1
.begin(), con1
.end(), con2
.begin(), con2
.end()).ptr
88 bool test
__attribute__((unused
)) = true;
89 int array3
[]={2, 2, 1, 2, 3, 5};
90 int array4
[]={1, 2, 3, 4};
91 Container
con1(array3
, array3
+ 3);
92 Container
con2(array3
, array3
+ 4);
93 Container
con3(array3
, array3
+ 5);
94 Container
con4(array3
, array3
+ 6);
95 Container
endcon(array4
, array4
+ 4);
96 VERIFY(search(con1
.begin(), con1
.end(), endcon
.begin(), endcon
.end()).ptr
98 VERIFY(search(con2
.begin(), con2
.end(), endcon
.begin(), endcon
.end()).ptr
100 VERIFY(search(con3
.begin(), con3
.end(), endcon
.begin(), endcon
.end()).ptr
102 VERIFY(search(con4
.begin(), con4
.end(), endcon
.begin(), endcon
.end()).ptr
107 lexstep(int* start
, int length
)
111 while(i
< length
&& carry
)
129 for(int length1
= 0; length1
< 6; length1
++)
131 for(int length2
= 0; length2
< 6; length2
++)
133 std::fill_n(array1
, length1
, 0);
134 while(lexstep(array1
, length1
))
136 std::fill_n(array2
, length2
, 0);
137 while(lexstep(array2
, length2
))
139 Container
con1(array1
, array1
+ length1
);
140 Container
con2(array2
, array2
+ length2
);
141 RAcontainer
rcon1(array1
, array1
+ length1
);
142 RAcontainer
rcon2(array2
, array2
+ length2
);
143 VERIFY(search(con1
.begin(), con1
.end(), con2
.begin(),
145 search(rcon1
.begin(), rcon1
.end(), rcon2
.begin(),