os/ossrv/genericopenlibs/cppstdlib/stl/test/unit/logic_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 <algorithm>
sl@0
     3
#include <functional>
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 LogicTest : public CPPUNIT_NS::TestCase
sl@0
    15
{
sl@0
    16
  CPPUNIT_TEST_SUITE(LogicTest);
sl@0
    17
  CPPUNIT_TEST(logicand);
sl@0
    18
  CPPUNIT_TEST(logicnot);
sl@0
    19
  CPPUNIT_TEST(logicor);
sl@0
    20
  CPPUNIT_TEST_SUITE_END();
sl@0
    21
sl@0
    22
protected:
sl@0
    23
  void logicand();
sl@0
    24
  void logicnot();
sl@0
    25
  void logicor();
sl@0
    26
};
sl@0
    27
sl@0
    28
CPPUNIT_TEST_SUITE_REGISTRATION(LogicTest);
sl@0
    29
sl@0
    30
//
sl@0
    31
// tests implementation
sl@0
    32
//
sl@0
    33
void LogicTest::logicand()
sl@0
    34
{
sl@0
    35
  bool input1 [4] = { true, true, false, true };
sl@0
    36
  bool input2 [4] = { false, true, false, false };
sl@0
    37
sl@0
    38
  bool output [4];
sl@0
    39
  transform((bool*)input1, (bool*)input1 + 4, (bool*)input2, (bool*)output, logical_and<bool>());
sl@0
    40
sl@0
    41
  CPPUNIT_ASSERT(output[0]==false);
sl@0
    42
  CPPUNIT_ASSERT(output[1]==true);
sl@0
    43
  CPPUNIT_ASSERT(output[2]==false);
sl@0
    44
  CPPUNIT_ASSERT(output[3]==false);
sl@0
    45
}
sl@0
    46
void LogicTest::logicnot()
sl@0
    47
{
sl@0
    48
  bool input [7] = { 1, 0, 0, 1, 1, 1, 1 };
sl@0
    49
sl@0
    50
  int n = count_if(input, input + 7, logical_not<bool>());
sl@0
    51
  CPPUNIT_ASSERT( n == 2 );
sl@0
    52
}
sl@0
    53
void LogicTest::logicor()
sl@0
    54
{
sl@0
    55
  bool input1 [4] = { true, true, false, true };
sl@0
    56
  bool input2 [4] = { false, true, false, false };
sl@0
    57
sl@0
    58
  bool output [4];
sl@0
    59
  transform((bool*)input1, (bool*)input1 + 4, (bool*)input2, (bool*)output, logical_or<bool>());
sl@0
    60
sl@0
    61
  CPPUNIT_ASSERT(output[0]==true);
sl@0
    62
  CPPUNIT_ASSERT(output[1]==true);
sl@0
    63
  CPPUNIT_ASSERT(output[2]==false);
sl@0
    64
  CPPUNIT_ASSERT(output[3]==true);
sl@0
    65
}