genericopenlibs/cppstdlib/stl/test/unit/plusminus_test.cpp
author hgs
Tue, 20 Jul 2010 16:35:53 +0530
changeset 44 97b0fb8a2cc2
parent 18 47c74d1534e1
permissions -rw-r--r--
201025

#include <numeric>
#include <algorithm>
#include <functional>

#include "cppunit/cppunit_proxy.h"

#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
using namespace std;
#endif

//
// TestCase class
//
class PlusMinusTest : public CPPUNIT_NS::TestCase
{
  CPPUNIT_TEST_SUITE(PlusMinusTest);
  CPPUNIT_TEST(plus0);
  CPPUNIT_TEST(minus0);
  CPPUNIT_TEST_SUITE_END();

protected:
  void plus0();
  void minus0();
};

CPPUNIT_TEST_SUITE_REGISTRATION(PlusMinusTest);

//
// tests implementation
//
void PlusMinusTest::plus0()
{
  int input1 [4] = { 1, 6, 11, 8 };
  int input2 [4] = { 1, 5, 2, 3 };

  int total = inner_product(input1, input1 + 4, input2, 0, plus<int>(), multiplies <int>());

  CPPUNIT_ASSERT(total==77);
}
void PlusMinusTest::minus0()
{
  int input1 [4] = { 1, 5, 7, 8 };
  int input2 [4] = { 1, 4, 8, 3 };

  int output [4];

  transform((int*)input1, (int*)input1 + 4, (int*)input2, (int*)output, minus<int>());
  CPPUNIT_ASSERT(output[0]==0);
  CPPUNIT_ASSERT(output[1]==1);
  CPPUNIT_ASSERT(output[2]==-1);
  CPPUNIT_ASSERT(output[3]==5);
}