[compute] 43/49: Fix test for binary_search, lower_bound and upper_bound
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Fri Dec 18 17:58:21 UTC 2015
This is an automated email from the git hooks/post-receive script.
ghisvail-guest pushed a commit to branch master
in repository compute.
commit ff51c44434741b01c836aa1b797baf7d63e9b3c2
Author: Jakub Szuppe <j.szuppe at gmail.com>
Date: Sat Sep 19 17:53:08 2015 +0200
Fix test for binary_search, lower_bound and upper_bound
Previous test data was too small to properly test binary_find which
is used in binary_search, lower_bound and upper_bound algorithms.
---
test/test_binary_search.cpp | 65 ++++++++++++++++++++++++++++++++++-----------
1 file changed, 50 insertions(+), 15 deletions(-)
diff --git a/test/test_binary_search.cpp b/test/test_binary_search.cpp
index f8fd71c..43e4fcf 100644
--- a/test/test_binary_search.cpp
+++ b/test/test_binary_search.cpp
@@ -15,6 +15,7 @@
#include <boost/compute/command_queue.hpp>
#include <boost/compute/algorithm/binary_search.hpp>
+#include <boost/compute/algorithm/fill.hpp>
#include <boost/compute/algorithm/lower_bound.hpp>
#include <boost/compute/algorithm/upper_bound.hpp>
#include <boost/compute/container/vector.hpp>
@@ -23,8 +24,22 @@
BOOST_AUTO_TEST_CASE(binary_search_int)
{
- int data[] = { 1, 2, 2, 2, 4, 4, 5, 7 };
- boost::compute::vector<int> vector(data, data + 8, queue);
+ // test data = { 1, ..., 2, ..., 4, 4, 5, 7, ..., 9, ..., 10 }
+ boost::compute::vector<int> vector(size_t(4096), int(1), queue);
+ boost::compute::vector<int>::iterator first = vector.begin() + 128;
+ boost::compute::vector<int>::iterator last = first + (1024 - 128);
+ boost::compute::fill(first, last, int(2), queue);
+ last.write(4, queue); last++;
+ last.write(4, queue); last++;
+ last.write(5, queue); last++;
+ first = last;
+ last = first + 127;
+ boost::compute::fill(first, last, 7, queue);
+ first = last;
+ last = vector.end() - 1;
+ boost::compute::fill(first, last, 9, queue);
+ last.write(10, queue);
+ queue.finish();
BOOST_CHECK(boost::compute::binary_search(vector.begin(), vector.end(), int(0), queue) == false);
BOOST_CHECK(boost::compute::binary_search(vector.begin(), vector.end(), int(1), queue) == true);
@@ -39,29 +54,49 @@ BOOST_AUTO_TEST_CASE(binary_search_int)
BOOST_AUTO_TEST_CASE(range_bounds_int)
{
- int data[] = { 1, 2, 2, 2, 3, 3, 4, 5 };
- boost::compute::vector<int> vector(data, data + 8, queue);
+ // test data = { 1, ..., 2, ..., 4, 4, 5, 7, ..., 9, ..., 10 }
+ boost::compute::vector<int> vector(size_t(4096), int(1), queue);
+ boost::compute::vector<int>::iterator first = vector.begin() + 128;
+ boost::compute::vector<int>::iterator last = first + (1024 - 128);
+ boost::compute::fill(first, last, int(2), queue);
+ last.write(4, queue); last++; // 1024
+ last.write(4, queue); last++; // 1025
+ last.write(5, queue); last++; // 1026
+ first = last;
+ last = first + 127;
+ boost::compute::fill(first, last, 7, queue);
+ first = last;
+ last = vector.end() - 1;
+ boost::compute::fill(first, last, 9, queue);
+ last.write(10, queue);
+ queue.finish();
BOOST_CHECK(boost::compute::lower_bound(vector.begin(), vector.end(), int(0), queue) == vector.begin());
BOOST_CHECK(boost::compute::upper_bound(vector.begin(), vector.end(), int(0), queue) == vector.begin());
BOOST_CHECK(boost::compute::lower_bound(vector.begin(), vector.end(), int(1), queue) == vector.begin());
- BOOST_CHECK(boost::compute::upper_bound(vector.begin(), vector.end(), int(1), queue) == vector.begin() + 1);
+ BOOST_CHECK(boost::compute::upper_bound(vector.begin(), vector.end(), int(1), queue) == vector.begin() + 128);
- BOOST_CHECK(boost::compute::lower_bound(vector.begin(), vector.end(), int(2), queue) == vector.begin() + 1);
- BOOST_CHECK(boost::compute::upper_bound(vector.begin(), vector.end(), int(2), queue) == vector.begin() + 4);
+ BOOST_CHECK(boost::compute::lower_bound(vector.begin(), vector.end(), int(2), queue) == vector.begin() + 128);
+ BOOST_CHECK(boost::compute::upper_bound(vector.begin(), vector.end(), int(2), queue) == vector.begin() + 1024);
- BOOST_CHECK(boost::compute::lower_bound(vector.begin(), vector.end(), int(3), queue) == vector.begin() + 4);
- BOOST_CHECK(boost::compute::upper_bound(vector.begin(), vector.end(), int(3), queue) == vector.begin() + 6);
+ BOOST_CHECK(boost::compute::lower_bound(vector.begin(), vector.end(), int(4), queue) == vector.begin() + 1024);
+ BOOST_CHECK(boost::compute::upper_bound(vector.begin(), vector.end(), int(4), queue) == vector.begin() + 1026);
- BOOST_CHECK(boost::compute::lower_bound(vector.begin(), vector.end(), int(4), queue) == vector.begin() + 6);
- BOOST_CHECK(boost::compute::upper_bound(vector.begin(), vector.end(), int(4), queue) == vector.begin() + 7);
+ BOOST_CHECK(boost::compute::lower_bound(vector.begin(), vector.end(), int(5), queue) == vector.begin() + 1026);
+ BOOST_CHECK(boost::compute::upper_bound(vector.begin(), vector.end(), int(5), queue) == vector.begin() + 1027);
- BOOST_CHECK(boost::compute::lower_bound(vector.begin(), vector.end(), int(5), queue) == vector.begin() + 7);
- BOOST_CHECK(boost::compute::upper_bound(vector.begin(), vector.end(), int(5), queue) == vector.end());
+ BOOST_CHECK(boost::compute::lower_bound(vector.begin(), vector.end(), int(6), queue) == vector.begin() + 1027);
+ BOOST_CHECK(boost::compute::upper_bound(vector.begin(), vector.end(), int(6), queue) == vector.begin() + 1027);
- BOOST_CHECK(boost::compute::lower_bound(vector.begin(), vector.end(), int(6), queue) == vector.end());
- BOOST_CHECK(boost::compute::upper_bound(vector.begin(), vector.end(), int(6), queue) == vector.end());
+ BOOST_CHECK(boost::compute::lower_bound(vector.begin(), vector.end(), int(7), queue) == vector.begin() + 1027);
+ BOOST_CHECK(boost::compute::upper_bound(vector.begin(), vector.end(), int(7), queue) == vector.begin() + (1027 + 127));
+
+ BOOST_CHECK(boost::compute::lower_bound(vector.begin(), vector.end(), int(9), queue) == vector.begin() + (1027 + 127));
+ BOOST_CHECK(boost::compute::upper_bound(vector.begin(), vector.end(), int(9), queue) == vector.end() - 1);
+
+ BOOST_CHECK(boost::compute::lower_bound(vector.begin(), vector.end(), int(10), queue) == vector.end() - 1);
+ BOOST_CHECK(boost::compute::upper_bound(vector.begin(), vector.end(), int(10), queue) == vector.end());
}
BOOST_AUTO_TEST_SUITE_END()
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/compute.git
More information about the debian-science-commits
mailing list