31
|
1 |
|
|
2 |
// STLport regression testsuite component.
|
|
3 |
// To compile as a separate example, please #define MAIN.
|
|
4 |
|
|
5 |
#include <algorithm>
|
|
6 |
#include <iostream>
|
|
7 |
#include <iterator>
|
|
8 |
#include <functional>
|
|
9 |
|
|
10 |
#ifdef MAIN
|
|
11 |
#define sort2_test main
|
|
12 |
#endif
|
|
13 |
|
|
14 |
#if !defined (STLPORT) || defined(__STL_USE_NAMESPACES)
|
|
15 |
using namespace std;
|
|
16 |
#endif
|
|
17 |
int sort2_test(int, char**)
|
|
18 |
{
|
|
19 |
int failures=0;
|
|
20 |
cout<<"Results of sort2_test:"<<endl;
|
|
21 |
int array[] = { 1, 50, -10, 11, 42, 19 };
|
|
22 |
|
|
23 |
int count = sizeof(array) / sizeof(array[0]);
|
|
24 |
ostream_iterator <int> iter(cout, " ");
|
|
25 |
cout << "before: ";
|
|
26 |
copy(array, array + count, iter);
|
|
27 |
cout << "\nafter: ";
|
|
28 |
if(1!=array[0])
|
|
29 |
failures++;
|
|
30 |
else if(50 !=array[1])
|
|
31 |
failures++;
|
|
32 |
else if(-10!=array[2])
|
|
33 |
failures++;
|
|
34 |
else if(11 !=array[3])
|
|
35 |
failures++;
|
|
36 |
else if(42!=array[4])
|
|
37 |
failures++;
|
|
38 |
else if(19 !=array[5])
|
|
39 |
failures++;
|
|
40 |
|
|
41 |
sort(array, array + count, greater<int>());
|
|
42 |
if(50!=array[0])
|
|
43 |
failures++;
|
|
44 |
else if(42 !=array[1])
|
|
45 |
failures++;
|
|
46 |
else if(19!=array[2])
|
|
47 |
failures++;
|
|
48 |
else if(11 !=array[3])
|
|
49 |
failures++;
|
|
50 |
else if(1!=array[4])
|
|
51 |
failures++;
|
|
52 |
else if(-10!=array[5])
|
|
53 |
failures++;
|
|
54 |
|
|
55 |
copy(array, array + count, iter);
|
|
56 |
cout << endl;
|
|
57 |
|
|
58 |
if(failures)
|
|
59 |
return 1;
|
|
60 |
else
|
|
61 |
return 0;
|
|
62 |
|
|
63 |
}
|
|
64 |
|