ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

count_test.cpp
Go to the documentation of this file.
00001 #include <algorithm>
00002 #include <vector>
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 CountTest : public CPPUNIT_NS::TestCase
00013 {
00014   CPPUNIT_TEST_SUITE(CountTest);
00015   CPPUNIT_TEST(count0);
00016   CPPUNIT_TEST(count1);
00017   CPPUNIT_TEST(countif1);
00018   CPPUNIT_TEST_SUITE_END();
00019 
00020 protected:
00021   void count0();
00022   void count1();
00023   void countif1();
00024   static int odd(int a_);
00025 };
00026 
00027 CPPUNIT_TEST_SUITE_REGISTRATION(CountTest);
00028 
00029 //
00030 // tests implementation
00031 //
00032 void CountTest::count0()
00033 {
00034   int numbers[10] = { 1, 2, 4, 1, 2, 4, 1, 2, 4, 1 };
00035 
00036   int result = count(numbers, numbers + 10, 1);
00037   CPPUNIT_ASSERT(result==4);
00038 #if defined (STLPORT) && !defined (_STLP_NO_ANACHRONISMS)
00039   result = 0;
00040   count(numbers, numbers + 10, 1, result);
00041   CPPUNIT_ASSERT(result==4);
00042 #endif
00043 }
00044 void CountTest::count1()
00045 {
00046   vector <int> numbers(100);
00047   for(int i = 0; i < 100; i++)
00048   numbers[i] = i % 3;
00049   int elements = count(numbers.begin(), numbers.end(), 2);
00050   CPPUNIT_ASSERT(elements==33);
00051 #if defined (STLPORT) && !defined (_STLP_NO_ANACHRONISMS)
00052   elements = 0;
00053   count(numbers.begin(), numbers.end(), 2, elements);
00054   CPPUNIT_ASSERT(elements==33);
00055 #endif
00056 }
00057 void CountTest::countif1()
00058 {
00059   vector <int> numbers(100);
00060   for(int i = 0; i < 100; i++)
00061     numbers[i] = i % 3;
00062   int elements = count_if(numbers.begin(), numbers.end(), odd);
00063   CPPUNIT_ASSERT(elements==33);
00064 #if defined (STLPORT) && !defined (_STLP_NO_ANACHRONISMS)
00065   elements = 0;
00066   count_if(numbers.begin(), numbers.end(), odd, elements);
00067   CPPUNIT_ASSERT(elements==33);
00068 #endif
00069 }
00070 int CountTest::odd(int a_)
00071 {
00072   return a_ % 2;
00073 }

Generated on Sat May 26 2012 04:34:11 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.