Skip to content

Commit

Permalink
add test by BBv2.
Browse files Browse the repository at this point in the history
  • Loading branch information
faithandbrave committed Mar 13, 2011
1 parent 9d9d3e4 commit a2c7201
Show file tree
Hide file tree
Showing 15 changed files with 464 additions and 1 deletion.
6 changes: 6 additions & 0 deletions Jamrules
@@ -0,0 +1,6 @@
# Copyright Shunsuke Sogame 2005-2007.
# Use, modification, and distribution are subject to 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)

# For some reason, bjam needs this file.
26 changes: 26 additions & 0 deletions boost-build.jam
@@ -0,0 +1,26 @@
# Copyright Shunsuke Sogame 2005-2007.
# Use, modification, and distribution are subject to 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)

# Thanks to:
#
# Hamigaki Library build settings

# Copyright Takeshi Mouri 2006, 2007.
# Use, modification, and distribution are subject to 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)

# Original Copyright
# ============================================================================>
#~ Copyright (C) 2002-2003, David Abrahams.
#~ Copyright (C) 2002-2003, Vladimir Prus.
#~ Copyright (C) 2003, Rene Rivera.
#~ Use, modification and distribution are subject to 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)
# <============================================================================

PSTADE_ROOT = $(.boost-build-file:D) ;
boost-build $(BOOST_ROOT)/tools/build/v2 ;
49 changes: 49 additions & 0 deletions libs/range/test/Jamfile.v2
@@ -0,0 +1,49 @@
# Boost.Range 2.0 Extension library
# via PStade Oven Library
#
# Copyright Akira Takahashi 2011.
# Copyright Shunsuke Sogame 2005-2007.
# Use, modification and distribution is subject to 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)

# bring in rules for testing
import testing ;

project
: requirements
<link>static
<threading>multi
;

rule range-test ( name : includes * )
{
return [
run $(name).cpp
:
:
: <toolset>gcc:<cxxflags>"-Wall -Wunused"
] ;
}

test-suite range_extension :
[ range-test adaptor_test/dropped ]
[ range-test adaptor_test/dropped_while ]
[ range-test adaptor_test/elements ]
[ range-test adaptor_test/elements_key ]
[ range-test adaptor_test/outdirected ]
[ range-test adaptor_test/taken ]
[ range-test adaptor_test/taken_while ]
[ range-test access_test/at ]
[ range-test access_test/back ]
[ range-test access_test/front ]
# [ range-test directory_range ]
[ range-test iteration ]
[ range-test member_select_example ]
[ range-test regular ]
[ range-test regular_example ]
[ range-test regular_operator_example ]
[ range-test single ]
[ range-test split_at ]
;

72 changes: 72 additions & 0 deletions libs/range/test/directory_range.cpp
@@ -0,0 +1,72 @@
// Boost.Range 2.0 Extension library
// via PStade Oven Library
//
// Copyright Akira Takahashi 2011.
// Copyright Shunsuke Sogame 2005-2007.
// Use, modification and distribution is subject to 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)

#include <iostream>
#include <boost/detail/lightweight_test.hpp>

#include <boost/range/directory_range.hpp>

#include <vector>
#include <string>
#include <boost/assign/list_of.hpp>
#include <boost/range/begin.hpp>
#include <boost/range/end.hpp>
#include <boost/range/algorithm/for_each.hpp>
#include <boost/range/algorithm/find.hpp>

template <class InputIterator, class Pred>
bool all(InputIterator first, InputIterator last, Pred pred)
{
for (; first != last; ++first) {
if (!pred(*first))
return false;
}
return true;
}

template <class SinglePassRange, class Pred>
bool all(const SinglePassRange& rng, Pred pred)
{
return all(boost::begin(rng), boost::end(rng), pred);
}

namespace {
const std::vector<std::string> filenames = boost::assign::list_of
("a.txt")
("b.png")
("c_dir")
;

const std::vector<std::string> recursive_filenames = boost::assign::list_of
("a.txt")
("b.png")
("c_dir")
("d.cpp")
;
}

bool exist_check(const boost::filesystem::path& p)
{
return boost::find(filenames, p.filename()) != boost::end(filenames);
}

bool recursive_exist_check(const boost::filesystem::path& p)
{
return boost::find(recursive_filenames, p.filename()) != boost::end(recursive_filenames);
}

int main()
{
const boost::filesystem::path path("./directory_range_test_dir");

BOOST_TEST(all(boost::directory_range(path), exist_check));
BOOST_TEST(all(boost::recursive_directory_range(path), recursive_exist_check));

return boost::report_errors();
}
Empty file.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
49 changes: 49 additions & 0 deletions libs/range/test/iteration.cpp
@@ -0,0 +1,49 @@
// Boost.Range 2.0 Extension library
// via PStade Oven Library
//
// Copyright Akira Takahashi 2011.
// Copyright Shunsuke Sogame 2005-2007.
// Use, modification and distribution is subject to 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)

#include <iostream>
#include <boost/detail/lightweight_test.hpp>

