Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygennthelm_test.cppGo to the documentation of this file.00001 #include <vector> 00002 #include <algorithm> 00003 #include <functional> 00004 00005 #include "cppunit/cppunit_proxy.h" 00006 00007 #if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) 00008 using namespace std; 00009 #endif 00010 00011 // 00012 // TestCase class 00013 // 00014 class NthElemTest : public CPPUNIT_NS::TestCase 00015 { 00016 CPPUNIT_TEST_SUITE(NthElemTest); 00017 CPPUNIT_TEST(nthelem0); 00018 CPPUNIT_TEST(nthelem1); 00019 CPPUNIT_TEST(nthelem2); 00020 CPPUNIT_TEST_SUITE_END(); 00021 00022 protected: 00023 void nthelem0(); 00024 void nthelem1(); 00025 void nthelem2(); 00026 }; 00027 00028 CPPUNIT_TEST_SUITE_REGISTRATION(NthElemTest); 00029 00030 // 00031 // tests implementation 00032 // 00033 void NthElemTest::nthelem0() 00034 { 00035 int numbers[7] = { 5, 2, 4, 1, 0, 3 ,77}; 00036 nth_element(numbers, numbers + 3, numbers + 6); 00037 00038 CPPUNIT_ASSERT(numbers[0]==1); 00039 CPPUNIT_ASSERT(numbers[1]==0); 00040 CPPUNIT_ASSERT(numbers[2]==2); 00041 CPPUNIT_ASSERT(numbers[3]==3); 00042 CPPUNIT_ASSERT(numbers[4]==4); 00043 CPPUNIT_ASSERT(numbers[5]==5); 00044 } 00045 void NthElemTest::nthelem1() 00046 { 00047 //6 8 5 1 7 4 1 5 2 6 00048 //1 1 4 2 5 5 6 7 8 6 00049 int numbers[10] = { 6, 8, 5, 1, 7, 4, 1, 5, 2, 6 }; 00050 00051 vector <int> v1(numbers, numbers+10); 00052 nth_element(v1.begin(), v1.begin() + v1.size() / 2, v1.end()); 00053 00054 CPPUNIT_ASSERT(v1[0]==1); 00055 CPPUNIT_ASSERT(v1[1]==1); 00056 CPPUNIT_ASSERT(v1[2]==4); 00057 CPPUNIT_ASSERT(v1[3]==2); 00058 CPPUNIT_ASSERT(v1[4]==5); 00059 CPPUNIT_ASSERT(v1[5]==5); 00060 CPPUNIT_ASSERT(v1[6]==6); 00061 CPPUNIT_ASSERT(v1[7]==7); 00062 CPPUNIT_ASSERT(v1[8]==8); 00063 CPPUNIT_ASSERT(v1[9]==6); 00064 } 00065 void NthElemTest::nthelem2() 00066 { 00067 //4 5 4 2 1 7 4 3 1 6 00068 //6 7 4 4 5 4 3 2 1 1 00069 00070 int numbers[10] = { 4, 5, 4, 2, 1, 7, 4, 3, 1, 6 }; 00071 vector <int> v1(numbers, numbers+10); 00072 nth_element(v1.begin(), v1.begin() + v1.size() / 2, v1.end(), greater<int>()); 00073 00074 CPPUNIT_ASSERT(v1[0]==6); 00075 CPPUNIT_ASSERT(v1[1]==7); 00076 CPPUNIT_ASSERT(v1[2]==4); 00077 CPPUNIT_ASSERT(v1[3]==4); 00078 CPPUNIT_ASSERT(v1[4]==5); 00079 CPPUNIT_ASSERT(v1[5]==4); 00080 CPPUNIT_ASSERT(v1[6]==3); 00081 CPPUNIT_ASSERT(v1[7]==2); 00082 CPPUNIT_ASSERT(v1[8]==1); 00083 CPPUNIT_ASSERT(v1[9]==1); 00084 } Generated on Tue May 15 04:59:47 2012 for ReactOS by
1.6.3
|