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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libstdc++-v3/] [testsuite/] [25_algorithms/] [search_n/] [iterator.cc] - Blame information for rev 742

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 742 jeremybenn
// Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010
2
// Free Software Foundation, Inc.
3
//
4
// This file is part of the GNU ISO C++ Library.  This library is free
5
// software; you can redistribute it and/or modify it under the
6
// terms of the GNU General Public License as published by the
7
// Free Software Foundation; either version 3, or (at your option)
8
// any later version.
9
 
10
// This library is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
// GNU General Public License for more details.
14
 
15
// You should have received a copy of the GNU General Public License along
16
// with this library; see the file COPYING3.  If not see
17
// <http://www.gnu.org/licenses/>.
18
 
19
// { dg-options "-DTEST_DEPTH=10" { target simulator } }
20
 
21
// 25 algorithms, search_n
22
 
23
#include <algorithm>
24
#include <functional>
25
#include <testsuite_hooks.h>
26
#include <testsuite_iterators.h>
27
 
28
#ifndef TEST_DEPTH
29
#define TEST_DEPTH 14
30
#endif
31
 
32
int array1[11] = {0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0};
33
int array2[TEST_DEPTH];
34
 
35
bool
36
pred(int i, int j)
37
{
38
  return i == j;
39
}
40
 
41
bool
42
lexstep(int* start, int length)
43
{
44
  int i = 0;
45
  int carry = 1;
46
  while(i < length && carry)
47
    {
48
      if(start[i] == 1)
49
        start[i] = 0;
50
      else
51
        {
52
          start[i] = 1;
53
          carry = 0;
54
        }
55
      i++;
56
    }
57
  return !carry;
58
}
59
 
60
int main()
61
{
62
  using __gnu_test::test_container;
63
  using __gnu_test::random_access_iterator_wrapper;
64
  using __gnu_test::bidirectional_iterator_wrapper;
65
  using __gnu_test::forward_iterator_wrapper;
66
 
67
  using std::search_n;
68
 
69
  test_container<int,forward_iterator_wrapper> con(array1,array1 + 10);
70
  VERIFY(search_n(con.end(), con.end(), 0, 1) == con.end());
71
  VERIFY(search_n(con.end(), con.end(), 1, 1) == con.end());
72
  VERIFY(search_n(con.begin(), con.end(), 1, 1).ptr == array1 + 1);
73
  VERIFY(search_n(con.begin(), con.end(), 2, 1).ptr == array1 + 4);
74
  VERIFY(search_n(con.begin(), con.end(), 3, 1).ptr == array1 + 7);
75
  VERIFY(search_n(con.begin(), con.end(), 3, 0) == con.end());
76
 
77
  // Now do a brute-force comparison of the different types
78
  for(int i = 0; i < TEST_DEPTH; i++)
79
    {
80
      for(int j = 0; j < i; j++)
81
        array2[i] = 0;
82
      do {
83
        for(int j = 0; j < i; j++)
84
          {
85
            test_container<int, forward_iterator_wrapper>
86
              forwardcon(array2, array2 + i);
87
            test_container<int, random_access_iterator_wrapper>
88
              randomcon(array2, array2 + i);
89
            test_container<int, bidirectional_iterator_wrapper>
90
              bidircon(array2, array2 + i);
91
 
92
            int* t1 = search_n(forwardcon.begin(),
93
                               forwardcon.end(), j, 1).ptr;
94
            int* t2 = search_n(forwardcon.begin(),
95
                               forwardcon.end(), j, 1, pred).ptr;
96
            int* t3 = search_n(bidircon.begin(),
97
                               bidircon.end(), j, 1).ptr;
98
            int* t4 = search_n(bidircon.begin(),
99
                               bidircon.end(), j, 1, pred).ptr;
100
            int* t5 = search_n(randomcon.begin(),
101
                               randomcon.end(), j, 1).ptr;
102
            int* t6 = search_n(randomcon.begin(),
103
                               randomcon.end(), j, 1, pred).ptr;
104
            VERIFY((t1 == t2) && (t2 == t3) && (t3 == t4) &&
105
                   (t4 == t5) && (t5 == t6));
106
          }
107
      }
108
      while(lexstep(array2, i));
109
    }
110
  return 0;
111
}

powered by: WebSVN 2.1.0

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