Sha256: 749c14c46b2639ab6128cac6457c6a64804ac5f0d793ffdd5b2851ed3a6d3355

Contents?: true

Size: 1.72 KB

Versions: 135

Compression:

Stored size: 1.72 KB

Contents

#include <vector>
#include <algorithm>

#include "cppunit/cppunit_proxy.h"

#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
using namespace std;
#endif

//
// TestCase class
//
class BoundTest : public CPPUNIT_NS::TestCase
{
  CPPUNIT_TEST_SUITE(BoundTest);
  CPPUNIT_TEST(lwrbnd1);
  CPPUNIT_TEST(lwrbnd2);
  CPPUNIT_TEST(uprbnd1);
  CPPUNIT_TEST(uprbnd2);
  CPPUNIT_TEST_SUITE_END();

protected:
  void lwrbnd1();
  void lwrbnd2();
  void uprbnd1();
  void uprbnd2();

  static bool char_str_less(const char* a_, const char* b_)
  {
    return strcmp(a_, b_) < 0 ? 1 : 0;
  }
};

CPPUNIT_TEST_SUITE_REGISTRATION(BoundTest);

//
// tests implementation
//
void BoundTest::uprbnd1()
{
  int arr[20];
  for(int i = 0; i < 20; i++)
  {
    arr[i] = i/4;
  }
  int location = upper_bound((int*)arr, (int*)arr + 20, 3) - arr;
  CPPUNIT_ASSERT(location==16);
}

void BoundTest::uprbnd2()
{
  char const* str [] = { "a", "a", "b", "b", "q", "w", "z" };

  const unsigned strCt = sizeof(str)/sizeof(str[0]);

  int location = (upper_bound((char const**)str,  (char const**)str + strCt, (const char *)"d", char_str_less) - str);
  CPPUNIT_ASSERT(location==4);
}
void BoundTest::lwrbnd1()
{
  vector <int> v1(20);
  for (int i = 0; (size_t)i < v1.size(); ++i)
  {
    v1[i] = i/4;
  }
  // 0 0 0 0 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4
  vector<int>::iterator location = lower_bound(v1.begin(), v1.end(), 3);

  CPPUNIT_ASSERT((location - v1.begin())==12);
}

void BoundTest::lwrbnd2()
{
  char const* str [] = { "a", "a", "b", "b", "q", "w", "z" };

  const unsigned strCt = sizeof(str)/sizeof(str[0]);
  char const** location = lower_bound((char const**)str,  (char const**)str + strCt, (const char *)"d", char_str_less);

  CPPUNIT_ASSERT((location - str) == 4);
}

Version data entries

135 entries across 135 versions & 2 rubygems

Version Path
rhodes-7.6.0 platform/shared/stlport/test/unit/bound_test.cpp
rhodes-7.5.1 platform/shared/stlport/test/unit/bound_test.cpp
rhodes-7.4.1 platform/shared/stlport/test/unit/bound_test.cpp
rhodes-7.1.17 platform/shared/stlport/test/unit/bound_test.cpp
rhodes-6.2.0 platform/shared/stlport/test/unit/bound_test.cpp
rhodes-6.0.11 platform/shared/stlport/test/unit/bound_test.cpp
rhodes-5.5.18 platform/shared/stlport/test/unit/bound_test.cpp
rhodes-5.5.17 platform/shared/stlport/test/unit/bound_test.cpp
rhodes-5.5.15 platform/shared/stlport/test/unit/bound_test.cpp
rhodes-5.5.0.22 platform/shared/stlport/test/unit/bound_test.cpp
rhodes-5.5.2 platform/shared/stlport/test/unit/bound_test.cpp
rhodes-5.5.0.7 platform/shared/stlport/test/unit/bound_test.cpp
rhodes-5.5.0.3 platform/shared/stlport/test/unit/bound_test.cpp
rhodes-5.5.0 platform/shared/stlport/test/unit/bound_test.cpp
tauplatform-1.0.3 platform/shared/stlport/test/unit/bound_test.cpp
tauplatform-1.0.2 platform/shared/stlport/test/unit/bound_test.cpp
tauplatform-1.0.1 platform/shared/stlport/test/unit/bound_test.cpp
rhodes-3.5.1.12 platform/shared/stlport/test/unit/bound_test.cpp
rhodes-3.3.5 platform/shared/stlport/test/unit/bound_test.cpp
rhodes-3.4.2 platform/shared/stlport/test/unit/bound_test.cpp