From 9841d87212f39da1f99de1302c57d4ee25b8c56f Mon Sep 17 00:00:00 2001 From: Kohei Takahashi Date: Thu, 12 Jun 2014 01:04:29 +0900 Subject: [PATCH] Add tests for fusion based zip_iterator Signed-off-by: Kohei Takahashi --- test/Jamfile.v2 | 22 +++++---- test/detail/zip_iterator_test.ipp | 73 ++++++++++++++++++++++++++++ test/zip_iterator_test_fusion.cpp | 15 ++++++ test/zip_iterator_test_std_pair.cpp | 16 ++++++ test/zip_iterator_test_std_tuple.cpp | 29 +++++++++++ 5 files changed, 145 insertions(+), 10 deletions(-) create mode 100644 test/detail/zip_iterator_test.ipp create mode 100644 test/zip_iterator_test_fusion.cpp create mode 100644 test/zip_iterator_test_std_pair.cpp create mode 100644 test/zip_iterator_test_std_tuple.cpp diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 023a826..560c212 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -3,28 +3,30 @@ # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) test-suite iterator - : + : # These first two tests will run last, and are expected to fail # for many less-capable compilers. - + [ compile-fail interoperable_fail.cpp ] # test uses expected success, so that we catch unrelated # compilation problems. - [ run is_convertible_fail.cpp ] + [ run is_convertible_fail.cpp ] [ run zip_iterator_test.cpp - : : : - + : : : # stlport's debug mode generates long symbols which overwhelm # vc6 - #<*>release + #<*>release ] - + [ run zip_iterator_test_fusion.cpp ] + [ run zip_iterator_test_std_tuple.cpp ] + [ run zip_iterator_test_std_pair.cpp ] + # These tests should work for just about everything. [ compile is_lvalue_iterator.cpp ] [ compile is_readable_iterator.cpp ] [ compile pointee.cpp ] - + [ run unit_tests.cpp ] [ run concept_tests.cpp ] [ run iterator_adaptor_cc.cpp ] @@ -41,8 +43,8 @@ test-suite iterator [ run counting_iterator_test.cpp ] [ run interoperable.cpp ] [ run iterator_traits_test.cpp ] - [ run permutation_iterator_test.cpp : : : # on + [ run permutation_iterator_test.cpp : : : # on ] [ run function_input_iterator_test.cpp ] - + ; diff --git a/test/detail/zip_iterator_test.ipp b/test/detail/zip_iterator_test.ipp new file mode 100644 index 0000000..f659099 --- /dev/null +++ b/test/detail/zip_iterator_test.ipp @@ -0,0 +1,73 @@ +// Copyright (c) 2014 Kohei Takahashi. +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// +// See http://www.boost.org for most recent version including documentation. + +#include + +#include +#include +#include +#include +#include + + +int main() +{ + typedef TUPLE< + std::vector::iterator, + std::vector::iterator + > iterator_tuple; + + std::vector vi = boost::assign::list_of(42)(72); + std::vector vs = boost::assign::list_of("kokoro")("pyonpyon"); + + { + boost::zip_iterator i1(MAKE_TUPLE(vi.begin(), vs.begin())); + boost::zip_iterator i2 = i1; + + BOOST_TEST( i1 == i2); + BOOST_TEST( i1++ == i2); + BOOST_TEST( i1 == (i2 + 1)); + BOOST_TEST((i1 - 1) == i2); + BOOST_TEST( i1-- == ++i2); + BOOST_TEST( i1 == --i2); + } + + { + boost::zip_iterator i1(MAKE_TUPLE(vi.begin(), vs.begin())); + boost::zip_iterator i2 = i1 + 1; + + BOOST_TEST( i1 != i2); + BOOST_TEST( i1++ != i2); + BOOST_TEST( i1 != (i2 + 1)); + BOOST_TEST((i1 - 1) != i2); + BOOST_TEST( i1-- != ++i2); + BOOST_TEST( i1 != --i2); + } + + { + boost::zip_iterator i(MAKE_TUPLE(vi.begin(), vs.begin())); + + BOOST_TEST(boost::fusion::at_c<0>(* i ) == 42); + BOOST_TEST(boost::fusion::at_c<1>(* i ) == "kokoro"); + BOOST_TEST(boost::fusion::at_c<0>(*(i + 1)) == 72); + BOOST_TEST(boost::fusion::at_c<1>(*(i + 1)) == "pyonpyon"); + } + + { + boost::zip_iterator i1(MAKE_TUPLE(vi.begin(), vs.begin())); + boost::zip_iterator i2(MAKE_TUPLE(vi.end(), vs.end())); + + BOOST_TEST((i2 - i1) == 2); + ++i1; + BOOST_TEST((i2 - i1) == 1); + --i2; + BOOST_TEST((i2 - i1) == 0); + } + + return boost::report_errors(); +} diff --git a/test/zip_iterator_test_fusion.cpp b/test/zip_iterator_test_fusion.cpp new file mode 100644 index 0000000..542fd88 --- /dev/null +++ b/test/zip_iterator_test_fusion.cpp @@ -0,0 +1,15 @@ +// Copyright (c) 2014 Kohei Takahashi. +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// +// See http://www.boost.org for most recent version including documentation. + +#include +#include + +#define TUPLE boost::fusion::vector +#define MAKE_TUPLE boost::fusion::make_vector + +#include "detail/zip_iterator_test.ipp" diff --git a/test/zip_iterator_test_std_pair.cpp b/test/zip_iterator_test_std_pair.cpp new file mode 100644 index 0000000..215777a --- /dev/null +++ b/test/zip_iterator_test_std_pair.cpp @@ -0,0 +1,16 @@ +// Copyright (c) 2014 Kohei Takahashi. +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// +// See http://www.boost.org for most recent version including documentation. + +#include +#include + +#define TUPLE std::pair +#define MAKE_TUPLE std::make_pair + +#include "detail/zip_iterator_test.ipp" + diff --git a/test/zip_iterator_test_std_tuple.cpp b/test/zip_iterator_test_std_tuple.cpp new file mode 100644 index 0000000..02d648d --- /dev/null +++ b/test/zip_iterator_test_std_tuple.cpp @@ -0,0 +1,29 @@ +// Copyright (c) 2014 Kohei Takahashi. +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// +// See http://www.boost.org for most recent version including documentation. + +#include + +#if !defined(BOOST_NO_CXX11_HDR_TUPLE) && !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) + +#include +#include + +#define TUPLE std::tuple +#define MAKE_TUPLE std::make_tuple + +#include "detail/zip_iterator_test.ipp" + +#else + +int main() +{ + return 0; +} + +#endif +