1 // Copyright (C) 2005-2013 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 3, 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 COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
18 // 25.1.5 [lib.alg.search]
21 #include <testsuite_hooks.h>
22 #include <testsuite_iterators.h>
24 using __gnu_test::test_container;
25 using __gnu_test::forward_iterator_wrapper;
26 using __gnu_test::random_access_iterator_wrapper;
29 typedef test_container<int, forward_iterator_wrapper> Container;
30 typedef test_container<int, random_access_iterator_wrapper> RAcontainer;
31 int array1[] = {0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1};
32 int array2[] = {0, 0, 0};
37 bool test __attribute__((unused)) = true;
38 Container con1(array1, array1);
39 Container con2(array1, array1 + 1);
40 VERIFY(search(con1.begin(), con1.end(), con2.begin(), con2.end()).ptr == array1);
41 VERIFY(search(con2.begin(), con2.end(), con1.begin(), con1.end()).ptr == array1);
47 bool test __attribute__((unused)) = true;
48 Container con1(array1, array1 + 3);
49 Container con2(array2, array2 + 3);
50 VERIFY(search(con1.begin(), con1.end(), con2.begin(), con2.end()).ptr
57 bool test __attribute__((unused)) = true;
58 Container con1(array1 + 3, array1 + 10);
59 Container con2(array2, array2 + 3);
60 VERIFY(search(con1.begin(), con1.end(), con2.begin(), con2.end()).ptr
67 bool test __attribute__((unused)) = true;
68 Container con1(array1, array1 + 10);
69 Container con2(array2, array2 + 1);
70 VERIFY(search(con1.begin(), con1.end(), con2.begin(), con2.end()).ptr
77 bool test __attribute__((unused)) = true;
78 Container con1(array1 + 6, array1 + 10);
79 Container con2(array2, array2 + 1);
80 VERIFY(search(con1.begin(), con1.end(), con2.begin(), con2.end()).ptr
87 bool test __attribute__((unused)) = true;
88 int array3[]={2, 2, 1, 2, 3, 5};
89 int array4[]={1, 2, 3, 4};
90 Container con1(array3, array3 + 3);
91 Container con2(array3, array3 + 4);
92 Container con3(array3, array3 + 5);
93 Container con4(array3, array3 + 6);
94 Container endcon(array4, array4 + 4);
95 VERIFY(search(con1.begin(), con1.end(), endcon.begin(), endcon.end()).ptr
97 VERIFY(search(con2.begin(), con2.end(), endcon.begin(), endcon.end()).ptr
99 VERIFY(search(con3.begin(), con3.end(), endcon.begin(), endcon.end()).ptr
101 VERIFY(search(con4.begin(), con4.end(), endcon.begin(), endcon.end()).ptr
106 lexstep(int* start, int length)
110 while(i < length && carry)
128 for(int length1 = 0; length1 < 6; length1++)
130 for(int length2 = 0; length2 < 6; length2++)
132 std::fill_n(array1, length1, 0);
133 while(lexstep(array1, length1))
135 std::fill_n(array2, length2, 0);
136 while(lexstep(array2, length2))
138 Container con1(array1, array1 + length1);
139 Container con2(array2, array2 + length2);
140 RAcontainer rcon1(array1, array1 + length1);
141 RAcontainer rcon2(array2, array2 + length2);
142 VERIFY(search(con1.begin(), con1.end(), con2.begin(),
144 search(rcon1.begin(), rcon1.end(), rcon2.begin(),