Skip to content

Commit f28a6b6

Browse files
committed
The great Thrust index type fix, part 2: verify binary searches.
1 parent 500c4e0 commit f28a6b6

1 file changed

Lines changed: 54 additions & 0 deletions

File tree

testing/binary_search.cu

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,3 +291,57 @@ void TestScalarEqualRangeDispatchImplicit()
291291
DECLARE_UNITTEST(TestScalarEqualRangeDispatchImplicit);
292292

293293
THRUST_DISABLE_MSVC_POSSIBLE_LOSS_OF_DATA_WARNING_END
294+
295+
void TestBoundsWithBigIndexesHelper(int magnitude)
296+
{
297+
thrust::counting_iterator<long long> begin(1);
298+
thrust::counting_iterator<long long> end = begin + (1ll << magnitude);
299+
ASSERT_EQUAL(thrust::distance(begin, end), 1ll << magnitude);
300+
301+
thrust::detail::intmax_t distance_low_value = thrust::distance(
302+
begin,
303+
thrust::lower_bound(
304+
thrust::device,
305+
begin,
306+
end,
307+
17));
308+
309+
thrust::detail::intmax_t distance_high_value = thrust::distance(
310+
begin,
311+
thrust::lower_bound(
312+
thrust::device,
313+
begin,
314+
end,
315+
(1ll << magnitude) - 17));
316+
317+
ASSERT_EQUAL(distance_low_value, 16);
318+
ASSERT_EQUAL(distance_high_value, (1ll << magnitude) - 18);
319+
320+
distance_low_value = thrust::distance(
321+
begin,
322+
thrust::upper_bound(
323+
thrust::device,
324+
begin,
325+
end,
326+
17));
327+
328+
distance_high_value = thrust::distance(
329+
begin,
330+
thrust::upper_bound(
331+
thrust::device,
332+
begin,
333+
end,
334+
(1ll << magnitude) - 17));
335+
336+
ASSERT_EQUAL(distance_low_value, 17);
337+
ASSERT_EQUAL(distance_high_value, (1ll << magnitude) - 17);
338+
}
339+
340+
void TestBoundsWithBigIndexes()
341+
{
342+
TestBoundsWithBigIndexesHelper(30);
343+
TestBoundsWithBigIndexesHelper(31);
344+
TestBoundsWithBigIndexesHelper(32);
345+
TestBoundsWithBigIndexesHelper(33);
346+
}
347+
DECLARE_UNITTEST(TestBoundsWithBigIndexes);

0 commit comments

Comments
 (0)