os/ossrv/genericopenlibs/cppstdlib/stl/test/unit/unary_test.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
#include <vector>
sl@0
     2
#include "unary.h"
sl@0
     3
#include <algorithm>
sl@0
     4
sl@0
     5
#include "cppunit/cppunit_proxy.h"
sl@0
     6
sl@0
     7
#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
sl@0
     8
using namespace std;
sl@0
     9
#endif
sl@0
    10
sl@0
    11
//
sl@0
    12
// TestCase class
sl@0
    13
//
sl@0
    14
class UnaryTest : public CPPUNIT_NS::TestCase
sl@0
    15
{
sl@0
    16
  CPPUNIT_TEST_SUITE(UnaryTest);
sl@0
    17
#if !defined (STLPORT) || defined (_STLP_NO_EXTENSIONS)
sl@0
    18
  CPPUNIT_IGNORE;
sl@0
    19
#endif
sl@0
    20
  CPPUNIT_TEST(ucompos1);
sl@0
    21
  CPPUNIT_TEST(ucompos2);
sl@0
    22
  CPPUNIT_STOP_IGNORE;
sl@0
    23
  CPPUNIT_TEST(unegate1);
sl@0
    24
  CPPUNIT_TEST(unegate2);
sl@0
    25
#if defined (STLPORT) && !defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
sl@0
    26
  CPPUNIT_IGNORE;
sl@0
    27
#endif
sl@0
    28
  CPPUNIT_TEST(unegate3);
sl@0
    29
  CPPUNIT_TEST_SUITE_END();
sl@0
    30
sl@0
    31
protected:
sl@0
    32
  void ucompos1();
sl@0
    33
  void ucompos2();
sl@0
    34
  void unegate1();
sl@0
    35
  void unegate2();
sl@0
    36
  void unegate3();
sl@0
    37
};
sl@0
    38
sl@0
    39
CPPUNIT_TEST_SUITE_REGISTRATION(UnaryTest);
sl@0
    40
sl@0
    41
//
sl@0
    42
// tests implementation
sl@0
    43
//
sl@0
    44
void UnaryTest::unegate1()
sl@0
    45
{
sl@0
    46
  int array [3] = { 1, 2, 3 };
sl@0
    47
  //unary_negate<odd>::argument_type arg_val = 0;
sl@0
    48
  int* p = find_if((int*)array, (int*)array + 3, unary_negate<odd>(odd()));
sl@0
    49
  CPPUNIT_ASSERT((p != array + 3));
sl@0
    50
  CPPUNIT_ASSERT(*p==2);
sl@0
    51
}
sl@0
    52
void UnaryTest::unegate2()
sl@0
    53
{
sl@0
    54
  int array [3] = { 1, 2, 3 };
sl@0
    55
  int* p = find_if((int*)array, (int*)array + 3, not1(odd()));
sl@0
    56
  CPPUNIT_ASSERT(p != array + 3);
sl@0
    57
  CPPUNIT_ASSERT(*p==2);
sl@0
    58
}
sl@0
    59
sl@0
    60
bool test_func(int param) {
sl@0
    61
  return param < 3;
sl@0
    62
}
sl@0
    63
void UnaryTest::unegate3()
sl@0
    64
{
sl@0
    65
#if !defined (STLPORT) || defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
sl@0
    66
  int array [3] = { 1, 2, 3 };
sl@0
    67
  int* p = find_if((int*)array, (int*)array + 3, not1(ptr_fun(test_func)));
sl@0
    68
  CPPUNIT_ASSERT(p != array + 3);
sl@0
    69
  CPPUNIT_ASSERT(*p==3);
sl@0
    70
#endif
sl@0
    71
}
sl@0
    72
sl@0
    73
void UnaryTest::ucompos1()
sl@0
    74
{
sl@0
    75
#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS)
sl@0
    76
  int input [3] = { -1, -4, -16 };
sl@0
    77
sl@0
    78
  double output[3];
sl@0
    79
  transform((int*)input, (int*)input + 3, output, unary_compose<square_root, negate<int> >(square_root(), negate<int>()));
sl@0
    80
sl@0
    81
  CPPUNIT_ASSERT(output[0]==1);
sl@0
    82
  CPPUNIT_ASSERT(output[1]==2);
sl@0
    83
  CPPUNIT_ASSERT(output[2]==4);
sl@0
    84
#endif
sl@0
    85
}
sl@0
    86
void UnaryTest::ucompos2()
sl@0
    87
{
sl@0
    88
#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS)
sl@0
    89
  int input [3] = { -1, -4, -16 };
sl@0
    90
sl@0
    91
  double output [3];
sl@0
    92
  transform((int*)input, (int*)input + 3, output, compose1(square_root(), negate<int>()));
sl@0
    93
sl@0
    94
  CPPUNIT_ASSERT(output[0]==1);
sl@0
    95
  CPPUNIT_ASSERT(output[1]==2);
sl@0
    96
  CPPUNIT_ASSERT(output[2]==4);
sl@0
    97
#endif
sl@0
    98
}