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

Subversion Repositories openrisc

[/] [openrisc/] [tags/] [gnu-src/] [gcc-4.5.1/] [gcc-4.5.1-or32-1.0rc3/] [libstdc++-v3/] [testsuite/] [25_algorithms/] [prev_permutation/] [moveable.cc] - Blame information for rev 516

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 424 jeremybenn
// { dg-options "-std=gnu++0x" }
2
 
3
// Copyright (C) 2009, 2010 Free Software Foundation, Inc.
4
//
5
// This file is part of the GNU ISO C++ Library.  This library is free
6
// software; you can redistribute it and/or modify it under the
7
// terms of the GNU General Public License as published by the
8
// Free Software Foundation; either version 3, or (at your option)
9
// any later version.
10
 
11
// This library is distributed in the hope that it will be useful,
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
// GNU General Public License for more details.
15
 
16
// You should have received a copy of the GNU General Public License along
17
// with this library; see the file COPYING3.  If not see
18
// <http://www.gnu.org/licenses/>.
19
 
20
// 25.3.9 [lib.alg.permutation.generators]
21
 
22
// XXX FIXME:  parallel-mode should deal correctly with moveable-only types
23
// per C++0x, at minimum smoothly fall back to serial.
24
#undef _GLIBCXX_PARALLEL
25
 
26
#include <algorithm>
27
#include <testsuite_hooks.h>
28
#include <testsuite_iterators.h>
29
#include <testsuite_rvalref.h>
30
 
31
using __gnu_test::test_container;
32
using __gnu_test::bidirectional_iterator_wrapper;
33
using __gnu_test::rvalstruct;
34
using std::prev_permutation;
35
 
36
typedef test_container<rvalstruct, bidirectional_iterator_wrapper> Container;
37
 
38
void
39
test1()
40
{
41
  bool test __attribute__((unused)) = true;
42
 
43
  // Note: The standard is unclear on what should happen in this case.
44
  // This seems the only really sensible behaviour, and what is done.
45
  rvalstruct array[] = {0};
46
  Container con(array, array);
47
  VERIFY( !prev_permutation(con.begin(), con.end()) );
48
}
49
 
50
void
51
test2()
52
{
53
  bool test __attribute__((unused)) = true;
54
 
55
  rvalstruct array[] = {0};
56
  Container con(array, array + 1);
57
  VERIFY( !prev_permutation(con.begin(), con.end()) );
58
}
59
 
60
void
61
test3()
62
{
63
  bool test __attribute__((unused)) = true;
64
 
65
  rvalstruct array[] = {3, 0};
66
  Container con(array, array + 2);
67
  VERIFY( prev_permutation(con.begin(), con.end()) );
68
  VERIFY( array[0] == 0 && array[1] == 3 );
69
  VERIFY( !prev_permutation(con.begin(), con.end()) );
70
  VERIFY( array[0] == 3 && array[1] == 0 );
71
}
72
 
73
void
74
test4()
75
{
76
  bool test __attribute__((unused)) = true;
77
 
78
  int array[6] = {5, 4, 3, 2, 1, 0};
79
  for(int i = 0 ; i < 719; ++i)
80
    {
81
      rvalstruct temp_array[6];
82
      std::copy(array, array + 6, temp_array);
83
      Container con(temp_array, temp_array + 6);
84
      VERIFY( prev_permutation(array, array + 6) );
85
      VERIFY( !std::lexicographical_compare(temp_array, temp_array + 6,
86
                                            array, array + 6) );
87
    }
88
  VERIFY( !prev_permutation(array,array + 6)) ;
89
  for(int i = 0; i < 6; ++i)
90
    VERIFY( array[i] == (5 - i) );
91
}
92
 
93
bool
94
are_ordered(const rvalstruct& lhs, const rvalstruct& rhs)
95
{ return lhs < rhs; }
96
 
97
void
98
test5()
99
{
100
  bool test __attribute__((unused)) = true;
101
 
102
  int array[6] = {5, 4, 3, 2, 1, 0};
103
  for(int i = 0 ; i < 719; ++i)
104
    {
105
      rvalstruct temp_array[6];
106
      std::copy(array, array + 6, temp_array);
107
      Container con(temp_array, temp_array + 6);
108
      VERIFY( prev_permutation(array, array + 6, are_ordered) );
109
      VERIFY( !std::lexicographical_compare(temp_array, temp_array + 6,
110
                                            array, array + 6, are_ordered) );
111
    }
112
  VERIFY( !prev_permutation(array,array + 6, are_ordered) );
113
  for(int i = 0; i < 6; ++i)
114
    VERIFY( array[i] == (5 - i) );
115
}
116
 
117
int main()
118
{
119
  test1();
120
  test2();
121
  test3();
122
  test4();
123
  test5();
124
  return 0;
125
}

powered by: WebSVN 2.1.0

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