1/*
2 Copyright (c) Marshall Clow 2010-2012.
3
4 Distributed under the Boost Software License, Version 1.0. (See accompanying
5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6
7 For more information, see http://www.boost.org
8*/
9
10#include <boost/config.hpp>
11#include <boost/algorithm/cxx11/none_of.hpp>
12
13#define BOOST_TEST_MAIN
14#include <boost/test/unit_test.hpp>
15
16#include <functional>
17#include <vector>
18#include <list>
19
20template<typename T>
21struct is_ : public std::unary_function<T, bool> {
22 is_ ( T v ) : val_ ( v ) {}
23 ~is_ () {}
24 bool operator () ( T comp ) const { return val_ == comp; }
25private:
26 is_ (); // need a value
27
28 T val_;
29 };
30
31namespace ba = boost::algorithm;
32
33void test_none()
34{
35// Note: The literal values here are tested against directly, careful if you change them:
36 int some_numbers[] = { 1, 5, 0, 18, 1 };
37 std::vector<int> vi(some_numbers, some_numbers + 5);
38 std::list<int> li(vi.begin(), vi.end ());
39
40 int some_letters[] = { 'a', 'q', 'n', 'y', 'n' };
41 std::vector<char> vc(some_letters, some_letters + 5);
42
43 BOOST_CHECK ( ba::none_of_equal ( vi, 100 ));
44 BOOST_CHECK ( ba::none_of ( vi, is_<int> ( 100 )));
45 BOOST_CHECK ( ba::none_of_equal ( vi.begin(), vi.end(), 100 ));
46 BOOST_CHECK ( ba::none_of ( vi.begin(), vi.end(), is_<int> ( 100 )));
47
48 BOOST_CHECK (!ba::none_of_equal ( vi, 1 ));
49 BOOST_CHECK (!ba::none_of ( vi, is_<int> ( 1 )));
50 BOOST_CHECK (!ba::none_of_equal ( vi.begin(), vi.end(), 1 ));
51 BOOST_CHECK (!ba::none_of ( vi.begin(), vi.end(), is_<int> ( 1 )));
52
53 BOOST_CHECK ( ba::none_of_equal ( vi.end(), vi.end(), 0 ));
54 BOOST_CHECK ( ba::none_of ( vi.end(), vi.end(), is_<int> ( 0 )));
55
56// 5 is not in { 0, 18, 1 }, but 1 is
57 BOOST_CHECK ( ba::none_of_equal ( vi.begin() + 2, vi.end(), 5 ));
58 BOOST_CHECK ( ba::none_of ( vi.begin() + 2, vi.end(), is_<int> ( 5 )));
59 BOOST_CHECK (!ba::none_of_equal ( vi.begin() + 2, vi.end(), 1 ));
60 BOOST_CHECK (!ba::none_of ( vi.begin() + 2, vi.end(), is_<int> ( 1 )));
61
62// 18 is not in { 1, 5, 0 }, but 5 is
63 BOOST_CHECK ( ba::none_of_equal ( vi.begin(), vi.begin() + 3, 18 ));
64 BOOST_CHECK ( ba::none_of ( vi.begin(), vi.begin() + 3, is_<int> ( 18 )));
65 BOOST_CHECK (!ba::none_of_equal ( vi.begin(), vi.begin() + 3, 5 ));
66 BOOST_CHECK (!ba::none_of ( vi.begin(), vi.begin() + 3, is_<int> ( 5 )));
67
68 BOOST_CHECK ( ba::none_of_equal ( vc, 'z' ));
69 BOOST_CHECK ( ba::none_of ( vc, is_<char> ( 'z' )));
70
71 BOOST_CHECK (!ba::none_of_equal ( vc, 'a' ));
72 BOOST_CHECK (!ba::none_of ( vc, is_<char> ( 'a' )));
73
74 BOOST_CHECK (!ba::none_of_equal ( vc, 'n' ));
75 BOOST_CHECK (!ba::none_of ( vc, is_<char> ( 'n' )));
76
77 BOOST_CHECK ( ba::none_of_equal ( vi.begin(), vi.begin(), 1 ));
78 BOOST_CHECK ( ba::none_of_equal ( vc.begin(), vc.begin(), 'a' ));
79 BOOST_CHECK ( ba::none_of ( vi.begin(), vi.begin(), is_<int> ( 1 )));
80 BOOST_CHECK ( ba::none_of ( vc.begin(), vc.begin(), is_<char> ( 'a' )));
81
82 BOOST_CHECK ( ba::none_of_equal ( li, 100 ));
83 BOOST_CHECK ( ba::none_of ( li, is_<int> ( 100 )));
84 BOOST_CHECK ( ba::none_of_equal ( li.begin(), li.end(), 100 ));
85 BOOST_CHECK ( ba::none_of ( li.begin(), li.end(), is_<int> ( 100 )));
86
87 std::list<int>::iterator l_iter = li.begin ();
88 l_iter++; l_iter++; l_iter++;
89 BOOST_CHECK ( ba::none_of_equal ( li.begin(), l_iter, 18 ));
90 BOOST_CHECK ( ba::none_of ( li.begin(), l_iter, is_<int> ( 18 )));
91 BOOST_CHECK (!ba::none_of ( li.begin(), l_iter, is_<int> ( 5 )));
92}
93
94BOOST_AUTO_TEST_CASE( test_main )
95{
96 test_none();
97}
98