コード例 #1
0
ファイル: testglib_keyset.c プロジェクト: 0003088/libelektra
int main (int argc, char ** argv)
{
	printf ("KEYSET TESTS\n");
	printf ("===============\n\n");

	init (argc, argv);

	test_ctor ();
	test_basic ();
	test_searching ();
	test_iterating ();

	printf ("\n%s RESULTS: %d test(s) done. %d error(s).\n", argv[0], nbTest, nbError);
	return nbError;
}
コード例 #2
0
ファイル: test.cpp プロジェクト: cassioneri/Map
static void
test_insertion_erasure_and_searching() {

  map<int, int> m;
  const auto& cb = m;

  std::map<int, int> sm;
  const auto& csm = sm;

  int i = 0;

  for (const auto& x : il) {

    if (i++ & 2)
      m.insert(x);
    else
      m[x.first] = x.second;

    sm.insert(x);

    test_equality(m, sm);
    test_copying(m);

    test_searching(m .lower_bound(1), m .end(), sm .lower_bound(1), sm .end());
    test_searching(m .lower_bound(2), m .end(), sm .lower_bound(2), sm .end());

    test_searching(cb.lower_bound(1), cb.end(), csm.lower_bound(1), csm.end());
    test_searching(cb.lower_bound(2), cb.end(), csm.lower_bound(2), csm.end());

    test_searching(m .upper_bound(1), m .end(), sm .upper_bound(1), sm .end());
    test_searching(m .upper_bound(2), m .end(), sm .upper_bound(2), sm .end());

    test_searching(cb.upper_bound(1), cb.end(), csm.upper_bound(1), csm.end());
    test_searching(cb.upper_bound(2), cb.end(), csm.upper_bound(2), csm.end());

    test_searching(m .find(1), m .end(), sm .find(1), sm .end());
    test_searching(m .find(2), m .end(), sm .find(2), sm .end());

    test_searching(cb.find(1), cb.end(), csm.find(1), csm.end());
    test_searching(cb.find(2), cb.end(), csm.find(2), csm.end());
  }

  for (const auto& x : il) {

    auto im  =  m.find(x.first);
    auto ism = sm.find(x.first);

    assert((im == m.end()) == (ism == sm.end()));

    if (im != m.end()) {
      im  =  m.erase(im);
      ism = sm.erase(ism);
    }

    assert((im == m.end()) == (ism == sm.end()));
    assert(im == m.end() || *im == *ism);
  }

  m.insert(il.begin(), il.end());
  sm = il;
  test_equality(m, sm);

  assert(m.erase(m.begin(), m.end()) == m.end());
  test_emptiness(m);

  m = il;
  auto it = --m.end();
  assert(m.erase(++m.begin(), it) == it);

  sm = il;
  sm.erase(++sm.begin(), --sm.end());

  test_equality(m, sm);
}