PageRenderTime 80ms CodeModel.GetById 64ms app.highlight 13ms RepoModel.GetById 1ms app.codeStats 0ms

/Src/Dependencies/Boost/libs/phoenix/test/algorithm/querying2.cpp

http://hadesmem.googlecode.com/
C++ | 85 lines | 66 code | 12 blank | 7 comment | 4 complexity | 4bde1d9fa8da641ff363fced0b931a62 MD5 | raw file
 1/*=============================================================================
 2    Copyright (c) 2005-2007 Dan Marsden
 3    Copyright (c) 2005-2007 Joel de Guzman
 4
 5    Distributed under the Boost Software License, Version 1.0. (See accompanying 
 6    file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 7==============================================================================*/
 8
 9#include <boost/phoenix/core.hpp>
10#include <boost/phoenix/stl/algorithm/querying.hpp>
11#include <boost/detail/lightweight_test.hpp>
12
13#include <boost/range.hpp>
14
15#include <functional>
16
17namespace
18{
19    void includes_test()
20    {
21        using boost::phoenix::includes;
22        using boost::phoenix::arg_names::arg1;
23        using boost::phoenix::arg_names::arg2;
24        int array[] = {1,2,3};
25        int array2[] = {1,2};
26        BOOST_TEST(includes(arg1, arg2)(array, array2));
27        boost::iterator_range<int*> rng(array + 1, array + 3);
28        BOOST_TEST(!includes(arg1, arg2)(rng, array2));
29
30        int array3[] = {3,2,1};
31        int array4[] = {2,1};
32        BOOST_TEST(boost::phoenix::includes(arg1, arg2, std::greater<int>())(array3, array4));
33        boost::iterator_range<int*> rng2(array3, array3 + 2);
34        BOOST_TEST(!boost::phoenix::includes(arg1, arg2, std::greater<int>())(rng2, array4));
35        return;
36    }
37
38    void min_element_test()
39    {
40        using boost::phoenix::min_element;
41        using boost::phoenix::arg_names::arg1;
42        int array[] = {1,3,2};
43        BOOST_TEST(min_element(arg1)(array) == array);
44        BOOST_TEST(boost::phoenix::min_element(arg1, std::greater<int>())(array) == array + 1);
45        return;
46    }
47
48    void max_element_test()
49    {
50        using boost::phoenix::max_element;
51        using boost::phoenix::arg_names::arg1;
52        int array[] = {1,3,2};
53        BOOST_TEST(max_element(arg1)(array) == array + 1);
54        BOOST_TEST(boost::phoenix::max_element(arg1, std::greater<int>())(array) == array);
55        return;
56    }
57
58    void lexicographical_compare_test()
59    {
60        using boost::phoenix::lexicographical_compare;
61        using boost::phoenix::arg_names::arg1;
62        using boost::phoenix::arg_names::arg2;
63        int array[] = {1,2,3};
64        int array2[] = {1,2,4};
65
66        BOOST_TEST(lexicographical_compare(arg1, arg2)(array, array2));
67        BOOST_TEST(!lexicographical_compare(arg1, arg2)(array2, array));
68        BOOST_TEST(!lexicographical_compare(arg1, arg2)(array, array));
69
70        BOOST_TEST(!boost::phoenix::lexicographical_compare(arg1, arg2, std::greater<int>())(array, array2));
71        BOOST_TEST(boost::phoenix::lexicographical_compare(arg1, arg2, std::greater<int>())(array2, array));
72        BOOST_TEST(!boost::phoenix::lexicographical_compare(arg1, arg2, std::greater<int>())(array, array));
73
74        return;
75    }
76}
77
78int main()
79{
80    includes_test();
81    min_element_test();
82    max_element_test();
83    lexicographical_compare_test();
84    return boost::report_errors();
85}