test_equal.cpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. //---------------------------------------------------------------------------//
  2. // Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@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 TestEqual
  11. #include <boost/test/unit_test.hpp>
  12. #include <boost/compute/algorithm/equal.hpp>
  13. #include <boost/compute/algorithm/fill.hpp>
  14. #include <boost/compute/container/string.hpp>
  15. #include <boost/compute/container/vector.hpp>
  16. #include "context_setup.hpp"
  17. BOOST_AUTO_TEST_CASE(equal_int)
  18. {
  19. int data1[] = { 1, 2, 3, 4, 5, 6 };
  20. int data2[] = { 1, 2, 3, 7, 5, 6 };
  21. boost::compute::vector<int> vector1(data1, data1 + 6, queue);
  22. boost::compute::vector<int> vector2(data2, data2 + 6, queue);
  23. BOOST_CHECK(boost::compute::equal(vector1.begin(), vector1.end(),
  24. vector2.begin(), queue) == false);
  25. BOOST_CHECK(boost::compute::equal(vector1.begin(), vector1.begin() + 2,
  26. vector2.begin(), queue) == true);
  27. BOOST_CHECK(boost::compute::equal(vector1.begin() + 4, vector1.end(),
  28. vector2.begin() + 4, queue) == true);
  29. }
  30. BOOST_AUTO_TEST_CASE(equal_string)
  31. {
  32. boost::compute::string a = "abcdefghijk";
  33. boost::compute::string b = "abcdefghijk";
  34. boost::compute::string c = "abcdezghijk";
  35. BOOST_CHECK(boost::compute::equal(a.begin(), a.end(), b.begin(), queue) == true);
  36. BOOST_CHECK(boost::compute::equal(a.begin(), a.end(), c.begin(), queue) == false);
  37. }
  38. BOOST_AUTO_TEST_CASE(equal_different_range_sizes)
  39. {
  40. boost::compute::vector<int> a(10, context);
  41. boost::compute::vector<int> b(20, context);
  42. boost::compute::fill(a.begin(), a.end(), 3, queue);
  43. boost::compute::fill(b.begin(), b.end(), 3, queue);
  44. BOOST_CHECK(boost::compute::equal(a.begin(), a.end(), b.begin(), b.end(), queue) == false);
  45. BOOST_CHECK(boost::compute::equal(a.begin(), a.end(), a.begin(), a.end(), queue) == true);
  46. BOOST_CHECK(boost::compute::equal(b.begin(), b.end(), a.begin(), a.end(), queue) == false);
  47. BOOST_CHECK(boost::compute::equal(b.begin(), b.end(), b.begin(), b.end(), queue) == true);
  48. }
  49. BOOST_AUTO_TEST_SUITE_END()