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/] [unique/] [2.cc] - Blame information for rev 19

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 19 jlechner
// 2003-10-14  Paolo Carlini  <pcarlini@unitus.it>
2
 
3
// Copyright (C) 2003, 2004, 2005 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 2, 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 COPYING.  If not, write to the Free
18
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19
// USA.
20
 
21
// 25.2.8 [lib.alg.unique] Unique
22
 
23
#include <list>
24
#include <algorithm>
25
#include <functional>
26
#include <testsuite_hooks.h>
27
 
28
const int T1[] = {1, 4, 4, 6, 1, 2, 2, 3, 1, 6, 6, 6, 5, 7, 5, 4, 4};
29
const int T2[] = {1, 1, 1, 2, 2, 1, 1, 7, 6, 6, 7, 8, 8, 8, 8, 9, 9};
30
const int N = sizeof(T1) / sizeof(int);
31
 
32
const int A1[] = {1, 4, 6, 1, 2, 3, 1, 6, 5, 7, 5, 4};
33
const int A2[] = {1, 4, 4, 6, 6, 6, 6, 7};
34
const int A3[] = {1, 1, 1};
35
 
36
const int B1[] = {1, 2, 1, 7, 6, 7, 8, 9};
37
const int B2[] = {1, 1, 1, 2, 2, 7, 7, 8, 8, 8, 8, 9, 9};
38
const int B3[] = {9, 9, 8, 8, 8, 8, 7, 6, 6, 1, 1, 1, 1, 1};
39
 
40
void test01()
41
{
42
  bool test __attribute__((unused)) = true;
43
  using namespace std;
44
 
45
  list<int>::iterator pos;
46
 
47
  list<int> coll(T1, T1 + N);
48
  pos = unique(coll.begin(), coll.end());
49
  VERIFY( equal(coll.begin(), pos, A1) );
50
 
51
  list<int> coll2(T2, T2 + N);
52
  pos = unique(coll2.begin(), coll2.end());
53
  VERIFY( equal(coll2.begin(), pos, B1) );
54
}
55
 
56
void test02()
57
{
58
  bool test __attribute__((unused)) = true;
59
  using namespace std;
60
 
61
  list<int>::iterator pos;
62
 
63
  list<int> coll(T1, T1 + N);
64
  pos = unique(coll.begin(), coll.end(), greater<int>());
65
  VERIFY( equal(coll.begin(), pos, A2) );
66
 
67
  list<int> coll2(T2, T2 + N);
68
  pos = unique(coll2.begin(), coll2.end(), greater<int>());
69
  VERIFY( equal(coll2.begin(), pos, B2) );
70
}
71
 
72
void test03()
73
{
74
  bool test __attribute__((unused)) = true;
75
  using namespace std;
76
 
77
  list<int>::iterator pos;
78
 
79
  list<int> coll(T1, T1 + N);
80
  pos = unique(coll.begin(), coll.end(), less<int>());
81
  VERIFY( equal(coll.begin(), pos, A3) );
82
 
83
  list<int> coll2(T2, T2 + N);
84
  reverse(coll2.begin(), coll2.end());
85
  pos = unique(coll2.begin(), coll2.end(), less<int>());
86
  VERIFY( equal(coll2.begin(), pos, B3) );
87
}
88
 
89
int main()
90
{
91
  test01();
92
  test02();
93
  test03();
94
  return 0;
95
}

powered by: WebSVN 2.1.0

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