os/ossrv/genericopenlibs/cppstdlib/stl/test/unit/bound_test.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/genericopenlibs/cppstdlib/stl/test/unit/bound_test.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,80 @@
     1.4 +#include <vector>
     1.5 +#include <algorithm>
     1.6 +
     1.7 +#include "cppunit/cppunit_proxy.h"
     1.8 +
     1.9 +#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
    1.10 +using namespace std;
    1.11 +#endif
    1.12 +
    1.13 +//
    1.14 +// TestCase class
    1.15 +//
    1.16 +class BoundTest : public CPPUNIT_NS::TestCase
    1.17 +{
    1.18 +  CPPUNIT_TEST_SUITE(BoundTest);
    1.19 +  CPPUNIT_TEST(lwrbnd1);
    1.20 +  CPPUNIT_TEST(lwrbnd2);
    1.21 +  CPPUNIT_TEST(uprbnd1);
    1.22 +  CPPUNIT_TEST(uprbnd2);
    1.23 +  CPPUNIT_TEST_SUITE_END();
    1.24 +
    1.25 +protected:
    1.26 +  void lwrbnd1();
    1.27 +  void lwrbnd2();
    1.28 +  void uprbnd1();
    1.29 +  void uprbnd2();
    1.30 +
    1.31 +  static bool char_str_less(const char* a_, const char* b_)
    1.32 +  {
    1.33 +    return strcmp(a_, b_) < 0 ? 1 : 0;
    1.34 +  }
    1.35 +};
    1.36 +
    1.37 +CPPUNIT_TEST_SUITE_REGISTRATION(BoundTest);
    1.38 +
    1.39 +//
    1.40 +// tests implementation
    1.41 +//
    1.42 +void BoundTest::uprbnd1()
    1.43 +{
    1.44 +  int arr[20];
    1.45 +  for(int i = 0; i < 20; i++)
    1.46 +  {
    1.47 +    arr[i] = i/4;
    1.48 +  }
    1.49 +  int location = upper_bound((int*)arr, (int*)arr + 20, 3) - arr;
    1.50 +  CPPUNIT_ASSERT(location==16);
    1.51 +}
    1.52 +
    1.53 +void BoundTest::uprbnd2()
    1.54 +{
    1.55 +  char const* str [] = { "a", "a", "b", "b", "q", "w", "z" };
    1.56 +
    1.57 +  const unsigned strCt = sizeof(str)/sizeof(str[0]);
    1.58 +
    1.59 +  int location = (upper_bound((char const**)str,  (char const**)str + strCt, (const char *)"d", char_str_less) - str);
    1.60 +  CPPUNIT_ASSERT(location==4);
    1.61 +}
    1.62 +void BoundTest::lwrbnd1()
    1.63 +{
    1.64 +  vector <int> v1(20);
    1.65 +  for (int i = 0; (size_t)i < v1.size(); ++i)
    1.66 +  {
    1.67 +    v1[i] = i/4;
    1.68 +  }
    1.69 +  // 0 0 0 0 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4
    1.70 +  vector<int>::iterator location = lower_bound(v1.begin(), v1.end(), 3);
    1.71 +
    1.72 +  CPPUNIT_ASSERT((location - v1.begin())==12);
    1.73 +}
    1.74 +
    1.75 +void BoundTest::lwrbnd2()
    1.76 +{
    1.77 +  char const* str [] = { "a", "a", "b", "b", "q", "w", "z" };
    1.78 +
    1.79 +  const unsigned strCt = sizeof(str)/sizeof(str[0]);
    1.80 +  char const** location = lower_bound((char const**)str,  (char const**)str + strCt, (const char *)"d", char_str_less);
    1.81 +
    1.82 +  CPPUNIT_ASSERT((location - str) == 4);
    1.83 +}