31
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
// STLport regression testsuite component.
|
|
19 |
// To compile as a separate example, please #define MAIN.
|
|
20 |
|
|
21 |
#include <algorithm>
|
|
22 |
#include <iostream>
|
|
23 |
#include <iterator>
|
|
24 |
#include <functional>
|
|
25 |
|
|
26 |
#ifdef MAIN
|
|
27 |
#define sort2_test main
|
|
28 |
#endif
|
|
29 |
|
|
30 |
#if !defined (STLPORT) || defined(__STL_USE_NAMESPACES)
|
|
31 |
using namespace std;
|
|
32 |
#endif
|
|
33 |
int sort2_test(int, char**)
|
|
34 |
{
|
|
35 |
int failures=0;
|
|
36 |
cout<<"Results of sort2_test:"<<endl;
|
|
37 |
int array[] = { 1, 50, -10, 11, 42, 19 };
|
|
38 |
|
|
39 |
int count = sizeof(array) / sizeof(array[0]);
|
|
40 |
ostream_iterator <int> iter(cout, " ");
|
|
41 |
cout << "before: ";
|
|
42 |
copy(array, array + count, iter);
|
|
43 |
cout << "\nafter: ";
|
|
44 |
if(1!=array[0])
|
|
45 |
failures++;
|
|
46 |
else if(50 !=array[1])
|
|
47 |
failures++;
|
|
48 |
else if(-10!=array[2])
|
|
49 |
failures++;
|
|
50 |
else if(11 !=array[3])
|
|
51 |
failures++;
|
|
52 |
else if(42!=array[4])
|
|
53 |
failures++;
|
|
54 |
else if(19 !=array[5])
|
|
55 |
failures++;
|
|
56 |
|
|
57 |
sort(array, array + count, greater<int>());
|
|
58 |
if(50!=array[0])
|
|
59 |
failures++;
|
|
60 |
else if(42 !=array[1])
|
|
61 |
failures++;
|
|
62 |
else if(19!=array[2])
|
|
63 |
failures++;
|
|
64 |
else if(11 !=array[3])
|
|
65 |
failures++;
|
|
66 |
else if(1!=array[4])
|
|
67 |
failures++;
|
|
68 |
else if(-10!=array[5])
|
|
69 |
failures++;
|
|
70 |
|
|
71 |
copy(array, array + count, iter);
|
|
72 |
cout << endl;
|
|
73 |
|
|
74 |
if(failures)
|
|
75 |
return 1;
|
|
76 |
else
|
|
77 |
return 0;
|
|
78 |
|
|
79 |
}
|
|
80 |
|