31
|
1 |
|
|
2 |
// STLport regression testsuite component.
|
|
3 |
// To compile as a separate example, please #define MAIN.
|
|
4 |
|
|
5 |
#include <numeric>
|
|
6 |
#include <iostream>
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
#ifdef MAIN
|
|
11 |
#define adjdiff0_test main
|
|
12 |
#endif
|
|
13 |
|
|
14 |
#if !defined (STLPORT) || defined(__STL_USE_NAMESPACES)
|
|
15 |
using namespace std;
|
|
16 |
#endif
|
|
17 |
|
|
18 |
int adjdiff0_test(int, char**)
|
|
19 |
{
|
|
20 |
|
|
21 |
|
|
22 |
cout<<"Results of adjdiff0_test:"<<endl;
|
|
23 |
int numbers[5] = { 1, 2, 4, 8, 16 };
|
|
24 |
|
|
25 |
// To compare the results
|
|
26 |
int failures = 0;
|
|
27 |
int arr[5];
|
|
28 |
int k;
|
|
29 |
for(k =0; k < 5; k++)
|
|
30 |
arr[k] = numbers[k];
|
|
31 |
|
|
32 |
int difference[5];
|
|
33 |
adjacent_difference(numbers, numbers + 5, (int*)difference);
|
|
34 |
int i;
|
|
35 |
for(i = 0; i < 5; i++)
|
|
36 |
{
|
|
37 |
cout << numbers[i] << ' ';
|
|
38 |
//check the number in array with the initial arr
|
|
39 |
if(numbers[i] != arr[i])
|
|
40 |
failures++;
|
|
41 |
}
|
|
42 |
cout << endl;
|
|
43 |
|
|
44 |
for(i = 0; i < 5; i++)
|
|
45 |
cout << difference[i] << ' ';
|
|
46 |
cout << endl;
|
|
47 |
|
|
48 |
//check the difference array
|
|
49 |
if((difference[0] != 1) || (difference[1] != 1) ||
|
|
50 |
(difference[2] != 2) || (difference[3] != 4) ||
|
|
51 |
(difference[4] != 8))
|
|
52 |
failures++;
|
|
53 |
|
|
54 |
if (!failures)
|
|
55 |
return 0;
|
|
56 |
else
|
|
57 |
return 1;
|
|
58 |
}
|