ReactOS  0.4.14-dev-317-g96040ec
transform_test.cpp
Go to the documentation of this file.
1 #include <string>
2 #include <iterator>
3 #include <vector>
4 #include <algorithm>
5 
7 
8 #if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
9 using namespace std;
10 #endif
11 
12 //
13 // TestCase class
14 //
15 class TransformTest : public CPPUNIT_NS::TestCase
16 {
18  CPPUNIT_TEST(trnsfrm1);
19  CPPUNIT_TEST(trnsfrm2);
20  CPPUNIT_TEST(self_str);
22 
23 protected:
24  void trnsfrm1();
25  void trnsfrm2();
26  void self_str();
27 
28  static int negate_int(int a_) {
29  return -a_;
30  }
31  static char map_char(char a_, int b_) {
32  return char(a_ + b_);
33  }
34  static char shift( char c ) {
35  return char(((int)c + 1) % 256);
36  }
37 };
38 
40 
41 //
42 // tests implementation
43 //
45 {
46  int numbers[6] = { -5, -1, 0, 1, 6, 11 };
47 
48  int result[6];
49  transform((int*)numbers, (int*)numbers + 6, (int*)result, negate_int);
50 
51  CPPUNIT_ASSERT(result[0]==5);
52  CPPUNIT_ASSERT(result[1]==1);
53  CPPUNIT_ASSERT(result[2]==0);
54  CPPUNIT_ASSERT(result[3]==-1);
55  CPPUNIT_ASSERT(result[4]==-6);
56  CPPUNIT_ASSERT(result[5]==-11);
57 }
59 {
60 #if defined (__MVS__)
61  int trans[] = {-11, 4, -6, -6, -18, 0, 18, -14, 6, 0, -1, -59};
62 #else
63  int trans[] = {-4, 4, -6, -6, -10, 0, 10, -6, 6, 0, -1, -77};
64 #endif
65  char n[] = "Larry Mullen";
66  const size_t count = ::strlen(n);
67 
68  string res;
69  transform(n, n + count, trans, back_inserter(res), map_char);
70  CPPUNIT_ASSERT( res == "Hello World!" )
71 }
72 
74 {
75  string s( "0123456789abcdefg" );
76  string r( "123456789:bcdefgh" );
77  transform( s.begin(), s.end(), s.begin(), shift );
78  CPPUNIT_ASSERT( s == r );
79 }
80 
#define shift
Definition: input.c:1668
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLuint GLuint GLsizei count
Definition: gl.h:1545
CPPUNIT_TEST_SUITE_REGISTRATION(TransformTest)
static char shift(char c)
static int negate_int(int a_)
GLdouble n
Definition: glext.h:7729
#define CPPUNIT_TEST_SUITE(X)
Definition: cppunit_mini.h:142
#define CPPUNIT_TEST(X)
Definition: cppunit_mini.h:182
Definition: features.h:417
back_insert_iterator< _Container > _STLP_CALL back_inserter(_Container &__x)
Definition: _iterator.h:187
unsigned char
Definition: typeof.h:29
#define CPPUNIT_TEST_SUITE_END()
Definition: cppunit_mini.h:191
static char map_char(char a_, int b_)
const GLubyte * c
Definition: glext.h:8905
GLdouble s
Definition: gl.h:2039
#define CPPUNIT_ASSERT(X)
Definition: cppunit_mini.h:200
GLuint res
Definition: glext.h:9613
GLuint GLenum GLenum transform
Definition: glext.h:9407
GLuint64EXT * result
Definition: glext.h:11304