1 // Copyright (C) 2004 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 algorithms, search_n
23 #include <testsuite_hooks.h>
24 #include <testsuite_iterators.h>
27 int array1
[11] = {0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0};
28 int array2
[TEST_DEPTH
];
37 lexstep(int* start
, int length
)
41 while(i
< length
&& carry
)
57 using __gnu_test::test_container
;
58 using __gnu_test::random_access_iterator_wrapper
;
59 using __gnu_test::bidirectional_iterator_wrapper
;
60 using __gnu_test::forward_iterator_wrapper
;
64 test_container
<int,forward_iterator_wrapper
> con(array1
,array1
+ 10);
65 VERIFY(search_n(con
.end(), con
.end(), 0, 1) == con
.end());
66 VERIFY(search_n(con
.end(), con
.end(), 1, 1) == con
.end());
67 VERIFY(search_n(con
.begin(), con
.end(), 1, 1).ptr
== array1
+ 1);
68 VERIFY(search_n(con
.begin(), con
.end(), 2, 1).ptr
== array1
+ 4);
69 VERIFY(search_n(con
.begin(), con
.end(), 3, 1).ptr
== array1
+ 7);
70 VERIFY(search_n(con
.begin(), con
.end(), 3, 0) == con
.end());
72 // Now do a brute-force comparison of the different types
73 for(int i
= 0; i
< TEST_DEPTH
; i
++)
75 for(int j
= 0; j
< i
; j
++)
78 for(int j
= 0; j
< i
; j
++)
80 test_container
<int, forward_iterator_wrapper
>
81 forwardcon(array2
, array2
+ i
);
82 test_container
<int, random_access_iterator_wrapper
>
83 randomcon(array2
, array2
+ i
);
84 test_container
<int, bidirectional_iterator_wrapper
>
85 bidircon(array2
, array2
+ i
);
87 int* t1
= search_n(forwardcon
.begin(),
88 forwardcon
.end(), j
, 1).ptr
;
89 int* t2
= search_n(forwardcon
.begin(),
90 forwardcon
.end(), j
, 1, pred
).ptr
;
91 int* t3
= search_n(bidircon
.begin(),
92 bidircon
.end(), j
, 1).ptr
;
93 int* t4
= search_n(bidircon
.begin(),
94 bidircon
.end(), j
, 1, pred
).ptr
;
95 int* t5
= search_n(randomcon
.begin(),
96 randomcon
.end(), j
, 1).ptr
;
97 int* t6
= search_n(randomcon
.begin(),
98 randomcon
.end(), j
, 1, pred
).ptr
;
99 VERIFY((t1
== t2
) && (t2
== t3
) && (t3
== t4
) &&
100 (t4
== t5
) && (t5
== t6
));
103 while(lexstep(array2
, i
));