OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [libstdc++-v3/] [testsuite/] [25_algorithms/] [search_n/] [iterator.cc] - Blame information for rev 19

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 19 jlechner
// Copyright (C) 2004 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.
8
 
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.
13
 
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,
17
// USA.
18
 
19
// 25 algorithms, search_n
20
 
21
#include <algorithm>
22
#include <functional>
23
#include <testsuite_hooks.h>
24
#include <testsuite_iterators.h>
25
 
26
#define TEST_DEPTH 14
27
int array1[11] = {0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0};
28
int array2[TEST_DEPTH];
29
 
30
bool
31
pred(int i, int j)
32
{
33
  return i == j;
34
}
35
 
36
bool
37
lexstep(int* start, int length)
38
{
39
  int i = 0;
40
  int carry = 1;
41
  while(i < length && carry)
42
    {
43
      if(start[i] == 1)
44
        start[i] = 0;
45
      else
46
        {
47
          start[i] = 1;
48
          carry = 0;
49
        }
50
      i++;
51
    }
52
  return !carry;
53
}
54
 
55
using __gnu_test::test_container;
56
using __gnu_test::random_access_iterator_wrapper;
57
using __gnu_test::bidirectional_iterator_wrapper;
58
using __gnu_test::forward_iterator_wrapper;
59
 
60
int main() {
61
  test_container<int,forward_iterator_wrapper> con(array1,array1 + 10);
62
  VERIFY(search_n(con.end(), con.end(), 0, 1) == con.end());
63
  VERIFY(search_n(con.end(), con.end(), 1, 1) == con.end());
64
  VERIFY(search_n(con.begin(), con.end(), 1, 1).ptr == array1 + 1);
65
  VERIFY(search_n(con.begin(), con.end(), 2, 1).ptr == array1 + 4);
66
  VERIFY(search_n(con.begin(), con.end(), 3, 1).ptr == array1 + 7);
67
  VERIFY(search_n(con.begin(), con.end(), 3, 0) == con.end());
68
 
69
  // Now do a brute-force comparison of the different types
70
  for(int i = 0; i < TEST_DEPTH; i++)
71
    {
72
      for(int j = 0; j < i; j++)
73
        array2[i] = 0;
74
      do {
75
        for(int j = 0; j < i; j++)
76
          {
77
            test_container<int, forward_iterator_wrapper>
78
              forwardcon(array2, array2 + i);
79
            test_container<int, random_access_iterator_wrapper>
80
              randomcon(array2, array2 + i);
81
            test_container<int, bidirectional_iterator_wrapper>
82
              bidircon(array2, array2 + i);
83
 
84
            int* t1 = search_n(forwardcon.begin(),
85
                               forwardcon.end(), j, 1).ptr;
86
            int* t2 = search_n(forwardcon.begin(),
87
                               forwardcon.end(), j, 1, pred).ptr;
88
            int* t3 = search_n(bidircon.begin(),
89
                               bidircon.end(), j, 1).ptr;
90
            int* t4 = search_n(bidircon.begin(),
91
                               bidircon.end(), j, 1, pred).ptr;
92
            int* t5 = search_n(randomcon.begin(),
93
                               randomcon.end(), j, 1).ptr;
94
            int* t6 = search_n(randomcon.begin(),
95
                               randomcon.end(), j, 1, pred).ptr;
96
            VERIFY((t1 == t2) && (t2 == t3) && (t3 == t4) &&
97
                   (t4 == t5) && (t5 == t6));
98
          }
99
      }
100
      while(lexstep(array2, i));
101
    }
102
  return 0;
103
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.