genericopenlibs/cppstdlib/stl/test/unit/logic_test.cpp
changeset 31 ce057bb09d0b
child 34 5fae379060a7
equal deleted inserted replaced
30:e20de85af2ee 31:ce057bb09d0b
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 #include <vector>
       
    18 #include <algorithm>
       
    19 #include <functional>
       
    20 
       
    21 #include "cppunit/cppunit_proxy.h"
       
    22 
       
    23 #if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
       
    24 using namespace std;
       
    25 #endif
       
    26 
       
    27 //
       
    28 // TestCase class
       
    29 //
       
    30 class LogicTest : public CPPUNIT_NS::TestCase
       
    31 {
       
    32   CPPUNIT_TEST_SUITE(LogicTest);
       
    33   CPPUNIT_TEST(logicand);
       
    34   CPPUNIT_TEST(logicnot);
       
    35   CPPUNIT_TEST(logicor);
       
    36   CPPUNIT_TEST_SUITE_END();
       
    37 
       
    38 protected:
       
    39   void logicand();
       
    40   void logicnot();
       
    41   void logicor();
       
    42 };
       
    43 
       
    44 CPPUNIT_TEST_SUITE_REGISTRATION(LogicTest);
       
    45 
       
    46 //
       
    47 // tests implementation
       
    48 //
       
    49 void LogicTest::logicand()
       
    50 {
       
    51   bool input1 [4] = { true, true, false, true };
       
    52   bool input2 [4] = { false, true, false, false };
       
    53 
       
    54   bool output [4];
       
    55   transform((bool*)input1, (bool*)input1 + 4, (bool*)input2, (bool*)output, logical_and<bool>());
       
    56 
       
    57   CPPUNIT_ASSERT(output[0]==false);
       
    58   CPPUNIT_ASSERT(output[1]==true);
       
    59   CPPUNIT_ASSERT(output[2]==false);
       
    60   CPPUNIT_ASSERT(output[3]==false);
       
    61 }
       
    62 void LogicTest::logicnot()
       
    63 {
       
    64   bool input [7] = { 1, 0, 0, 1, 1, 1, 1 };
       
    65 
       
    66   int n = count_if(input, input + 7, logical_not<bool>());
       
    67   CPPUNIT_ASSERT( n == 2 );
       
    68 }
       
    69 void LogicTest::logicor()
       
    70 {
       
    71   bool input1 [4] = { true, true, false, true };
       
    72   bool input2 [4] = { false, true, false, false };
       
    73 
       
    74   bool output [4];
       
    75   transform((bool*)input1, (bool*)input1 + 4, (bool*)input2, (bool*)output, logical_or<bool>());
       
    76 
       
    77   CPPUNIT_ASSERT(output[0]==true);
       
    78   CPPUNIT_ASSERT(output[1]==true);
       
    79   CPPUNIT_ASSERT(output[2]==false);
       
    80   CPPUNIT_ASSERT(output[3]==true);
       
    81 }