Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenunique_test.cpp
Go to the documentation of this file.
00001 #include <algorithm> 00002 00003 #include "cppunit/cppunit_proxy.h" 00004 00005 #if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) 00006 using namespace std; 00007 #endif 00008 00009 // 00010 // TestCase class 00011 // 00012 class UniqueTest : public CPPUNIT_NS::TestCase 00013 { 00014 CPPUNIT_TEST_SUITE(UniqueTest); 00015 CPPUNIT_TEST(uniqcpy1); 00016 CPPUNIT_TEST(uniqcpy2); 00017 CPPUNIT_TEST(unique1); 00018 CPPUNIT_TEST(unique2); 00019 CPPUNIT_TEST_SUITE_END(); 00020 00021 protected: 00022 void uniqcpy1(); 00023 void uniqcpy2(); 00024 void unique1(); 00025 void unique2(); 00026 }; 00027 00028 CPPUNIT_TEST_SUITE_REGISTRATION(UniqueTest); 00029 00030 static bool str_equal(const char* a_, const char* b_) 00031 { return *a_ == *b_; } 00032 // 00033 // tests implementation 00034 // 00035 void UniqueTest::unique1() 00036 { 00037 int numbers[8] = { 0, 1, 1, 2, 2, 2, 3, 4 }; 00038 unique((int*)numbers, (int*)numbers + 8); 00039 // 0 1 2 3 4 2 3 4 00040 CPPUNIT_ASSERT(numbers[0]==0); 00041 CPPUNIT_ASSERT(numbers[1]==1); 00042 CPPUNIT_ASSERT(numbers[2]==2); 00043 CPPUNIT_ASSERT(numbers[3]==3); 00044 CPPUNIT_ASSERT(numbers[4]==4); 00045 CPPUNIT_ASSERT(numbers[5]==2); 00046 CPPUNIT_ASSERT(numbers[6]==3); 00047 CPPUNIT_ASSERT(numbers[7]==4); 00048 } 00049 00050 void UniqueTest::unique2() 00051 { 00052 const char* labels[] = {"Q", "Q", "W", "W", "E", "E", "R", "T", "T", "Y", "Y"}; 00053 00054 const unsigned count = sizeof(labels) / sizeof(labels[0]); 00055 00056 unique((const char**)labels, (const char**)labels + count, str_equal); 00057 00058 // QWERTY 00059 CPPUNIT_ASSERT(*labels[0] == 'Q'); 00060 CPPUNIT_ASSERT(*labels[1] == 'W'); 00061 CPPUNIT_ASSERT(*labels[2] == 'E'); 00062 CPPUNIT_ASSERT(*labels[3] == 'R'); 00063 CPPUNIT_ASSERT(*labels[4] == 'T'); 00064 CPPUNIT_ASSERT(*labels[5] == 'Y'); 00065 00066 } 00067 00068 void UniqueTest::uniqcpy1() 00069 { 00070 int numbers[8] = { 0, 1, 1, 2, 2, 2, 3, 4 }; 00071 int result[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; 00072 00073 unique_copy((int*)numbers, (int*)numbers + 8, (int*)result); 00074 00075 // 0 1 2 3 4 0 0 0 00076 CPPUNIT_ASSERT(result[0]==0); 00077 CPPUNIT_ASSERT(result[1]==1); 00078 CPPUNIT_ASSERT(result[2]==2); 00079 CPPUNIT_ASSERT(result[3]==3); 00080 CPPUNIT_ASSERT(result[4]==4); 00081 CPPUNIT_ASSERT(result[5]==0); 00082 CPPUNIT_ASSERT(result[6]==0); 00083 CPPUNIT_ASSERT(result[7]==0); 00084 } 00085 00086 void UniqueTest::uniqcpy2() 00087 { 00088 const char* labels[] = {"Q", "Q", "W", "W", "E", "E", "R", "T", "T", "Y", "Y"}; 00089 const char **plabels = (const char**)labels; 00090 00091 const size_t count = sizeof(labels) / sizeof(labels[0]); 00092 const char* uCopy[count]; 00093 const char **puCopy = &uCopy[0]; 00094 fill(puCopy, puCopy + count, ""); 00095 00096 unique_copy(plabels, plabels + count, puCopy, str_equal); 00097 00098 //QWERTY 00099 CPPUNIT_ASSERT(*uCopy[0] == 'Q'); 00100 CPPUNIT_ASSERT(*uCopy[1] == 'W'); 00101 CPPUNIT_ASSERT(*uCopy[2] == 'E'); 00102 CPPUNIT_ASSERT(*uCopy[3] == 'R'); 00103 CPPUNIT_ASSERT(*uCopy[4] == 'T'); 00104 CPPUNIT_ASSERT(*uCopy[5] == 'Y'); 00105 } Generated on Sun May 27 2012 04:35:53 for ReactOS by
1.7.6.1
|