1 // Copyright (C) 2004-2025 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
];
43 lexstep(int* start
, int length
)
47 while(i
< length
&& carry
)
63 using __gnu_test::test_container
;
64 using __gnu_test::random_access_iterator_wrapper
;
65 using __gnu_test::bidirectional_iterator_wrapper
;
66 using __gnu_test::forward_iterator_wrapper
;
70 test_container
<int,forward_iterator_wrapper
> con(array1
,array1
+ 10);
71 VERIFY(search_n(con
.end(), con
.end(), 0, 1) == con
.end());
72 VERIFY(search_n(con
.end(), con
.end(), 1, 1) == con
.end());
73 VERIFY(search_n(con
.begin(), con
.end(), 1, 1).ptr
== array1
+ 1);
74 VERIFY(search_n(con
.begin(), con
.end(), 2, 1).ptr
== array1
+ 4);
75 VERIFY(search_n(con
.begin(), con
.end(), 3, 1).ptr
== array1
+ 7);
76 VERIFY(search_n(con
.begin(), con
.end(), 3, 0) == con
.end());
78 // Now do a brute-force comparison of the different types
79 for(int i
= 0; i
< TEST_DEPTH
; i
++)
81 for(int j
= 0; j
< i
; j
++)
84 for(int j
= 0; j
< i
; j
++)
86 test_container
<int, forward_iterator_wrapper
>
87 forwardcon(array2
, array2
+ i
);
88 test_container
<int, random_access_iterator_wrapper
>
89 randomcon(array2
, array2
+ i
);
90 test_container
<int, bidirectional_iterator_wrapper
>
91 bidircon(array2
, array2
+ i
);
93 int* t1
= search_n(forwardcon
.begin(),
94 forwardcon
.end(), j
, 1).ptr
;
96 int* t2
= search_n(forwardcon
.begin(),
97 forwardcon
.end(), j
, 1, pred
).ptr
;
98 VERIFY(pred_count
<= i
);
99 int* t3
= search_n(bidircon
.begin(),
100 bidircon
.end(), j
, 1).ptr
;
102 int* t4
= search_n(bidircon
.begin(),
103 bidircon
.end(), j
, 1, pred
).ptr
;
104 VERIFY(pred_count
<= i
);
105 int* t5
= search_n(randomcon
.begin(),
106 randomcon
.end(), j
, 1).ptr
;
108 int* t6
= search_n(randomcon
.begin(),
109 randomcon
.end(), j
, 1, pred
).ptr
;
110 VERIFY(pred_count
<= i
);
111 VERIFY((t1
== t2
) && (t2
== t3
) && (t3
== t4
) &&
112 (t4
== t5
) && (t5
== t6
));
115 while(lexstep(array2
, i
));