1 // Copyright (C) 2004-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 // { dg-options "-DTEST_DEPTH=10" { target simulator } }
20 // 25 algorithms, search_n
24 #include <testsuite_hooks.h>
25 #include <testsuite_iterators.h>
31 int array1[11] = {0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0};
32 int array2[TEST_DEPTH];
41 lexstep(int* start, int length)
45 while(i < length && carry)
61 using __gnu_test::test_container;
62 using __gnu_test::random_access_iterator_wrapper;
63 using __gnu_test::bidirectional_iterator_wrapper;
64 using __gnu_test::forward_iterator_wrapper;
68 test_container<int,forward_iterator_wrapper> con(array1,array1 + 10);
69 VERIFY(search_n(con.end(), con.end(), 0, 1) == con.end());
70 VERIFY(search_n(con.end(), con.end(), 1, 1) == con.end());
71 VERIFY(search_n(con.begin(), con.end(), 1, 1).ptr == array1 + 1);
72 VERIFY(search_n(con.begin(), con.end(), 2, 1).ptr == array1 + 4);
73 VERIFY(search_n(con.begin(), con.end(), 3, 1).ptr == array1 + 7);
74 VERIFY(search_n(con.begin(), con.end(), 3, 0) == con.end());
76 // Now do a brute-force comparison of the different types
77 for(int i = 0; i < TEST_DEPTH; i++)
79 for(int j = 0; j < i; j++)
82 for(int j = 0; j < i; j++)
84 test_container<int, forward_iterator_wrapper>
85 forwardcon(array2, array2 + i);
86 test_container<int, random_access_iterator_wrapper>
87 randomcon(array2, array2 + i);
88 test_container<int, bidirectional_iterator_wrapper>
89 bidircon(array2, array2 + i);
91 int* t1 = search_n(forwardcon.begin(),
92 forwardcon.end(), j, 1).ptr;
93 int* t2 = search_n(forwardcon.begin(),
94 forwardcon.end(), j, 1, pred).ptr;
95 int* t3 = search_n(bidircon.begin(),
96 bidircon.end(), j, 1).ptr;
97 int* t4 = search_n(bidircon.begin(),
98 bidircon.end(), j, 1, pred).ptr;
99 int* t5 = search_n(randomcon.begin(),
100 randomcon.end(), j, 1).ptr;
101 int* t6 = search_n(randomcon.begin(),
102 randomcon.end(), j, 1, pred).ptr;
103 VERIFY((t1 == t2) && (t2 == t3) && (t3 == t4) &&
104 (t4 == t5) && (t5 == t6));
107 while(lexstep(array2, i));