test_lexicographical_compare.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. //---------------------------------------------------------------------------//
  2. // Copyright (c) 2014 Mageswaran.D <mageswaran1989@gmail.com>
  3. //
  4. // Distributed under the Boost Software License, Version 1.0
  5. // See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt
  7. //
  8. // See http://boostorg.github.com/compute for more information.
  9. //---------------------------------------------------------------------------//
  10. #define BOOST_TEST_MODULE TestLexicographicalCompare
  11. #include <boost/test/unit_test.hpp>
  12. #include <boost/compute/container/string.hpp>
  13. #include <boost/compute/container/basic_string.hpp>
  14. #include <boost/compute/algorithm/lexicographical_compare.hpp>
  15. #include "context_setup.hpp"
  16. #include "check_macros.hpp"
  17. BOOST_AUTO_TEST_CASE(lexicographical_compare_string)
  18. {
  19. boost::compute::string a = "abcdefghijk";
  20. boost::compute::string b = "abcdefghijk";
  21. boost::compute::string c = "abcdefghija";
  22. boost::compute::string d = "zabcdefghij";
  23. BOOST_CHECK(boost::compute::lexicographical_compare(a.begin(),
  24. a.end(),
  25. b.begin(),
  26. b.end()) == false);
  27. BOOST_CHECK(boost::compute::lexicographical_compare(c.begin(),
  28. c.end(),
  29. a.begin(),
  30. a.end()) == true);
  31. BOOST_CHECK(boost::compute::lexicographical_compare(c.begin(),
  32. c.end(),
  33. d.begin(),
  34. d.end()) == true);
  35. }
  36. BOOST_AUTO_TEST_CASE(lexicographical_compare_number)
  37. {
  38. int data1[] = { 1, 2, 3, 4, 5, 6 };
  39. int data2[] = { 9, 2, 3, 4, 5, 6 };
  40. int data3[] = { 1, 2, 3, 4, 5 };
  41. int data4[] = { 9, 2, 3, 4, 5, 100 };
  42. boost::compute::vector<int> vector1(data1, data1 + 6, queue);
  43. boost::compute::vector<int> vector2(data2, data2 + 6, queue);
  44. boost::compute::vector<int> vector3(data3, data3 + 5, queue);
  45. boost::compute::vector<int> vector4(data4, data4 + 6, queue);
  46. BOOST_CHECK(boost::compute::lexicographical_compare(vector1.begin(),
  47. vector1.end(),
  48. vector2.begin(),
  49. vector2.end(),
  50. queue) == true);
  51. BOOST_CHECK(boost::compute::lexicographical_compare(vector1.begin(),
  52. vector1.end(),
  53. vector3.begin(),
  54. vector3.end(),
  55. queue) == false);
  56. BOOST_CHECK(boost::compute::lexicographical_compare(vector3.begin(),
  57. vector3.end(),
  58. vector4.begin(),
  59. vector4.end(),
  60. queue) == true);
  61. }
  62. BOOST_AUTO_TEST_SUITE_END()