mirror of
https://github.com/boostorg/iterator.git
synced 2025-07-29 20:37:17 +02:00
Stop using assert() in tests so we can test with NDEBUG defined.
[SVN r33026]
This commit is contained in:
@ -45,7 +45,7 @@
|
|||||||
#endif
|
#endif
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <cassert>
|
#include <boost/detail/lightweight_test.hpp>
|
||||||
#ifndef BOOST_NO_SLIST
|
#ifndef BOOST_NO_SLIST
|
||||||
# ifdef BOOST_SLIST_HEADER
|
# ifdef BOOST_SLIST_HEADER
|
||||||
# include BOOST_SLIST_HEADER
|
# include BOOST_SLIST_HEADER
|
||||||
@ -59,7 +59,7 @@
|
|||||||
template <class T>
|
template <class T>
|
||||||
struct signed_assert_nonnegative
|
struct signed_assert_nonnegative
|
||||||
{
|
{
|
||||||
static void test(T x) { assert(x >= 0); }
|
static void test(T x) { BOOST_TEST(x >= 0); }
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
@ -96,7 +96,7 @@ void category_test(
|
|||||||
difference_type offset = (unsigned)rand() % distance;
|
difference_type offset = (unsigned)rand() % distance;
|
||||||
|
|
||||||
#ifdef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
|
#ifdef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
|
||||||
assert(offset >= 0);
|
BOOST_TEST(offset >= 0);
|
||||||
#else
|
#else
|
||||||
assert_nonnegative<difference_type>::test(offset);
|
assert_nonnegative<difference_type>::test(offset);
|
||||||
#endif
|
#endif
|
||||||
@ -105,17 +105,17 @@ void category_test(
|
|||||||
std::advance(internal, offset);
|
std::advance(internal, offset);
|
||||||
|
|
||||||
// Try some binary searches on the range to show that it's ordered
|
// Try some binary searches on the range to show that it's ordered
|
||||||
assert(std::binary_search(start, finish, *internal));
|
BOOST_TEST(std::binary_search(start, finish, *internal));
|
||||||
|
|
||||||
// #including tuple crashed borland, so I had to give up on tie().
|
// #including tuple crashed borland, so I had to give up on tie().
|
||||||
std::pair<CountingIterator,CountingIterator> xy(
|
std::pair<CountingIterator,CountingIterator> xy(
|
||||||
std::equal_range(start, finish, *internal));
|
std::equal_range(start, finish, *internal));
|
||||||
CountingIterator x = xy.first, y = xy.second;
|
CountingIterator x = xy.first, y = xy.second;
|
||||||
|
|
||||||
assert(boost::detail::distance(x, y) == 1);
|
BOOST_TEST(boost::detail::distance(x, y) == 1);
|
||||||
|
|
||||||
// Show that values outside the range can't be found
|
// Show that values outside the range can't be found
|
||||||
assert(!std::binary_search(start, boost::prior(finish), *finish));
|
BOOST_TEST(!std::binary_search(start, boost::prior(finish), *finish));
|
||||||
|
|
||||||
// Do the generic random_access_iterator_test
|
// Do the generic random_access_iterator_test
|
||||||
typedef typename CountingIterator::value_type value_type;
|
typedef typename CountingIterator::value_type value_type;
|
||||||
@ -163,7 +163,7 @@ void test_aux(CountingIterator start, CountingIterator finish, Value v1)
|
|||||||
; p != finish && boost::next(p) != finish
|
; p != finish && boost::next(p) != finish
|
||||||
; ++p)
|
; ++p)
|
||||||
{
|
{
|
||||||
assert(boost::next(*p) == *boost::next(p));
|
BOOST_TEST(boost::next(*p) == *boost::next(p));
|
||||||
}
|
}
|
||||||
|
|
||||||
// prove that a reference can be formed to these values
|
// prove that a reference can be formed to these values
|
||||||
@ -296,5 +296,5 @@ int main()
|
|||||||
int array[2000];
|
int array[2000];
|
||||||
test(boost::make_counting_iterator(array), boost::make_counting_iterator(array+2000-1));
|
test(boost::make_counting_iterator(array), boost::make_counting_iterator(array+2000-1));
|
||||||
|
|
||||||
return 0;
|
return boost::report_errors();
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,9 @@
|
|||||||
#include <boost/mpl/has_xxx.hpp>
|
#include <boost/mpl/has_xxx.hpp>
|
||||||
|
|
||||||
#include <boost/type_traits/broken_compiler_spec.hpp>
|
#include <boost/type_traits/broken_compiler_spec.hpp>
|
||||||
|
|
||||||
|
#include <boost/detail/lightweight_test.hpp>
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <set>
|
#include <set>
|
||||||
@ -85,32 +88,32 @@ void more_indirect_iterator_tests()
|
|||||||
|
|
||||||
indirect_ra_container::iterator db(ptr_ra_container.begin());
|
indirect_ra_container::iterator db(ptr_ra_container.begin());
|
||||||
indirect_ra_container::iterator de(ptr_ra_container.end());
|
indirect_ra_container::iterator de(ptr_ra_container.end());
|
||||||
assert(static_cast<std::size_t>(de - db) == store.size());
|
BOOST_TEST(static_cast<std::size_t>(de - db) == store.size());
|
||||||
assert(db + store.size() == de);
|
BOOST_TEST(db + store.size() == de);
|
||||||
indirect_ra_container::const_iterator dci = db;
|
indirect_ra_container::const_iterator dci = db;
|
||||||
|
|
||||||
assert(dci == db);
|
BOOST_TEST(dci == db);
|
||||||
|
|
||||||
#ifndef NO_MUTABLE_CONST_RA_ITERATOR_INTEROPERABILITY
|
#ifndef NO_MUTABLE_CONST_RA_ITERATOR_INTEROPERABILITY
|
||||||
assert(db == dci);
|
BOOST_TEST(db == dci);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
assert(dci != de);
|
BOOST_TEST(dci != de);
|
||||||
assert(dci < de);
|
BOOST_TEST(dci < de);
|
||||||
assert(dci <= de);
|
BOOST_TEST(dci <= de);
|
||||||
|
|
||||||
#ifndef NO_MUTABLE_CONST_RA_ITERATOR_INTEROPERABILITY
|
#ifndef NO_MUTABLE_CONST_RA_ITERATOR_INTEROPERABILITY
|
||||||
assert(de >= dci);
|
BOOST_TEST(de >= dci);
|
||||||
assert(de > dci);
|
BOOST_TEST(de > dci);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
dci = de;
|
dci = de;
|
||||||
assert(dci == de);
|
BOOST_TEST(dci == de);
|
||||||
|
|
||||||
boost::random_access_iterator_test(db + 1, store.size() - 1, boost::next(store.begin()));
|
boost::random_access_iterator_test(db + 1, store.size() - 1, boost::next(store.begin()));
|
||||||
|
|
||||||
*db = 999;
|
*db = 999;
|
||||||
assert(store.front() == 999);
|
BOOST_TEST(store.front() == 999);
|
||||||
|
|
||||||
// Borland C++ is getting very confused about the typedefs here
|
// Borland C++ is getting very confused about the typedefs here
|
||||||
typedef boost::indirect_iterator<iterator_set::iterator> indirect_set_iterator;
|
typedef boost::indirect_iterator<iterator_set::iterator> indirect_set_iterator;
|
||||||
@ -122,22 +125,22 @@ void more_indirect_iterator_tests()
|
|||||||
indirect_set_iterator sb(iter_set.begin());
|
indirect_set_iterator sb(iter_set.begin());
|
||||||
indirect_set_iterator se(iter_set.end());
|
indirect_set_iterator se(iter_set.end());
|
||||||
const_indirect_set_iterator sci(iter_set.begin());
|
const_indirect_set_iterator sci(iter_set.begin());
|
||||||
assert(sci == sb);
|
BOOST_TEST(sci == sb);
|
||||||
|
|
||||||
# ifndef NO_MUTABLE_CONST_STD_SET_ITERATOR_INTEROPERABILITY
|
# ifndef NO_MUTABLE_CONST_STD_SET_ITERATOR_INTEROPERABILITY
|
||||||
assert(se != sci);
|
BOOST_TEST(se != sci);
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
assert(sci != se);
|
BOOST_TEST(sci != se);
|
||||||
sci = se;
|
sci = se;
|
||||||
assert(sci == se);
|
BOOST_TEST(sci == se);
|
||||||
|
|
||||||
*boost::prior(se) = 888;
|
*boost::prior(se) = 888;
|
||||||
assert(store.back() == 888);
|
BOOST_TEST(store.back() == 888);
|
||||||
assert(std::equal(sb, se, store.begin()));
|
BOOST_TEST(std::equal(sb, se, store.begin()));
|
||||||
|
|
||||||
boost::bidirectional_iterator_test(boost::next(sb), store[1], store[2]);
|
boost::bidirectional_iterator_test(boost::next(sb), store[1], store[2]);
|
||||||
assert(std::equal(db, de, store.begin()));
|
BOOST_TEST(std::equal(db, de, store.begin()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// element_type detector; defaults to true so the test passes when
|
// element_type detector; defaults to true so the test passes when
|
||||||
@ -214,6 +217,5 @@ main()
|
|||||||
|
|
||||||
more_indirect_iterator_tests();
|
more_indirect_iterator_tests();
|
||||||
}
|
}
|
||||||
std::cout << "test successful " << std::endl;
|
return boost::report_errors();
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#include <boost/iterator/iterator_adaptor.hpp>
|
#include <boost/iterator/iterator_adaptor.hpp>
|
||||||
#include <boost/pending/iterator_tests.hpp>
|
#include <boost/pending/iterator_tests.hpp>
|
||||||
|
#include <boost/detail/lightweight_test.hpp>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
struct mutable_it : boost::iterator_adaptor<mutable_it,int*>
|
struct mutable_it : boost::iterator_adaptor<mutable_it,int*>
|
||||||
@ -39,21 +40,21 @@ int main()
|
|||||||
|
|
||||||
mutable_it i(data);
|
mutable_it i(data);
|
||||||
constant_it j(data + 1);
|
constant_it j(data + 1);
|
||||||
assert(i < j);
|
BOOST_TEST(i < j);
|
||||||
assert(j > i);
|
BOOST_TEST(j > i);
|
||||||
assert(i <= j);
|
BOOST_TEST(i <= j);
|
||||||
assert(j >= i);
|
BOOST_TEST(j >= i);
|
||||||
assert(j - i == 1);
|
BOOST_TEST(j - i == 1);
|
||||||
assert(i - j == -1);
|
BOOST_TEST(i - j == -1);
|
||||||
|
|
||||||
constant_it k = i;
|
constant_it k = i;
|
||||||
|
|
||||||
assert(!(i < k));
|
BOOST_TEST(!(i < k));
|
||||||
assert(!(k > i));
|
BOOST_TEST(!(k > i));
|
||||||
assert(i <= k);
|
BOOST_TEST(i <= k);
|
||||||
assert(k >= i);
|
BOOST_TEST(k >= i);
|
||||||
assert(k - i == 0);
|
BOOST_TEST(k - i == 0);
|
||||||
assert(i - k == 0);
|
BOOST_TEST(i - k == 0);
|
||||||
|
|
||||||
return 0;
|
return boost::report_errors();
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,8 @@
|
|||||||
|
|
||||||
# include <boost/type_traits/broken_compiler_spec.hpp>
|
# include <boost/type_traits/broken_compiler_spec.hpp>
|
||||||
|
|
||||||
|
# include <boost/detail/lightweight_test.hpp>
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <deque>
|
#include <deque>
|
||||||
@ -303,7 +305,7 @@ main()
|
|||||||
adaptor_type i(forward_iter);
|
adaptor_type i(forward_iter);
|
||||||
int zero = 0;
|
int zero = 0;
|
||||||
if (zero) // don't do this, just make sure it compiles
|
if (zero) // don't do this, just make sure it compiles
|
||||||
assert((*i).m_x == i->foo());
|
BOOST_TEST((*i).m_x == i->foo());
|
||||||
}
|
}
|
||||||
|
|
||||||
// check operator-> with an input iterator
|
// check operator-> with an input iterator
|
||||||
@ -313,7 +315,7 @@ main()
|
|||||||
adaptor_type i(input_iter);
|
adaptor_type i(input_iter);
|
||||||
int zero = 0;
|
int zero = 0;
|
||||||
if (zero) // don't do this, just make sure it compiles
|
if (zero) // don't do this, just make sure it compiles
|
||||||
assert((*i).m_x == i->foo());
|
BOOST_TEST((*i).m_x == i->foo());
|
||||||
}
|
}
|
||||||
|
|
||||||
// check that base_type is correct
|
// check that base_type is correct
|
||||||
@ -331,5 +333,5 @@ main()
|
|||||||
|
|
||||||
std::cout << "test successful " << std::endl;
|
std::cout << "test successful " << std::endl;
|
||||||
(void)test;
|
(void)test;
|
||||||
return 0;
|
return boost::report_errors();
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <cassert>
|
#include <boost/detail/lightweight_test.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
// A UDT for which we can specialize std::iterator_traits<element*> on
|
// A UDT for which we can specialize std::iterator_traits<element*> on
|
||||||
@ -204,15 +204,15 @@ int main()
|
|||||||
for (int length = 3; length < 100; length += length / 3)
|
for (int length = 3; length < 100; length += length / 3)
|
||||||
{
|
{
|
||||||
std::list<int> l(length);
|
std::list<int> l(length);
|
||||||
assert(boost::detail::distance(l.begin(), l.end()) == length);
|
BOOST_TEST(boost::detail::distance(l.begin(), l.end()) == length);
|
||||||
|
|
||||||
std::vector<int> v(length);
|
std::vector<int> v(length);
|
||||||
assert(boost::detail::distance(v.begin(), v.end()) == length);
|
BOOST_TEST(boost::detail::distance(v.begin(), v.end()) == length);
|
||||||
|
|
||||||
assert(boost::detail::distance(&ints[0], ints + length) == length);
|
BOOST_TEST(boost::detail::distance(&ints[0], ints + length) == length);
|
||||||
assert(boost::detail::distance(my_iterator1(chars), my_iterator1(chars + length)) == length);
|
BOOST_TEST(boost::detail::distance(my_iterator1(chars), my_iterator1(chars + length)) == length);
|
||||||
assert(boost::detail::distance(my_iterator2(chars), my_iterator2(chars + length)) == length);
|
BOOST_TEST(boost::detail::distance(my_iterator2(chars), my_iterator2(chars + length)) == length);
|
||||||
assert(boost::detail::distance(my_iterator3(chars), my_iterator3(chars + length)) == length);
|
BOOST_TEST(boost::detail::distance(my_iterator3(chars), my_iterator3(chars + length)) == length);
|
||||||
}
|
}
|
||||||
return 0;
|
return boost::report_errors();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user