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