Sha256: 5b9b3a634f7598a96d2f53c5ddc79c3cf50a7719f684a39b3f7b9c54d452b9fb

Contents?: true

Size: 1.67 KB

Versions: 135

Compression:

Stored size: 1.67 KB

Contents

#include <string>
#include <iterator>
#include <vector>
#include <algorithm>

#include "cppunit/cppunit_proxy.h"

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

//
// TestCase class
//
class TransformTest : public CPPUNIT_NS::TestCase
{
  CPPUNIT_TEST_SUITE(TransformTest);
  CPPUNIT_TEST(trnsfrm1);
  CPPUNIT_TEST(trnsfrm2);
  CPPUNIT_TEST(self_str);
  CPPUNIT_TEST_SUITE_END();

protected:
  void trnsfrm1();
  void trnsfrm2();
  void self_str();

  static int negate_int(int a_) {
    return -a_;
  }
  static char map_char(char a_, int b_) {
    return char(a_ + b_);
  }
  static char shift( char c ) {
    return char(((int)c + 1) % 256);
  }
};

CPPUNIT_TEST_SUITE_REGISTRATION(TransformTest);

//
// tests implementation
//
void TransformTest::trnsfrm1()
{
  int numbers[6] = { -5, -1, 0, 1, 6, 11 };

  int result[6];
  transform((int*)numbers, (int*)numbers + 6, (int*)result, negate_int);

  CPPUNIT_ASSERT(result[0]==5);
  CPPUNIT_ASSERT(result[1]==1);
  CPPUNIT_ASSERT(result[2]==0);
  CPPUNIT_ASSERT(result[3]==-1);
  CPPUNIT_ASSERT(result[4]==-6);
  CPPUNIT_ASSERT(result[5]==-11);
}
void TransformTest::trnsfrm2()
{
#if defined (__MVS__)
  int trans[] = {-11, 4, -6, -6, -18, 0, 18, -14, 6, 0, -1, -59};
#else
  int trans[] = {-4, 4, -6, -6, -10, 0, 10, -6, 6, 0, -1, -77};
#endif
  char n[] = "Larry Mullen";
  const size_t count = ::strlen(n);

  string res;
  transform(n, n + count, trans, back_inserter(res), map_char);
  CPPUNIT_ASSERT( res == "Hello World!" )
}

void TransformTest::self_str()
{
  string s( "0123456789abcdefg" );
  string r( "123456789:bcdefgh" );
  transform( s.begin(), s.end(), s.begin(), shift );
  CPPUNIT_ASSERT( s == r );
}

Version data entries

135 entries across 135 versions & 2 rubygems

Version Path
rhodes-7.6.0 platform/shared/stlport/test/unit/transform_test.cpp
rhodes-7.5.1 platform/shared/stlport/test/unit/transform_test.cpp
rhodes-7.4.1 platform/shared/stlport/test/unit/transform_test.cpp
rhodes-7.1.17 platform/shared/stlport/test/unit/transform_test.cpp
rhodes-6.2.0 platform/shared/stlport/test/unit/transform_test.cpp
rhodes-6.0.11 platform/shared/stlport/test/unit/transform_test.cpp
rhodes-5.5.18 platform/shared/stlport/test/unit/transform_test.cpp
rhodes-5.5.17 platform/shared/stlport/test/unit/transform_test.cpp
rhodes-5.5.15 platform/shared/stlport/test/unit/transform_test.cpp
rhodes-5.5.0.22 platform/shared/stlport/test/unit/transform_test.cpp
rhodes-5.5.2 platform/shared/stlport/test/unit/transform_test.cpp
rhodes-5.5.0.7 platform/shared/stlport/test/unit/transform_test.cpp
rhodes-5.5.0.3 platform/shared/stlport/test/unit/transform_test.cpp
rhodes-5.5.0 platform/shared/stlport/test/unit/transform_test.cpp
tauplatform-1.0.3 platform/shared/stlport/test/unit/transform_test.cpp
tauplatform-1.0.2 platform/shared/stlport/test/unit/transform_test.cpp
tauplatform-1.0.1 platform/shared/stlport/test/unit/transform_test.cpp
rhodes-3.5.1.12 platform/shared/stlport/test/unit/transform_test.cpp
rhodes-3.3.5 platform/shared/stlport/test/unit/transform_test.cpp
rhodes-3.4.2 platform/shared/stlport/test/unit/transform_test.cpp