PageRenderTime 39ms CodeModel.GetById 15ms app.highlight 20ms RepoModel.GetById 2ms app.codeStats 0ms

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

http://hadesmem.googlecode.com/
C++ | 186 lines | 160 code | 19 blank | 7 comment | 11 complexity | 93088fd96e8121c4ce840f927617091a 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/transformation.hpp>
 11#include <boost/detail/lightweight_test.hpp>
 12
 13#include <list>
 14
 15namespace
 16{
 17    void nth_element_test()
 18    {
 19        using boost::phoenix::nth_element;
 20        using boost::phoenix::arg_names::arg1;
 21        int array[] = {5,1,4,3,2};
 22        nth_element(arg1, array + 2)(array);
 23        BOOST_TEST(array[0] < 3);
 24        BOOST_TEST(array[1] < 3);
 25        BOOST_TEST(array[2] == 3);
 26        BOOST_TEST(array[3] > 3);
 27        BOOST_TEST(array[4] > 3);
 28
 29        boost::phoenix::nth_element(arg1, array + 2, std::greater<int>())(array);
 30        BOOST_TEST(array[0] > 3);
 31        BOOST_TEST(array[1] > 3);
 32        BOOST_TEST(array[2] == 3);
 33        BOOST_TEST(array[3] < 3);
 34        BOOST_TEST(array[4] < 3);
 35
 36        return;
 37    }
 38
 39    void merge_test()
 40    {
 41        using boost::phoenix::merge;
 42        using boost::phoenix::arg_names::arg1;
 43        using boost::phoenix::arg_names::arg2;
 44        using boost::phoenix::arg_names::arg3;
 45        int array[] = {1,2,3};
 46        int array2[] = {2,3,4};
 47        int output[6];
 48
 49        BOOST_TEST(merge(arg1, arg2, arg3)(array, array2, output) == output + 6);
 50        int expected_result[] = {1,2,2,3,3,4};
 51        BOOST_TEST(std::equal(output, output + 6, expected_result));
 52
 53        int array3[] = {5,4,3};
 54        int array4[] = {3,2,1};
 55        int output2[6];
 56        BOOST_TEST(boost::phoenix::merge(arg1, arg2, arg3, std::greater<int>())(array3, array4, output2) ==
 57                   output2 + 6);
 58        int expected_result2[] = {5,4,3,3,2,1};
 59        BOOST_TEST(std::equal(output2, output2 + 6, expected_result2));
 60        return;
 61    }
 62
 63    void inplace_merge_test()
 64    {
 65        using boost::phoenix::inplace_merge;
 66        using boost::phoenix::arg_names::arg1;
 67        int array[] = {1,2,3,2,3,4};
 68        inplace_merge(arg1, array + 3)(array);
 69        int expected_result[] = {1,2,2,3,3,4};
 70        BOOST_TEST(std::equal(array, array + 6, expected_result));
 71
 72        int array2[] = {5,4,3,4,3,2};
 73        boost::phoenix::inplace_merge(arg1, array2 + 3, std::greater<int>())(array2);
 74        int expected_result2[] = {5,4,4,3,3,2};
 75        BOOST_TEST(std::equal(array2, array2 + 6, expected_result2));
 76        return;
 77    }
 78
 79    void set_union_test()
 80    {
 81        using boost::phoenix::set_union;
 82        using boost::phoenix::arg_names::arg1;
 83        using boost::phoenix::arg_names::arg2;
 84        using boost::phoenix::arg_names::arg3;
 85        int array[] = {1,2,3};
 86        int array2[] = {2,3,4};
 87        int output[4];
 88        BOOST_TEST(set_union(arg1, arg2, arg3)(array, array2, output) == output + 4);
 89        int expected_result[] = {1,2,3,4};
 90        BOOST_TEST(std::equal(output, output + 4, expected_result));
 91
 92        int array3[] = {3,2,1};
 93        int array4[] = {4,3,2};
 94        int output2[4];
 95        BOOST_TEST(boost::phoenix::set_union(arg1, arg2, arg3, std::greater<int>())
 96                   (array3, array4, output2) == 
 97                   output2 + 4);
 98        int expected_result2[] = {4,3,2,1};
 99        BOOST_TEST(std::equal(output2, output2 + 4, expected_result2));
100        return;
101    }
102
103    void set_intersection_test()
104    {
105        using boost::phoenix::set_intersection;
106        using boost::phoenix::arg_names::arg1;
107        using boost::phoenix::arg_names::arg2;
108        using boost::phoenix::arg_names::arg3;
109        int array[] = {1,2,3};
110        int array2[] = {2,3,4};
111        int output[2];
112        BOOST_TEST(set_intersection(arg1, arg2, arg3)(array, array2, output) == output + 2);
113        int expected_result[] = {2,3};
114        BOOST_TEST(std::equal(output, output + 2, expected_result));
115
116        int array3[] = {3,2,1};
117        int array4[] = {4,3,2};
118        int output2[2];
119        BOOST_TEST(boost::phoenix::set_intersection(arg1, arg2, arg3, std::greater<int>())
120                   (array3, array4, output2) == 
121                   output2 + 2);
122        int expected_result2[] = {3,2};
123        BOOST_TEST(std::equal(output2, output2 + 2, expected_result2));
124        return;
125    }
126
127    void set_difference_test()
128    {
129        using boost::phoenix::set_difference;
130        using boost::phoenix::arg_names::arg1;
131        using boost::phoenix::arg_names::arg2;
132        using boost::phoenix::arg_names::arg3;
133        int array[] = {1,2,3};
134        int array2[] = {2,3,4};
135        int output[1];
136        BOOST_TEST(set_difference(arg1, arg2, arg3)(array, array2, output) == output + 1);
137        int expected_result[] = {1};
138        BOOST_TEST(std::equal(output, output + 1, expected_result));
139
140        int array3[] = {3,2,1};
141        int array4[] = {4,3,2};
142        int output2[1];
143        BOOST_TEST(boost::phoenix::set_difference(arg1, arg2, arg3, std::greater<int>())
144                   (array3, array4, output2) == 
145                   output2 + 1);
146        int expected_result2[] = {1};
147        BOOST_TEST(std::equal(output2, output2 + 1, expected_result2));
148        return;
149    }
150
151    void set_symmetric_difference_test()
152    {
153        using boost::phoenix::set_symmetric_difference;
154        using boost::phoenix::arg_names::arg1;
155        using boost::phoenix::arg_names::arg2;
156        using boost::phoenix::arg_names::arg3;
157        int array[] = {1,2,3};
158        int array2[] = {2,3,4};
159        int output[2];
160        BOOST_TEST(set_symmetric_difference(arg1, arg2, arg3)(array, array2, output) == output + 2);
161        int expected_result[] = {1,4};
162        BOOST_TEST(std::equal(output, output + 2, expected_result));
163
164        int array3[] = {3,2,1};
165        int array4[] = {4,3,2};
166        int output2[2];
167        BOOST_TEST(boost::phoenix::set_symmetric_difference(arg1, arg2, arg3, std::greater<int>())
168                   (array3, array4, output2) == 
169                   output2 + 2);
170        int expected_result2[] = {4,1};
171        BOOST_TEST(std::equal(output2, output2 + 2, expected_result2));
172        return;
173    }
174}
175
176int main()
177{
178    nth_element_test();
179    merge_test();
180    inplace_merge_test();
181    set_union_test();
182    set_intersection_test();
183    set_difference_test();
184    set_symmetric_difference_test();
185    return boost::report_errors();
186}