genericopenlibs/cppstdlib/stl/test/unit/logic_test.cpp
changeset 0 e4d67989cc36
child 18 47c74d1534e1
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 #include <vector>
       
     2 #include <algorithm>
       
     3 #include <functional>
       
     4 
       
     5 #include "cppunit/cppunit_proxy.h"
       
     6 
       
     7 #if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
       
     8 using namespace std;
       
     9 #endif
       
    10 
       
    11 //
       
    12 // TestCase class
       
    13 //
       
    14 class LogicTest : public CPPUNIT_NS::TestCase
       
    15 {
       
    16   CPPUNIT_TEST_SUITE(LogicTest);
       
    17   CPPUNIT_TEST(logicand);
       
    18   CPPUNIT_TEST(logicnot);
       
    19   CPPUNIT_TEST(logicor);
       
    20   CPPUNIT_TEST_SUITE_END();
       
    21 
       
    22 protected:
       
    23   void logicand();
       
    24   void logicnot();
       
    25   void logicor();
       
    26 };
       
    27 
       
    28 CPPUNIT_TEST_SUITE_REGISTRATION(LogicTest);
       
    29 
       
    30 //
       
    31 // tests implementation
       
    32 //
       
    33 void LogicTest::logicand()
       
    34 {
       
    35   bool input1 [4] = { true, true, false, true };
       
    36   bool input2 [4] = { false, true, false, false };
       
    37 
       
    38   bool output [4];
       
    39   transform((bool*)input1, (bool*)input1 + 4, (bool*)input2, (bool*)output, logical_and<bool>());
       
    40 
       
    41   CPPUNIT_ASSERT(output[0]==false);
       
    42   CPPUNIT_ASSERT(output[1]==true);
       
    43   CPPUNIT_ASSERT(output[2]==false);
       
    44   CPPUNIT_ASSERT(output[3]==false);
       
    45 }
       
    46 void LogicTest::logicnot()
       
    47 {
       
    48   bool input [7] = { 1, 0, 0, 1, 1, 1, 1 };
       
    49 
       
    50   int n = count_if(input, input + 7, logical_not<bool>());
       
    51   CPPUNIT_ASSERT( n == 2 );
       
    52 }
       
    53 void LogicTest::logicor()
       
    54 {
       
    55   bool input1 [4] = { true, true, false, true };
       
    56   bool input2 [4] = { false, true, false, false };
       
    57 
       
    58   bool output [4];
       
    59   transform((bool*)input1, (bool*)input1 + 4, (bool*)input2, (bool*)output, logical_or<bool>());
       
    60 
       
    61   CPPUNIT_ASSERT(output[0]==true);
       
    62   CPPUNIT_ASSERT(output[1]==true);
       
    63   CPPUNIT_ASSERT(output[2]==false);
       
    64   CPPUNIT_ASSERT(output[3]==true);
       
    65 }