Merge reload-branch up to revision 101000
[official-gcc.git] / libstdc++-v3 / testsuite / 25_algorithms / search / 1.cc
blob5a0ed51cb68fb98c5b323bc54905b41823d3d163
1 // Copyright (C) 2005 Free Software Foundation, Inc.
2 //
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)
7 // any later version.
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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
17 // USA.
19 // 25.1.5 [lib.alg.search]
21 #include <algorithm>
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 std::search;
29 typedef test_container<int, forward_iterator_wrapper> Container;
30 int array1[] = {0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1};
31 int array2[] = {0, 0, 0};
33 void
34 test1()
36 bool test __attribute__((unused)) = true;
37 Container con1(array1, array1);
38 Container con2(array1, array1 + 1);
39 VERIFY(search(con1.begin(), con1.end(), con2.begin(), con2.end()).ptr == array1);
40 VERIFY(search(con2.begin(), con2.end(), con1.begin(), con1.end()).ptr == array1);
43 void
44 test2()
46 bool test __attribute__((unused)) = true;
47 Container con1(array1, array1 + 3);
48 Container con2(array2, array2 + 3);
49 VERIFY(search(con1.begin(), con1.end(), con2.begin(), con2.end()).ptr
50 == array1);
53 void
54 test3()
56 bool test __attribute__((unused)) = true;
57 Container con1(array1 + 3, array1 + 10);
58 Container con2(array2, array2 + 3);
59 VERIFY(search(con1.begin(), con1.end(), con2.begin(), con2.end()).ptr
60 == array1 + 10);
63 void
64 test4()
66 bool test __attribute__((unused)) = true;
67 Container con1(array1, array1 + 10);
68 Container con2(array2, array2 + 1);
69 VERIFY(search(con1.begin(), con1.end(), con2.begin(), con2.end()).ptr
70 == array1);
73 void
74 test5()
76 bool test __attribute__((unused)) = true;
77 Container con1(array1 + 6, array1 + 10);
78 Container con2(array2, array2 + 1);
79 VERIFY(search(con1.begin(), con1.end(), con2.begin(), con2.end()).ptr
80 == array1 + 10);
83 void
84 test6()
86 bool test __attribute__((unused)) = true;
87 int array3[]={2, 2, 1, 2, 3, 5};
88 int array4[]={1, 2, 3, 4};
89 Container con1(array3, array3 + 3);
90 Container con2(array3, array3 + 4);
91 Container con3(array3, array3 + 5);
92 Container con4(array3, array3 + 6);
93 Container endcon(array4, array4 + 4);
94 VERIFY(search(con1.begin(), con1.end(), endcon.begin(), endcon.end()).ptr
95 == array3 + 3);
96 VERIFY(search(con2.begin(), con2.end(), endcon.begin(), endcon.end()).ptr
97 == array3 + 4);
98 VERIFY(search(con3.begin(), con3.end(), endcon.begin(), endcon.end()).ptr
99 == array3 + 5);
100 VERIFY(search(con4.begin(), con4.end(), endcon.begin(), endcon.end()).ptr
101 == array3 + 6);
104 int
105 main()
107 test1();
108 test2();
109 test3();
110 test4();
111 test5();
112 test6();