Home | History | Annotate | Download | only in unit
      1 #include <numeric>
      2 #include <algorithm>
      3 #include <functional>
      4 
      5 #include "cppunit/cppunit_proxy.h"
      6 
      7 #if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
      8 using namespace std;
      9 #endif
     10 
     11 //
     12 // TestCase class
     13 //
     14 class PlusMinusTest : public CPPUNIT_NS::TestCase
     15 {
     16   CPPUNIT_TEST_SUITE(PlusMinusTest);
     17   CPPUNIT_TEST(plus0);
     18   CPPUNIT_TEST(minus0);
     19   CPPUNIT_TEST_SUITE_END();
     20 
     21 protected:
     22   void plus0();
     23   void minus0();
     24 };
     25 
     26 CPPUNIT_TEST_SUITE_REGISTRATION(PlusMinusTest);
     27 
     28 //
     29 // tests implementation
     30 //
     31 void PlusMinusTest::plus0()
     32 {
     33   int input1 [4] = { 1, 6, 11, 8 };
     34   int input2 [4] = { 1, 5, 2, 3 };
     35 
     36   int total = inner_product(input1, input1 + 4, input2, 0, plus<int>(), multiplies <int>());
     37 
     38   CPPUNIT_ASSERT(total==77);
     39 }
     40 void PlusMinusTest::minus0()
     41 {
     42   int input1 [4] = { 1, 5, 7, 8 };
     43   int input2 [4] = { 1, 4, 8, 3 };
     44 
     45   int output [4];
     46 
     47   transform((int*)input1, (int*)input1 + 4, (int*)input2, (int*)output, minus<int>());
     48   CPPUNIT_ASSERT(output[0]==0);
     49   CPPUNIT_ASSERT(output[1]==1);
     50   CPPUNIT_ASSERT(output[2]==-1);
     51   CPPUNIT_ASSERT(output[3]==5);
     52 }
     53