#include <boost/range/iteration.hpp>

#include <vector>
#include <boost/assign/list_of.hpp>
#include <boost/range/adaptor/taken.hpp>
#include <boost/range/adaptor/dropped.hpp>
#include <boost/range/access/front.hpp>
#include <boost/range/algorithm/equal.hpp>

int next(int x)
{
return x * 2;
}

int main()
{
{
const std::vector<int> expected = boost::assign::list_of(1)(2)(4)(8)(16);

BOOST_TEST(boost::equal(
boost::iteration(1, next) | boost::adaptors::taken(5),
expected
));
}
{
const int expected = 4;

BOOST_TEST(
(boost::iteration(1, next) | boost::adaptors::dropped(2) | boost::range::access::front)
== expected
);
}

return boost::report_errors();
}


51 changes: 51 additions & 0 deletions libs/range/test/member_select_example.cpp
@@ -0,0 +1,51 @@
// Boost.Range 2.0 Extension library
// via PStade Oven Library
//
// Copyright Akira Takahashi 2011.
// Copyright Shunsuke Sogame 2005-2007.
// Use, modification and distribution is subject to 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)

#include <iostream>
#include <vector>
#include <string>
#include <boost/assign/list_of.hpp>
#include <boost/range/adaptor/regular_extension/transformed.hpp>
#include <boost/range/algorithm/for_each.hpp>
#include <boost/lambda/lambda.hpp>

struct X {
int a;
std::string s;

X(int a_, const std::string& s_) : a(a_), s(s_) {}
};

struct disper {
template <class T>
void operator()(const T& x) const
{
std::cout << x << std::endl;
}
};

int main()
{
const std::vector<X> v = boost::assign::list_of
(X(1, "a"))
(X(2, "b"))
(X(3, "c"))
;

using boost::lambda::_1;

boost::for_each(v |+ boost::adaptors::transformed(&_1 ->* &X::s), disper());
}

/*
a
b
c
*/
33 changes: 33 additions & 0 deletions libs/range/test/regular.cpp
@@ -0,0 +1,33 @@
// Boost.Range 2.0 Extension library
// via PStade Oven Library
//
// Copyright Akira Takahashi 2011.
// Copyright Shunsuke Sogame 2005-2007.
// Use, modification and distribution is subject to 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)

#include <iostream>
#include <boost/detail/lightweight_test.hpp>

#include <boost/range/regular.hpp>
#include <boost/lambda/lambda.hpp>

template< class F >
void regular_check(F const f)
{
F f1(f);
F f2; // Default Constructible
f2 = f1; // Copy Assignable
}

int main()
{
namespace bll = boost::lambda;
::regular_check(boost::regular(bll::_1 != 'c'));
::regular_check(boost::regular(bll::_1 += 1));

return boost::report_errors();
}


47 changes: 47 additions & 0 deletions libs/range/test/regular_cpp0x_lambda_example.cpp
@@ -0,0 +1,47 @@
// Boost.Range 2.0 Extension library
// via PStade Oven Library
//
// Copyright Akira Takahashi 2011.
// Copyright Shunsuke Sogame 2005-2007.
// Use, modification and distribution is subject to 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)

#define BOOST_RESULT_OF_USE_DECLTYPE
#include <iostream>
#include <vector>
#include <boost/assign/list_of.hpp>
#include <boost/range/adaptor/transformed.hpp>
#include <boost/range/regular.hpp>

template <class InputIterator, class F>
void for_each_(InputIterator first, InputIterator last, F f)
{
InputIterator it; // Default Constructible
it = first; // Copy Assignable
for (; it != last; ++it) {
f(*it);
}
}

template <class SinglePassRange, class F>
void for_each_(const SinglePassRange& rng, F f)
{
return for_each_(boost::begin(rng), boost::end(rng), f);
}

void disp(int x)
{
std::cout << x << ' ';
}

int main()
{
const std::vector<int> v = boost::assign::list_of(1)(2)(3)(4)(5);
for_each_(v | boost::adaptors::transformed(boost::regular([](int x) { return x + 1; })), disp);
}

/*
2 3 4 5 6
*/

3 changes: 2 additions & 1 deletion libs/range/test/regular_operator_example.cpp
Expand Up @@ -10,6 +10,7 @@

#include <iostream>
#include <vector>
#include <boost/assign/list_of.hpp>
#include <boost/range/adaptor/taken_while.hpp>
#include <boost/range/adaptor/dropped_while.hpp>
#include <boost/range/adaptor/regular_extension/filtered.hpp>
Expand Down Expand Up @@ -49,7 +50,7 @@ int main()
using boost::lambda::_1;
using namespace boost::adaptors;

const std::vector<int> v = {1, 2, 3, 4, 5, 6};
const std::vector<int> v = boost::assign::list_of(1)(2)(3)(4)(5)(6);
for_each_(v |+ taken_while(_1 < 3) |+ dropped_while(_1 == 1), disp);

std::cout << std::endl;
Expand Down

0 comments on commit a2c7201

Please sign in to comment.