os/ossrv/genericopenlibs/cppstdlib/stl/test/unit/setinter_test.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200 (2012-06-15)
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
#include <numeric>
sl@0
     2
#include <string>
sl@0
     3
#include <iterator>
sl@0
     4
#include <vector>
sl@0
     5
#include <algorithm>
sl@0
     6
#include <functional>
sl@0
     7
sl@0
     8
#include "iota.h"
sl@0
     9
#include "cppunit/cppunit_proxy.h"
sl@0
    10
sl@0
    11
#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
sl@0
    12
using namespace std;
sl@0
    13
#endif
sl@0
    14
sl@0
    15
//
sl@0
    16
// TestCase class
sl@0
    17
//
sl@0
    18
class SetIntersectionTest : public CPPUNIT_NS::TestCase
sl@0
    19
{
sl@0
    20
  CPPUNIT_TEST_SUITE(SetIntersectionTest);
sl@0
    21
  CPPUNIT_TEST(setintr0);
sl@0
    22
  CPPUNIT_TEST(setintr1);
sl@0
    23
  CPPUNIT_TEST(setintr2);
sl@0
    24
  CPPUNIT_TEST_SUITE_END();
sl@0
    25
sl@0
    26
protected:
sl@0
    27
  void setintr0();
sl@0
    28
  void setintr1();
sl@0
    29
  void setintr2();
sl@0
    30
};
sl@0
    31
sl@0
    32
CPPUNIT_TEST_SUITE_REGISTRATION(SetIntersectionTest);
sl@0
    33
sl@0
    34
//
sl@0
    35
// tests implementation
sl@0
    36
//
sl@0
    37
void SetIntersectionTest::setintr0()
sl@0
    38
{
sl@0
    39
  int v1[3] = { 13, 18, 23 };
sl@0
    40
  int v2[4] = { 10, 13, 17, 23 };
sl@0
    41
  int result[4] = { 0, 0, 0, 0 };
sl@0
    42
sl@0
    43
  set_intersection((int*)v1, (int*)v1 + 3, (int*)v2, (int*)v2 + 4, (int*)result);
sl@0
    44
sl@0
    45
  CPPUNIT_ASSERT(result[0]==13);
sl@0
    46
  CPPUNIT_ASSERT(result[1]==23);
sl@0
    47
  CPPUNIT_ASSERT(result[2]==0);
sl@0
    48
  CPPUNIT_ASSERT(result[3]==0);
sl@0
    49
}
sl@0
    50
sl@0
    51
void SetIntersectionTest::setintr1()
sl@0
    52
{
sl@0
    53
  vector <int> v1(10);
sl@0
    54
  __iota(v1.begin(), v1.end(), 0);
sl@0
    55
  vector <int> v2(10);
sl@0
    56
  __iota(v2.begin(), v2.end(), 7);
sl@0
    57
sl@0
    58
  vector<int> inter;
sl@0
    59
  set_intersection(v1.begin(), v1.end(), v2.begin(), v2.end(), back_inserter(inter));
sl@0
    60
  CPPUNIT_ASSERT( inter.size() == 3 );
sl@0
    61
  CPPUNIT_ASSERT( inter[0] == 7 );
sl@0
    62
  CPPUNIT_ASSERT( inter[1] == 8 );
sl@0
    63
  CPPUNIT_ASSERT( inter[2] == 9 );
sl@0
    64
}
sl@0
    65
sl@0
    66
void SetIntersectionTest::setintr2()
sl@0
    67
{
sl@0
    68
  char* word1 = "ABCDEFGHIJKLMNO";
sl@0
    69
  char* word2 = "LMNOPQRSTUVWXYZ";
sl@0
    70
sl@0
    71
  string inter;
sl@0
    72
  set_intersection(word1, word1 + ::strlen(word1), word2, word2 + ::strlen(word2),
sl@0
    73
                   back_inserter(inter), less<char>());
sl@0
    74
  CPPUNIT_ASSERT( inter.size() == 4 );
sl@0
    75
  CPPUNIT_ASSERT( inter[0] == 'L' );
sl@0
    76
  CPPUNIT_ASSERT( inter[1] == 'M' );
sl@0
    77
  CPPUNIT_ASSERT( inter[2] == 'N' );
sl@0
    78
  CPPUNIT_ASSERT( inter[3] == 'O' );
sl@0
    79
}