test_mismatch.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 TestMismatch
  11. #include <boost/test/unit_test.hpp>
  12. #include <boost/compute/algorithm/fill.hpp>
  13. #include <boost/compute/algorithm/mismatch.hpp>
  14. #include <boost/compute/container/vector.hpp>
  15. #include "context_setup.hpp"
  16. BOOST_AUTO_TEST_CASE(mismatch_int)
  17. {
  18. int data1[] = { 1, 2, 3, 4, 5, 6 };
  19. int data2[] = { 1, 2, 3, 7, 5, 6 };
  20. boost::compute::vector<int> vector1(data1, data1 + 6, queue);
  21. boost::compute::vector<int> vector2(data2, data2 + 6, queue);
  22. typedef boost::compute::vector<int>::iterator iter;
  23. std::pair<iter, iter> location =
  24. boost::compute::mismatch(vector1.begin(), vector1.end(),
  25. vector2.begin(), queue);
  26. BOOST_CHECK(location.first == vector1.begin() + 3);
  27. BOOST_CHECK_EQUAL(int(*location.first), int(4));
  28. BOOST_CHECK(location.second == vector2.begin() + 3);
  29. BOOST_CHECK_EQUAL(int(*location.second), int(7));
  30. }
  31. BOOST_AUTO_TEST_CASE(mismatch_different_range_sizes)
  32. {
  33. boost::compute::vector<int> a(10, context);
  34. boost::compute::vector<int> b(20, context);
  35. boost::compute::fill(a.begin(), a.end(), 3, queue);
  36. boost::compute::fill(b.begin(), b.end(), 3, queue);
  37. typedef boost::compute::vector<int>::iterator iter;
  38. std::pair<iter, iter> location;
  39. location = boost::compute::mismatch(
  40. a.begin(), a.end(), b.begin(), b.end(), queue
  41. );
  42. BOOST_CHECK(location.first == a.end());
  43. BOOST_CHECK(location.second == b.begin() + 10);
  44. location = boost::compute::mismatch(
  45. b.begin(), b.end(), a.begin(), a.end(), queue
  46. );
  47. BOOST_CHECK(location.first == b.begin() + 10);
  48. BOOST_CHECK(location.second == a.end());
  49. }
  50. BOOST_AUTO_TEST_SUITE_END()