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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libstdc++-v3/] [testsuite/] [25_algorithms/] [equal_range/] [2.cc] - Blame information for rev 749

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 742 jeremybenn
// Copyright (C) 2001, 2009 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 3, 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 COPYING3.  If not see
16
// <http://www.gnu.org/licenses/>.
17
 
18
// 25.3.3 [lib.alg.binary.search] Binary search algorithms.
19
 
20
#include <algorithm>
21
#include <testsuite_hooks.h>
22
 
23
bool test __attribute__((unused)) = true;
24
 
25
const int A[] = {1, 2, 3, 3, 3, 5, 8};
26
const int C[] = {8, 5, 3, 3, 3, 2, 1};
27
const int N = sizeof(A) / sizeof(int);
28
 
29
// A comparison, equalivalent to std::greater<int> without the
30
// dependency on <functional>.
31
struct gt
32
{
33
    bool
34
    operator()(const int& x, const int& y) const
35
    { return x > y; }
36
};
37
 
38
// Each test performs general-case, bookend, not-found condition,
39
// and predicate functional checks.
40
 
41
// 25.3.3.3 equal_range, with and without comparison predicate
42
void
43
test03()
44
{
45
    using std::equal_range;
46
    typedef std::pair<const int*, const int*> Ipair;
47
 
48
    const int first = A[0];
49
    const int last = A[N - 1];
50
 
51
    Ipair p = equal_range(A, A + N, 3);
52
    VERIFY(p.first == A + 2);
53
    VERIFY(p.second == A + 5);
54
 
55
    Ipair q = equal_range(A, A + N, first);
56
    VERIFY(q.first == A + 0);
57
    VERIFY(q.second == A + 1);
58
 
59
    Ipair r = equal_range(A, A + N, last);
60
    VERIFY(r.first == A + N - 1);
61
    VERIFY(r.second == A + N);
62
 
63
    Ipair s = equal_range(A, A + N, 4);
64
    VERIFY(s.first == A + 5);
65
    VERIFY(s.second == A + 5);
66
 
67
    Ipair t = equal_range(C, C + N, 3, gt());
68
    VERIFY(t.first == C + 2);
69
    VERIFY(t.second == C + 5);
70
 
71
    Ipair u = equal_range(C, C + N, first, gt());
72
    VERIFY(u.first == C + N - 1);
73
    VERIFY(u.second == C + N);
74
 
75
    Ipair v = equal_range(C, C + N, last, gt());
76
    VERIFY(v.first == C + 0);
77
    VERIFY(v.second == C + 1);
78
 
79
    Ipair w = equal_range(C, C + N, 4, gt());
80
    VERIFY(w.first == C + 2);
81
    VERIFY(w.second == C + 2);
82
}
83
 
84
int
85
main()
86
{
87
  test03();
88
  return 0;
89
}

powered by: WebSVN 2.1.0

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