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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libstdc++-v3/] [testsuite/] [25_algorithms/] [heap/] [moveable.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
// { dg-options "-std=gnu++0x" }
2
 
3
// Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011
4
// Free Software Foundation, Inc.
5
//
6
// This file is part of the GNU ISO C++ Library.  This library is free
7
// software; you can redistribute it and/or modify it under the
8
// terms of the GNU General Public License as published by the
9
// Free Software Foundation; either version 3, or (at your option)
10
// any later version.
11
 
12
// This library is distributed in the hope that it will be useful,
13
// but WITHOUT ANY WARRANTY; without Pred the implied warranty of
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
// GNU General Public License for more details.
16
 
17
// You should have received a copy of the GNU General Public License along
18
// with this library; see the file COPYING3.  If not see
19
// <http://www.gnu.org/licenses/>.
20
 
21
// { dg-options "-std=gnu++0x -DITERATIONS=5" { target simulator } }
22
 
23
// 25.3.6 Heap operations [lib.alg.heap.operations]
24
 
25
#undef _GLIBCXX_CONCEPT_CHECKS
26
 
27
#include <algorithm>
28
#include <testsuite_hooks.h>
29
#include <testsuite_iterators.h>
30
#include <testsuite_rvalref.h>
31
 
32
#ifndef ITERATIONS
33
#define ITERATIONS 9
34
#endif
35
 
36
using __gnu_test::test_container;
37
using __gnu_test::random_access_iterator_wrapper;
38
using __gnu_test::rvalstruct;
39
 
40
typedef test_container<rvalstruct, random_access_iterator_wrapper> container;
41
typedef test_container<int, random_access_iterator_wrapper> container_ref;
42
 
43
void
44
check_make(int* array, int length)
45
{
46
  bool test __attribute__((unused)) = true;
47
 
48
  rvalstruct makeheap[9];
49
  int        makeheap_ref[9];
50
  std::copy(array, array + length, makeheap);
51
  std::copy(array, array + length, makeheap_ref);
52
  container makecon(makeheap, makeheap + length);
53
  container_ref makecon_ref(makeheap_ref, makeheap_ref + length);
54
  std::make_heap(makecon.begin(), makecon.end());
55
  std::make_heap(makecon_ref.begin(), makecon_ref.end());
56
  for (int z = 0; z < length; ++z)
57
    VERIFY( makeheap[z] == makeheap_ref[z] );
58
  VERIFY( std::__is_heap(makecon.begin(), makecon.end()) );
59
  for (int z = 0; z < length; ++z)
60
    VERIFY( makeheap[z].valid );
61
}
62
 
63
void
64
check_pop(int* array, int length)
65
{
66
  bool test __attribute__((unused)) = true;
67
 
68
  rvalstruct popheap[9];
69
  int        popheap_ref[9];
70
  std::copy(array, array + length, popheap);
71
  std::copy(array, array + length, popheap_ref);
72
  container popcon(popheap, popheap + length);
73
  container_ref popcon_ref(popheap_ref, popheap_ref + length);
74
  std::pop_heap(popcon.begin(), popcon.end());
75
  std::pop_heap(popcon_ref.begin(), popcon_ref.end());
76
  for (int z = 0; z < length; ++z)
77
    VERIFY( popheap[z] == popheap_ref[z] );
78
  VERIFY( (std::__is_heap(popheap, popheap + length - 1)) );
79
  for (int z = 0; z < length; ++z)
80
    VERIFY( popheap[z].val <= popheap[length-1].val && popheap[z].valid );
81
}
82
 
83
void
84
check_sort(int* array, int length)
85
{
86
  bool test __attribute__((unused)) = true;
87
 
88
  rvalstruct sortheap[9];
89
  int        sortheap_ref[9];
90
  std::copy(array, array + length, sortheap);
91
  std::copy(array, array + length, sortheap_ref);
92
  container sortcon(sortheap, sortheap + length);
93
  container_ref sortcon_ref(sortheap_ref, sortheap_ref + length);
94
  std::sort_heap(sortcon.begin(), sortcon.end());
95
  std::sort_heap(sortcon_ref.begin(), sortcon_ref.end());
96
  for (int z = 0; z < length; ++z)
97
    VERIFY( sortheap[z] == sortheap_ref[z] );
98
  for (int z = 0; z < length - 1; ++z)
99
    VERIFY( sortheap[z].val <= sortheap[z + 1].val && sortheap[z].valid );
100
  VERIFY( sortheap[length - 1].valid );
101
}
102
 
103
void
104
check_push(int* array, int pushval, int length)
105
{
106
  bool test __attribute__((unused)) = true;
107
 
108
  rvalstruct pushheap[10];
109
  int        pushheap_ref[10];
110
  std::copy(array, array + length, pushheap);
111
  std::copy(array, array + length, pushheap_ref);
112
  pushheap[length] = pushval;
113
  pushheap_ref[length] = pushval;
114
  container pushcon(pushheap, pushheap + length + 1);
115
  container_ref pushcon_ref(pushheap_ref, pushheap_ref + length + 1);
116
  std::push_heap(pushcon.begin(), pushcon.end());
117
  std::push_heap(pushcon_ref.begin(), pushcon_ref.end());
118
  for (int z = 0; z < length + 1; ++z)
119
    VERIFY( pushheap[z] == pushheap_ref[z] );
120
  VERIFY( std::__is_heap(pushheap, pushheap + length + 1) );
121
  for (int z = 0; z < length + 1; ++z)
122
    VERIFY( pushheap[z].valid );
123
}
124
 
125
void
126
test01()
127
{
128
  int array[9];
129
  for (int i = 1; i < ITERATIONS; ++i)
130
    {
131
      for(int z = 0; z < i; ++z)
132
        array[z] = z;
133
      while (std::next_permutation(array, array + i))
134
        {
135
          check_make(array, i);
136
          if (std::__is_heap(array, array + i))
137
            {
138
              check_pop(array, i);
139
              check_sort(array, i);
140
              for (int pushval = -1; pushval <= i; ++pushval)
141
                check_push(array, pushval, i);
142
            }
143
        }
144
    }
145
}
146
 
147
int
148
main()
149
{
150
  test01();
151
  return 0;
152
}

powered by: WebSVN 2.1.0

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