genericopenlibs/cppstdlib/stl/test/unit/plusminus_test.cpp
author Simon Howkins <simonh@symbian.org>
Thu, 28 Oct 2010 12:05:33 +0100
branchRCL_3
changeset 78 5b3c983434ca
parent 0 e4d67989cc36
child 18 47c74d1534e1
permissions -rw-r--r--
Commented out export of missing CRML source file to avoid build error. There are no known side effects of this file being missing, so this seems a reasonable way to avoid the build error.

#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);
}