stdcpp/tsrc/Stdcpp_test/stlport/auto/stlport_nthelem/src/nthelem1.cpp
changeset 31 ce057bb09d0b
child 34 5fae379060a7
equal deleted inserted replaced
30:e20de85af2ee 31:ce057bb09d0b
       
     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 <vector>
       
    22 #include <algorithm>
       
    23 #include <cstdlib>
       
    24 #include <iterator>
       
    25 #include <iostream>
       
    26 #include <fstream>
       
    27 
       
    28 #ifdef MAIN 
       
    29 #define nthelem1_test main
       
    30 #endif
       
    31 
       
    32 #if !defined (STLPORT) || defined(__STL_USE_NAMESPACES)
       
    33 using namespace std;
       
    34 #endif
       
    35 int nthelem1_test(int, char**)
       
    36 {
       
    37 ofstream Outfile("c:\\nthelem1.txt");
       
    38   cout<<"Results of nthelem1_test:"<<endl;
       
    39   vector <int> v1(10) ;
       
    40   int failures = 0;
       
    41 	v1[0] = 23;
       
    42 	v1[1] = 6;
       
    43 	v1[2] = 7;
       
    44 	v1[3] = 5;
       
    45 	v1[4] = 3;
       
    46 	v1[5] = 5;
       
    47 	v1[6] = 6;
       
    48 	v1[7] = 2;
       
    49 	v1[8] = 9;
       
    50 	v1[9] = 1;
       
    51    
       
    52   /*for(int i = 0; i < v1.size(); i++)
       
    53     v1[i] = rand() % 10;*/
       
    54     
       
    55   ostream_iterator<int> iter(cout, " ");
       
    56    ostream_iterator<int> iterfile(Outfile, " ");
       
    57   copy(v1.begin(), v1.end(), iter);
       
    58    copy(v1.begin(), v1.end(), iterfile);
       
    59   cout << endl;
       
    60   Outfile << endl;
       
    61   
       
    62           
       
    63   nth_element(v1.begin(),
       
    64                v1.begin() + v1.size() / 2,
       
    65                v1.end());
       
    66   copy(v1.begin(), v1.end(), iter);
       
    67   copy(v1.begin(), v1.end(), iterfile);
       
    68   cout << endl;
       
    69    Outfile << endl;
       
    70     Outfile <<v1[0]<<endl;
       
    71   Outfile <<v1[1]<<endl;
       
    72 Outfile <<v1[2]<<endl;
       
    73 Outfile <<v1[3]<<endl;
       
    74 Outfile <<v1[4]<<endl;
       
    75 Outfile <<v1[5]<<endl;
       
    76 Outfile <<v1[6]<<endl;
       
    77 Outfile <<v1[7]<<endl;
       
    78 Outfile <<v1[8]<<endl;
       
    79 Outfile <<v1[9]<<endl;
       
    80 	if(v1[0] != 1)
       
    81 		failures++;
       
    82 	if(v1[1] != 2)
       
    83 		failures++;
       
    84 	if(v1[2] != 5)
       
    85 		failures++;
       
    86 	if(v1[3] != 3)
       
    87 		failures++;
       
    88 	if(v1[4] != 5)
       
    89 		failures++;
       
    90 	if(v1[5] != 6)
       
    91 		failures++;
       
    92 	if(v1[6] != 6)
       
    93 		failures++;
       
    94 	if(v1[7] != 7)
       
    95 		failures++;
       
    96 	if(v1[8] != 9)
       
    97 		failures++;
       
    98 	if(v1[9] != 23)
       
    99 		failures++;
       
   100 
       
   101    Outfile.close();
       
   102   return failures;
       
   103 }