From b4ab488900a35ade039c842f8a77c7fade02a2e1 Mon Sep 17 00:00:00 2001 From: gonidelis Date: Mon, 9 Sep 2024 14:02:42 -0700 Subject: [PATCH] More tests with less lines --- thrust/testing/adjacent_difference.cu | 25 +-- thrust/testing/binary_search.cu | 32 +--- thrust/testing/binary_search_descending.cu | 32 +--- thrust/testing/binary_search_vector.cu | 72 ++------- .../binary_search_vector_descending.cu | 73 ++------- thrust/testing/constant_iterator.cu | 18 +-- thrust/testing/copy.cu | 148 +++++------------- thrust/testing/copy_n.cu | 125 ++++----------- thrust/testing/count.cu | 21 +-- thrust/testing/cuda/swap_ranges.cu | 4 +- thrust/testing/dereference.cu | 14 +- thrust/testing/equal.cu | 9 +- thrust/testing/fill.cu | 115 +++++--------- thrust/testing/find.cu | 21 +-- 14 files changed, 168 insertions(+), 541 deletions(-) diff --git a/thrust/testing/adjacent_difference.cu b/thrust/testing/adjacent_difference.cu index 7b4473b143..ea40c8cc2d 100644 --- a/thrust/testing/adjacent_difference.cu +++ b/thrust/testing/adjacent_difference.cu @@ -11,39 +11,28 @@ void TestAdjacentDifferenceSimple() { using T = typename Vector::value_type; - Vector input(4); + Vector input{1, 4, 6, 7}; Vector output(4); - input[0] = 1; - input[1] = 4; - input[2] = 6; - input[3] = 7; - typename Vector::iterator result; result = thrust::adjacent_difference(input.begin(), input.end(), output.begin()); ASSERT_EQUAL(result - output.begin(), 4); - ASSERT_EQUAL(output[0], T(1)); - ASSERT_EQUAL(output[1], T(3)); - ASSERT_EQUAL(output[2], T(2)); - ASSERT_EQUAL(output[3], T(1)); + Vector ref{1, 3, 2, 1}; + ASSERT_EQUAL(output, ref); result = thrust::adjacent_difference(input.begin(), input.end(), output.begin(), thrust::plus()); ASSERT_EQUAL(result - output.begin(), 4); - ASSERT_EQUAL(output[0], T(1)); - ASSERT_EQUAL(output[1], T(5)); - ASSERT_EQUAL(output[2], T(10)); - ASSERT_EQUAL(output[3], T(13)); + ref = {1, 5, 10, 13}; + ASSERT_EQUAL(output, ref); // test in-place operation, result and first are permitted to be the same result = thrust::adjacent_difference(input.begin(), input.end(), input.begin()); ASSERT_EQUAL(result - input.begin(), 4); - ASSERT_EQUAL(input[0], T(1)); - ASSERT_EQUAL(input[1], T(3)); - ASSERT_EQUAL(input[2], T(2)); - ASSERT_EQUAL(input[3], T(1)); + ref = {1, 3, 2, 1}; + ASSERT_EQUAL(input, ref); } DECLARE_VECTOR_UNITTEST(TestAdjacentDifferenceSimple); diff --git a/thrust/testing/binary_search.cu b/thrust/testing/binary_search.cu index e27d5a0c98..46979c2c42 100644 --- a/thrust/testing/binary_search.cu +++ b/thrust/testing/binary_search.cu @@ -14,13 +14,7 @@ THRUST_DISABLE_MSVC_POSSIBLE_LOSS_OF_DATA_WARNING_BEGIN template void TestScalarLowerBoundSimple() { - Vector vec(5); - - vec[0] = 0; - vec[1] = 2; - vec[2] = 5; - vec[3] = 7; - vec[4] = 8; + Vector vec{0, 2, 5, 7, 8}; ASSERT_EQUAL(thrust::lower_bound(vec.begin(), vec.end(), 0) - vec.begin(), 0); ASSERT_EQUAL(thrust::lower_bound(vec.begin(), vec.end(), 1) - vec.begin(), 1); @@ -74,13 +68,7 @@ DECLARE_UNITTEST(TestScalarLowerBoundDispatchImplicit); template void TestScalarUpperBoundSimple() { - Vector vec(5); - - vec[0] = 0; - vec[1] = 2; - vec[2] = 5; - vec[3] = 7; - vec[4] = 8; + Vector vec{0, 2, 5, 7, 8}; ASSERT_EQUAL(thrust::upper_bound(vec.begin(), vec.end(), 0) - vec.begin(), 1); ASSERT_EQUAL(thrust::upper_bound(vec.begin(), vec.end(), 1) - vec.begin(), 1); @@ -134,13 +122,7 @@ DECLARE_UNITTEST(TestScalarUpperBoundDispatchImplicit); template void TestScalarBinarySearchSimple() { - Vector vec(5); - - vec[0] = 0; - vec[1] = 2; - vec[2] = 5; - vec[3] = 7; - vec[4] = 8; + Vector vec{0, 2, 5, 7, 8}; ASSERT_EQUAL(thrust::binary_search(vec.begin(), vec.end(), 0), true); ASSERT_EQUAL(thrust::binary_search(vec.begin(), vec.end(), 1), false); @@ -194,13 +176,7 @@ DECLARE_UNITTEST(TestScalarBinarySearchDispatchImplicit); template void TestScalarEqualRangeSimple() { - Vector vec(5); - - vec[0] = 0; - vec[1] = 2; - vec[2] = 5; - vec[3] = 7; - vec[4] = 8; + Vector vec{0, 2, 5, 7, 8}; ASSERT_EQUAL(thrust::equal_range(vec.begin(), vec.end(), 0).first - vec.begin(), 0); ASSERT_EQUAL(thrust::equal_range(vec.begin(), vec.end(), 1).first - vec.begin(), 1); diff --git a/thrust/testing/binary_search_descending.cu b/thrust/testing/binary_search_descending.cu index 2677c82e74..7d842a456f 100644 --- a/thrust/testing/binary_search_descending.cu +++ b/thrust/testing/binary_search_descending.cu @@ -14,13 +14,7 @@ void TestScalarLowerBoundDescendingSimple() { using T = typename Vector::value_type; - Vector vec(5); - - vec[0] = 8; - vec[1] = 7; - vec[2] = 5; - vec[3] = 2; - vec[4] = 0; + Vector vec{8, 7, 5, 2, 0}; ASSERT_EQUAL_QUIET(vec.begin() + 4, thrust::lower_bound(vec.begin(), vec.end(), T{0}, thrust::greater())); ASSERT_EQUAL_QUIET(vec.begin() + 4, thrust::lower_bound(vec.begin(), vec.end(), T{1}, thrust::greater())); @@ -40,13 +34,7 @@ void TestScalarUpperBoundDescendingSimple() { using T = typename Vector::value_type; - Vector vec(5); - - vec[0] = 8; - vec[1] = 7; - vec[2] = 5; - vec[3] = 2; - vec[4] = 0; + Vector vec{8, 7, 5, 2, 0}; ASSERT_EQUAL_QUIET(vec.begin() + 5, thrust::upper_bound(vec.begin(), vec.end(), T{0}, thrust::greater())); ASSERT_EQUAL_QUIET(vec.begin() + 4, thrust::upper_bound(vec.begin(), vec.end(), T{1}, thrust::greater())); @@ -66,13 +54,7 @@ void TestScalarBinarySearchDescendingSimple() { using T = typename Vector::value_type; - Vector vec(5); - - vec[0] = 8; - vec[1] = 7; - vec[2] = 5; - vec[3] = 2; - vec[4] = 0; + Vector vec{8, 7, 5, 2, 0}; ASSERT_EQUAL(true, thrust::binary_search(vec.begin(), vec.end(), T{0}, thrust::greater())); ASSERT_EQUAL(false, thrust::binary_search(vec.begin(), vec.end(), T{1}, thrust::greater())); @@ -92,13 +74,7 @@ void TestScalarEqualRangeDescendingSimple() { using T = typename Vector::value_type; - Vector vec(5); - - vec[0] = 8; - vec[1] = 7; - vec[2] = 5; - vec[3] = 2; - vec[4] = 0; + Vector vec{8, 7, 5, 2, 0}; ASSERT_EQUAL_QUIET(vec.begin() + 4, thrust::equal_range(vec.begin(), vec.end(), T{0}, thrust::greater()).first); ASSERT_EQUAL_QUIET(vec.begin() + 4, thrust::equal_range(vec.begin(), vec.end(), T{1}, thrust::greater()).first); diff --git a/thrust/testing/binary_search_vector.cu b/thrust/testing/binary_search_vector.cu index 13f81c0015..129f086dc5 100644 --- a/thrust/testing/binary_search_vector.cu +++ b/thrust/testing/binary_search_vector.cu @@ -24,13 +24,7 @@ struct vector_like template void TestVectorLowerBoundSimple() { - Vector vec(5); - - vec[0] = 0; - vec[1] = 2; - vec[2] = 5; - vec[3] = 7; - vec[4] = 8; + Vector vec{0, 2, 5, 7, 8}; Vector input(10); thrust::sequence(input.begin(), input.end()); @@ -47,16 +41,8 @@ void TestVectorLowerBoundSimple() ASSERT_EQUAL((output_end - integral_output.begin()), 10); - ASSERT_EQUAL(integral_output[0], 0); - ASSERT_EQUAL(integral_output[1], 1); - ASSERT_EQUAL(integral_output[2], 1); - ASSERT_EQUAL(integral_output[3], 2); - ASSERT_EQUAL(integral_output[4], 2); - ASSERT_EQUAL(integral_output[5], 2); - ASSERT_EQUAL(integral_output[6], 3); - ASSERT_EQUAL(integral_output[7], 3); - ASSERT_EQUAL(integral_output[8], 4); - ASSERT_EQUAL(integral_output[9], 5); + IntVector ref{0, 1, 1, 2, 2, 2, 3, 3, 4, 5}; + ASSERT_EQUAL(integral_output, ref); // // test with interator output type // using IteratorVector = typename vector_like::type; @@ -120,13 +106,7 @@ DECLARE_UNITTEST(TestVectorLowerBoundDispatchImplicit); template void TestVectorUpperBoundSimple() { - Vector vec(5); - - vec[0] = 0; - vec[1] = 2; - vec[2] = 5; - vec[3] = 7; - vec[4] = 8; + Vector vec{0, 2, 5, 7, 8}; Vector input(10); thrust::sequence(input.begin(), input.end()); @@ -141,16 +121,8 @@ void TestVectorUpperBoundSimple() ASSERT_EQUAL((output_end - integral_output.begin()), 10); - ASSERT_EQUAL(integral_output[0], 1); - ASSERT_EQUAL(integral_output[1], 1); - ASSERT_EQUAL(integral_output[2], 2); - ASSERT_EQUAL(integral_output[3], 2); - ASSERT_EQUAL(integral_output[4], 2); - ASSERT_EQUAL(integral_output[5], 3); - ASSERT_EQUAL(integral_output[6], 3); - ASSERT_EQUAL(integral_output[7], 4); - ASSERT_EQUAL(integral_output[8], 5); - ASSERT_EQUAL(integral_output[9], 5); + IntVector ref{1, 1, 2, 2, 2, 3, 3, 4, 5, 5}; + ASSERT_EQUAL(integral_output, ref); // // test with interator output type // using IteratorVector = typename vector_like::type; @@ -214,13 +186,7 @@ DECLARE_UNITTEST(TestVectorUpperBoundDispatchImplicit); template void TestVectorBinarySearchSimple() { - Vector vec(5); - - vec[0] = 0; - vec[1] = 2; - vec[2] = 5; - vec[3] = 7; - vec[4] = 8; + Vector vec{0, 2, 5, 7, 8}; Vector input(10); thrust::sequence(input.begin(), input.end()); @@ -236,16 +202,8 @@ void TestVectorBinarySearchSimple() ASSERT_EQUAL((bool_output_end - bool_output.begin()), 10); - ASSERT_EQUAL(bool_output[0], true); - ASSERT_EQUAL(bool_output[1], false); - ASSERT_EQUAL(bool_output[2], true); - ASSERT_EQUAL(bool_output[3], false); - ASSERT_EQUAL(bool_output[4], false); - ASSERT_EQUAL(bool_output[5], true); - ASSERT_EQUAL(bool_output[6], false); - ASSERT_EQUAL(bool_output[7], true); - ASSERT_EQUAL(bool_output[8], true); - ASSERT_EQUAL(bool_output[9], false); + BoolVector bool_ref{true, false, true, false, false, true, false, true, true, false}; + ASSERT_EQUAL(bool_output, bool_ref); // test with integral output type IntVector integral_output(10, 2); @@ -254,16 +212,8 @@ void TestVectorBinarySearchSimple() ASSERT_EQUAL((int_output_end - integral_output.begin()), 10); - ASSERT_EQUAL(integral_output[0], 1); - ASSERT_EQUAL(integral_output[1], 0); - ASSERT_EQUAL(integral_output[2], 1); - ASSERT_EQUAL(integral_output[3], 0); - ASSERT_EQUAL(integral_output[4], 0); - ASSERT_EQUAL(integral_output[5], 1); - ASSERT_EQUAL(integral_output[6], 0); - ASSERT_EQUAL(integral_output[7], 1); - ASSERT_EQUAL(integral_output[8], 1); - ASSERT_EQUAL(integral_output[9], 0); + IntVector int_ref{1, 0, 1, 0, 0, 1, 0, 1, 1, 0}; + ASSERT_EQUAL(integral_output, int_ref); } DECLARE_VECTOR_UNITTEST(TestVectorBinarySearchSimple); diff --git a/thrust/testing/binary_search_vector_descending.cu b/thrust/testing/binary_search_vector_descending.cu index 4e5a391827..1d1650921d 100644 --- a/thrust/testing/binary_search_vector_descending.cu +++ b/thrust/testing/binary_search_vector_descending.cu @@ -25,13 +25,7 @@ void TestVectorLowerBoundDescendingSimple() { using T = typename Vector::value_type; - Vector vec(5); - - vec[0] = 8; - vec[1] = 7; - vec[2] = 5; - vec[3] = 2; - vec[4] = 0; + Vector vec{8, 7, 5, 2, 0}; Vector input(10); thrust::sequence(input.begin(), input.end()); @@ -46,29 +40,15 @@ void TestVectorLowerBoundDescendingSimple() ASSERT_EQUAL_QUIET(integral_output.end(), output_end); - ASSERT_EQUAL(4, integral_output[0]); - ASSERT_EQUAL(4, integral_output[1]); - ASSERT_EQUAL(3, integral_output[2]); - ASSERT_EQUAL(3, integral_output[3]); - ASSERT_EQUAL(3, integral_output[4]); - ASSERT_EQUAL(2, integral_output[5]); - ASSERT_EQUAL(2, integral_output[6]); - ASSERT_EQUAL(1, integral_output[7]); - ASSERT_EQUAL(0, integral_output[8]); - ASSERT_EQUAL(0, integral_output[9]); + IntVector ref{4, 4, 3, 3, 3, 2, 2, 1, 0, 0}; + ASSERT_EQUAL(ref, integral_output); } DECLARE_VECTOR_UNITTEST(TestVectorLowerBoundDescendingSimple); template void TestVectorUpperBoundDescendingSimple() { - Vector vec(5); - - vec[0] = 8; - vec[1] = 7; - vec[2] = 5; - vec[3] = 2; - vec[4] = 0; + Vector vec{8, 7, 5, 2, 0}; Vector input(10); thrust::sequence(input.begin(), input.end()); @@ -84,29 +64,15 @@ void TestVectorUpperBoundDescendingSimple() ASSERT_EQUAL_QUIET(output_end, integral_output.end()); - ASSERT_EQUAL(5, integral_output[0]); - ASSERT_EQUAL(4, integral_output[1]); - ASSERT_EQUAL(4, integral_output[2]); - ASSERT_EQUAL(3, integral_output[3]); - ASSERT_EQUAL(3, integral_output[4]); - ASSERT_EQUAL(3, integral_output[5]); - ASSERT_EQUAL(2, integral_output[6]); - ASSERT_EQUAL(2, integral_output[7]); - ASSERT_EQUAL(1, integral_output[8]); - ASSERT_EQUAL(0, integral_output[9]); + IntVector ref{5, 4, 4, 3, 3, 3, 2, 2, 1, 0}; + ASSERT_EQUAL(ref, integral_output); } DECLARE_VECTOR_UNITTEST(TestVectorUpperBoundDescendingSimple); template void TestVectorBinarySearchDescendingSimple() { - Vector vec(5); - - vec[0] = 8; - vec[1] = 7; - vec[2] = 5; - vec[3] = 2; - vec[4] = 0; + Vector vec{8, 7, 5, 2, 0}; Vector input(10); thrust::sequence(input.begin(), input.end()); @@ -123,16 +89,8 @@ void TestVectorBinarySearchDescendingSimple() ASSERT_EQUAL_QUIET(bool_output_end, bool_output.end()); - ASSERT_EQUAL(true, bool_output[0]); - ASSERT_EQUAL(false, bool_output[1]); - ASSERT_EQUAL(true, bool_output[2]); - ASSERT_EQUAL(false, bool_output[3]); - ASSERT_EQUAL(false, bool_output[4]); - ASSERT_EQUAL(true, bool_output[5]); - ASSERT_EQUAL(false, bool_output[6]); - ASSERT_EQUAL(true, bool_output[7]); - ASSERT_EQUAL(true, bool_output[8]); - ASSERT_EQUAL(false, bool_output[9]); + BoolVector bool_ref{true, false, true, false, false, true, false, true, true, false}; + ASSERT_EQUAL(bool_ref, bool_output); // test with integral output type IntVector integral_output(10, 2); @@ -141,16 +99,9 @@ void TestVectorBinarySearchDescendingSimple() ASSERT_EQUAL_QUIET(int_output_end, integral_output.end()); - ASSERT_EQUAL(1, integral_output[0]); - ASSERT_EQUAL(0, integral_output[1]); - ASSERT_EQUAL(1, integral_output[2]); - ASSERT_EQUAL(0, integral_output[3]); - ASSERT_EQUAL(0, integral_output[4]); - ASSERT_EQUAL(1, integral_output[5]); - ASSERT_EQUAL(0, integral_output[6]); - ASSERT_EQUAL(1, integral_output[7]); - ASSERT_EQUAL(1, integral_output[8]); - ASSERT_EQUAL(0, integral_output[9]); + IntVector int_ref{1, 0, 1, 0, 0, 1, 0, 1, 1, 0}; + + ASSERT_EQUAL(int_ref, integral_output); } DECLARE_VECTOR_UNITTEST(TestVectorBinarySearchDescendingSimple); diff --git a/thrust/testing/constant_iterator.cu b/thrust/testing/constant_iterator.cu index 9dbc3369dc..99a81f6510 100644 --- a/thrust/testing/constant_iterator.cu +++ b/thrust/testing/constant_iterator.cu @@ -121,10 +121,8 @@ void TestConstantIteratorCopy() ConstIter last = first + result.size(); thrust::copy(first, last, result.begin()); - ASSERT_EQUAL(7, result[0]); - ASSERT_EQUAL(7, result[1]); - ASSERT_EQUAL(7, result[2]); - ASSERT_EQUAL(7, result[3]); + Vector ref(4, 7); + ASSERT_EQUAL(ref, result); }; DECLARE_VECTOR_UNITTEST(TestConstantIteratorCopy); @@ -144,17 +142,13 @@ void TestConstantIteratorTransform() thrust::transform(first1, last1, result.begin(), thrust::negate()); - ASSERT_EQUAL(-7, result[0]); - ASSERT_EQUAL(-7, result[1]); - ASSERT_EQUAL(-7, result[2]); - ASSERT_EQUAL(-7, result[3]); + Vector ref(4, -7); + ASSERT_EQUAL(ref, result); thrust::transform(first1, last1, first2, result.begin(), thrust::plus()); - ASSERT_EQUAL(10, result[0]); - ASSERT_EQUAL(10, result[1]); - ASSERT_EQUAL(10, result[2]); - ASSERT_EQUAL(10, result[3]); + ref = Vector(4, 10); + ASSERT_EQUAL(ref, result); }; DECLARE_VECTOR_UNITTEST(TestConstantIteratorTransform); diff --git a/thrust/testing/copy.cu b/thrust/testing/copy.cu index a3f7f01f00..db9c06da7f 100644 --- a/thrust/testing/copy.cu +++ b/thrust/testing/copy.cu @@ -21,12 +21,7 @@ void TestCopyFromConstIterator() { using T = int; - std::vector v(5); - v[0] = 0; - v[1] = 1; - v[2] = 2; - v[3] = 3; - v[4] = 4; + std::vector v{0, 1, 2, 3, 4}; std::vector::const_iterator begin = v.begin(); std::vector::const_iterator end = v.end(); @@ -34,21 +29,16 @@ void TestCopyFromConstIterator() // copy to host_vector thrust::host_vector h(5, (T) 10); thrust::host_vector::iterator h_result = thrust::copy(begin, end, h.begin()); - ASSERT_EQUAL(h[0], 0); - ASSERT_EQUAL(h[1], 1); - ASSERT_EQUAL(h[2], 2); - ASSERT_EQUAL(h[3], 3); - ASSERT_EQUAL(h[4], 4); + + thrust::host_vector href{0, 1, 2, 3, 4}; + ASSERT_EQUAL(h, href); ASSERT_EQUAL_QUIET(h_result, h.end()); // copy to device_vector thrust::device_vector d(5, (T) 10); thrust::device_vector::iterator d_result = thrust::copy(begin, end, d.begin()); - ASSERT_EQUAL(d[0], 0); - ASSERT_EQUAL(d[1], 1); - ASSERT_EQUAL(d[2], 2); - ASSERT_EQUAL(d[3], 3); - ASSERT_EQUAL(d[4], 4); + thrust::device_vector dref{0, 1, 2, 3, 4}; + ASSERT_EQUAL(d, dref); ASSERT_EQUAL_QUIET(d_result, d.end()); } DECLARE_UNITTEST(TestCopyFromConstIterator); @@ -114,31 +104,21 @@ void TestCopyMatchingTypes() { using T = typename Vector::value_type; - Vector v(5); - v[0] = 0; - v[1] = 1; - v[2] = 2; - v[3] = 3; - v[4] = 4; + Vector v{0, 1, 2, 3, 4}; // copy to host_vector thrust::host_vector h(5, (T) 10); typename thrust::host_vector::iterator h_result = thrust::copy(v.begin(), v.end(), h.begin()); - ASSERT_EQUAL(h[0], 0); - ASSERT_EQUAL(h[1], 1); - ASSERT_EQUAL(h[2], 2); - ASSERT_EQUAL(h[3], 3); - ASSERT_EQUAL(h[4], 4); + thrust::host_vector href{0, 1, 2, 3, 4}; + ASSERT_EQUAL(h, href); ASSERT_EQUAL_QUIET(h_result, h.end()); // copy to device_vector thrust::device_vector d(5, (T) 10); typename thrust::device_vector::iterator d_result = thrust::copy(v.begin(), v.end(), d.begin()); - ASSERT_EQUAL(d[0], 0); - ASSERT_EQUAL(d[1], 1); - ASSERT_EQUAL(d[2], 2); - ASSERT_EQUAL(d[3], 3); - ASSERT_EQUAL(d[4], 4); + + thrust::device_vector dref{0, 1, 2, 3, 4}; + ASSERT_EQUAL(d, dref); ASSERT_EQUAL_QUIET(d_result, d.end()); } DECLARE_VECTOR_UNITTEST(TestCopyMatchingTypes); @@ -146,42 +126,27 @@ DECLARE_VECTOR_UNITTEST(TestCopyMatchingTypes); template void TestCopyMixedTypes() { - Vector v(5); - v[0] = 0; - v[1] = 1; - v[2] = 2; - v[3] = 3; - v[4] = 4; + Vector v{0, 1, 2, 3, 4}; // copy to host_vector with different type thrust::host_vector h(5, (float) 10); typename thrust::host_vector::iterator h_result = thrust::copy(v.begin(), v.end(), h.begin()); - - ASSERT_EQUAL(h[0], 0); - ASSERT_EQUAL(h[1], 1); - ASSERT_EQUAL(h[2], 2); - ASSERT_EQUAL(h[3], 3); - ASSERT_EQUAL(h[4], 4); + thrust::host_vector href{0, 1, 2, 3, 4}; + ASSERT_EQUAL(h, href); ASSERT_EQUAL_QUIET(h_result, h.end()); // copy to device_vector with different type thrust::device_vector d(5, (float) 10); typename thrust::device_vector::iterator d_result = thrust::copy(v.begin(), v.end(), d.begin()); - ASSERT_EQUAL(d[0], 0); - ASSERT_EQUAL(d[1], 1); - ASSERT_EQUAL(d[2], 2); - ASSERT_EQUAL(d[3], 3); - ASSERT_EQUAL(d[4], 4); + thrust::device_vector dref{0, 1, 2, 3, 4}; + ASSERT_EQUAL(d, dref); ASSERT_EQUAL_QUIET(d_result, d.end()); } DECLARE_INTEGRAL_VECTOR_UNITTEST(TestCopyMixedTypes); void TestCopyVectorBool() { - std::vector v(3); - v[0] = true; - v[1] = false; - v[2] = true; + std::vector v{true, false, true}; thrust::host_vector h(3); thrust::device_vector d(3); @@ -189,13 +154,11 @@ void TestCopyVectorBool() thrust::copy(v.begin(), v.end(), h.begin()); thrust::copy(v.begin(), v.end(), d.begin()); - ASSERT_EQUAL(h[0], true); - ASSERT_EQUAL(h[1], false); - ASSERT_EQUAL(h[2], true); + thrust::host_vector href{true, false, true}; + ASSERT_EQUAL(h, href); - ASSERT_EQUAL(d[0], true); - ASSERT_EQUAL(d[1], false); - ASSERT_EQUAL(d[2], true); + thrust::device_vector dref{true, false, true}; + ASSERT_EQUAL(d, dref); } DECLARE_UNITTEST(TestCopyVectorBool); @@ -205,22 +168,14 @@ void TestCopyListTo() using T = typename Vector::value_type; // copy from list to Vector - std::list l; - l.push_back(0); - l.push_back(1); - l.push_back(2); - l.push_back(3); - l.push_back(4); + std::list l{0, 1, 2, 3, 4}; Vector v(l.size()); typename Vector::iterator v_result = thrust::copy(l.begin(), l.end(), v.begin()); - ASSERT_EQUAL(v[0], T(0)); - ASSERT_EQUAL(v[1], T(1)); - ASSERT_EQUAL(v[2], T(2)); - ASSERT_EQUAL(v[3], T(3)); - ASSERT_EQUAL(v[4], T(4)); + Vector ref{0, 1, 2, 3, 4}; + ASSERT_EQUAL(v, ref); ASSERT_EQUAL_QUIET(v_result, v.end()); l.clear(); @@ -275,21 +230,14 @@ void TestCopyIfSimple() { using T = typename Vector::value_type; - Vector v(5); - v[0] = 0; - v[1] = 1; - v[2] = 2; - v[3] = 3; - v[4] = 4; + Vector v{0, 1, 2, 3, 4}; Vector dest(4); typename Vector::iterator dest_end = thrust::copy_if(v.begin(), v.end(), dest.begin(), is_true()); - ASSERT_EQUAL(1, dest[0]); - ASSERT_EQUAL(2, dest[1]); - ASSERT_EQUAL(3, dest[2]); - ASSERT_EQUAL(4, dest[3]); + Vector ref{1, 2, 3, 4}; + ASSERT_EQUAL(ref, dest); ASSERT_EQUAL_QUIET(dest.end(), dest_end); } DECLARE_VECTOR_UNITTEST(TestCopyIfSimple); @@ -403,27 +351,15 @@ void TestCopyIfStencilSimple() { using T = typename Vector::value_type; - Vector v(5); - v[0] = 0; - v[1] = 1; - v[2] = 2; - v[3] = 3; - v[4] = 4; - - Vector s(5); - s[0] = 1; - s[1] = 1; - s[2] = 0; - s[3] = 1; - s[4] = 0; + Vector v{0, 1, 2, 3, 4}; + Vector s{1, 1, 0, 1, 0}; Vector dest(3); typename Vector::iterator dest_end = thrust::copy_if(v.begin(), v.end(), s.begin(), dest.begin(), is_true()); - ASSERT_EQUAL(0, dest[0]); - ASSERT_EQUAL(1, dest[1]); - ASSERT_EQUAL(3, dest[2]); + Vector ref{0, 1, 3}; + ASSERT_EQUAL(ref, dest); ASSERT_EQUAL_QUIET(dest.end(), dest_end); } DECLARE_VECTOR_UNITTEST(TestCopyIfStencilSimple); @@ -572,14 +508,8 @@ void TestCopyZipIterator() { using T = typename Vector::value_type; - Vector v1(3); - v1[0] = 1; - v1[1] = 2; - v1[2] = 3; - Vector v2(3); - v2[0] = 4; - v2[1] = 5; - v2[2] = 6; + Vector v1{1, 2, 3}; + Vector v2{4, 5, 6}; Vector v3(3, T(0)); Vector v4(3, T(0)); @@ -604,12 +534,10 @@ void TestCopyConstantIteratorToZipIterator() thrust::make_constant_iterator(thrust::tuple(4, 7)) + v1.size(), thrust::make_zip_iterator(thrust::make_tuple(v1.begin(), v2.begin()))); - ASSERT_EQUAL(v1[0], 4); - ASSERT_EQUAL(v1[1], 4); - ASSERT_EQUAL(v1[2], 4); - ASSERT_EQUAL(v2[0], 7); - ASSERT_EQUAL(v2[1], 7); - ASSERT_EQUAL(v2[2], 7); + Vector ref1{4, 4, 4}; + Vector ref2{7, 7, 7}; + ASSERT_EQUAL(v1, ref1); + ASSERT_EQUAL(v2, ref2); }; DECLARE_VECTOR_UNITTEST(TestCopyConstantIteratorToZipIterator); diff --git a/thrust/testing/copy_n.cu b/thrust/testing/copy_n.cu index 39eb3a1e75..04cc29397b 100644 --- a/thrust/testing/copy_n.cu +++ b/thrust/testing/copy_n.cu @@ -15,33 +15,22 @@ void TestCopyNFromConstIterator() { using T = int; - std::vector v(5); - v[0] = 0; - v[1] = 1; - v[2] = 2; - v[3] = 3; - v[4] = 4; + std::vector v{0, 1, 2, 3, 4}; std::vector::const_iterator begin = v.begin(); // copy to host_vector thrust::host_vector h(5, (T) 10); thrust::host_vector::iterator h_result = thrust::copy_n(begin, h.size(), h.begin()); - ASSERT_EQUAL(h[0], 0); - ASSERT_EQUAL(h[1], 1); - ASSERT_EQUAL(h[2], 2); - ASSERT_EQUAL(h[3], 3); - ASSERT_EQUAL(h[4], 4); + ASSERT_EQUAL_QUIET(h_result, h.end()); // copy to device_vector thrust::device_vector d(5, (T) 10); thrust::device_vector::iterator d_result = thrust::copy_n(begin, d.size(), d.begin()); - ASSERT_EQUAL(d[0], 0); - ASSERT_EQUAL(d[1], 1); - ASSERT_EQUAL(d[2], 2); - ASSERT_EQUAL(d[3], 3); - ASSERT_EQUAL(d[4], 4); + + thrust::device_vector dref{0, 1, 2, 3, 4}; + ASSERT_EQUAL(d, dref); ASSERT_EQUAL_QUIET(d_result, d.end()); } DECLARE_UNITTEST(TestCopyNFromConstIterator); @@ -73,31 +62,20 @@ void TestCopyNMatchingTypes() { using T = typename Vector::value_type; - Vector v(5); - v[0] = 0; - v[1] = 1; - v[2] = 2; - v[3] = 3; - v[4] = 4; + Vector v{0, 1, 2, 3, 4}; // copy to host_vector thrust::host_vector h(5, (T) 10); typename thrust::host_vector::iterator h_result = thrust::copy_n(v.begin(), v.size(), h.begin()); - ASSERT_EQUAL(h[0], 0); - ASSERT_EQUAL(h[1], 1); - ASSERT_EQUAL(h[2], 2); - ASSERT_EQUAL(h[3], 3); - ASSERT_EQUAL(h[4], 4); + thrust::host_vector href{0, 1, 2, 3, 4}; + ASSERT_EQUAL(h, href); ASSERT_EQUAL_QUIET(h_result, h.end()); // copy to device_vector thrust::device_vector d(5, (T) 10); typename thrust::device_vector::iterator d_result = thrust::copy_n(v.begin(), v.size(), d.begin()); - ASSERT_EQUAL(d[0], 0); - ASSERT_EQUAL(d[1], 1); - ASSERT_EQUAL(d[2], 2); - ASSERT_EQUAL(d[3], 3); - ASSERT_EQUAL(d[4], 4); + thrust::device_vector dref{0, 1, 2, 3, 4}; + ASSERT_EQUAL(d, dref); ASSERT_EQUAL_QUIET(d_result, d.end()); } DECLARE_VECTOR_UNITTEST(TestCopyNMatchingTypes); @@ -105,42 +83,28 @@ DECLARE_VECTOR_UNITTEST(TestCopyNMatchingTypes); template void TestCopyNMixedTypes() { - Vector v(5); - v[0] = 0; - v[1] = 1; - v[2] = 2; - v[3] = 3; - v[4] = 4; + Vector v{0, 1, 2, 3, 4}; // copy to host_vector with different type thrust::host_vector h(5, (float) 10); typename thrust::host_vector::iterator h_result = thrust::copy_n(v.begin(), v.size(), h.begin()); - ASSERT_EQUAL(h[0], 0); - ASSERT_EQUAL(h[1], 1); - ASSERT_EQUAL(h[2], 2); - ASSERT_EQUAL(h[3], 3); - ASSERT_EQUAL(h[4], 4); + thrust::host_vector href{0, 1, 2, 3, 4}; + ASSERT_EQUAL(h, href); ASSERT_EQUAL_QUIET(h_result, h.end()); // copy to device_vector with different type thrust::device_vector d(5, (float) 10); typename thrust::device_vector::iterator d_result = thrust::copy_n(v.begin(), v.size(), d.begin()); - ASSERT_EQUAL(d[0], 0); - ASSERT_EQUAL(d[1], 1); - ASSERT_EQUAL(d[2], 2); - ASSERT_EQUAL(d[3], 3); - ASSERT_EQUAL(d[4], 4); + thrust::device_vector dref{0, 1, 2, 3, 4}; + ASSERT_EQUAL(d, dref); ASSERT_EQUAL_QUIET(d_result, d.end()); } DECLARE_INTEGRAL_VECTOR_UNITTEST(TestCopyNMixedTypes); void TestCopyNVectorBool() { - std::vector v(3); - v[0] = true; - v[1] = false; - v[2] = true; + std::vector v{true, false, true}; thrust::host_vector h(3); thrust::device_vector d(3); @@ -148,13 +112,13 @@ void TestCopyNVectorBool() thrust::copy_n(v.begin(), v.size(), h.begin()); thrust::copy_n(v.begin(), v.size(), d.begin()); - ASSERT_EQUAL(h[0], true); - ASSERT_EQUAL(h[1], false); - ASSERT_EQUAL(h[2], true); + thrust::host_vector href{true, false, true}; + ASSERT_EQUAL(h, href); - ASSERT_EQUAL(d[0], true); - ASSERT_EQUAL(d[1], false); - ASSERT_EQUAL(d[2], true); + thrust::device_vector dref{true, false, true}; + ASSERT_EQUAL(d, dref); + + ASSERT_EQUAL(d, dref); } DECLARE_UNITTEST(TestCopyNVectorBool); @@ -164,22 +128,14 @@ void TestCopyNListTo() using T = typename Vector::value_type; // copy from list to Vector - std::list l; - l.push_back(0); - l.push_back(1); - l.push_back(2); - l.push_back(3); - l.push_back(4); + std::list l{0, 1, 2, 3, 4}; Vector v(l.size()); typename Vector::iterator v_result = thrust::copy_n(l.begin(), l.size(), v.begin()); - ASSERT_EQUAL(v[0], T(0)); - ASSERT_EQUAL(v[1], T(1)); - ASSERT_EQUAL(v[2], T(2)); - ASSERT_EQUAL(v[3], T(3)); - ASSERT_EQUAL(v[4], T(4)); + Vector ref{0, 1, 2, 3, 4}; + ASSERT_EQUAL(v, ref); ASSERT_EQUAL_QUIET(v_result, v.end()); l.clear(); @@ -213,10 +169,8 @@ void TestCopyNCountingIterator() thrust::copy_n(iter, 4, vec.begin()); - ASSERT_EQUAL(vec[0], T(1)); - ASSERT_EQUAL(vec[1], T(2)); - ASSERT_EQUAL(vec[2], T(3)); - ASSERT_EQUAL(vec[3], T(4)); + Vector ref{1, 2, 3, 4}; + ASSERT_EQUAL(vec, ref); } DECLARE_INTEGRAL_VECTOR_UNITTEST(TestCopyNCountingIterator); @@ -225,16 +179,8 @@ void TestCopyNZipIterator() { using T = typename Vector::value_type; - Vector v1(4); - v1[0] = 1; - v1[1] = 2; - v1[2] = 3; - v1[3] = 4; - Vector v2(4); - v2[0] = 4; - v2[1] = 5; - v2[2] = 6; - v2[3] = 7; + Vector v1{1, 2, 3, 4}; + Vector v2{4, 5, 6, 7}; Vector v3(4, T(0)); Vector v4(4, T(0)); @@ -259,14 +205,11 @@ void TestCopyNConstantIteratorToZipIterator() v1.size(), thrust::make_zip_iterator(thrust::make_tuple(v1.begin(), v2.begin()))); - ASSERT_EQUAL(v1[0], T(4)); - ASSERT_EQUAL(v1[1], T(4)); - ASSERT_EQUAL(v1[2], T(4)); - ASSERT_EQUAL(v1[3], T(4)); - ASSERT_EQUAL(v2[0], T(7)); - ASSERT_EQUAL(v2[1], T(7)); - ASSERT_EQUAL(v2[2], T(7)); - ASSERT_EQUAL(v2[3], T(7)); + Vector ref1(4, 4); + Vector ref2(4, 7); + + ASSERT_EQUAL(v1, ref1); + ASSERT_EQUAL(v2, ref2); }; DECLARE_VECTOR_UNITTEST(TestCopyNConstantIteratorToZipIterator); diff --git a/thrust/testing/count.cu b/thrust/testing/count.cu index 3df7a1f6b4..18ee8225f9 100644 --- a/thrust/testing/count.cu +++ b/thrust/testing/count.cu @@ -6,12 +6,7 @@ template void TestCountSimple() { - Vector data(5); - data[0] = 1; - data[1] = 1; - data[2] = 0; - data[3] = 0; - data[4] = 1; + Vector data{1, 1, 0, 0, 1}; ASSERT_EQUAL(thrust::count(data.begin(), data.end(), 0), 2); ASSERT_EQUAL(thrust::count(data.begin(), data.end(), 1), 3); @@ -46,12 +41,7 @@ void TestCountIfSimple() { using T = typename Vector::value_type; - Vector data(5); - data[0] = 1; - data[1] = 6; - data[2] = 1; - data[3] = 9; - data[4] = 2; + Vector data{1, 6, 1, 9, 2}; ASSERT_EQUAL(thrust::count_if(data.begin(), data.end(), greater_than_five()), 2); } @@ -73,12 +63,7 @@ DECLARE_VARIABLE_UNITTEST(TestCountIf); template void TestCountFromConstIteratorSimple() { - Vector data(5); - data[0] = 1; - data[1] = 1; - data[2] = 0; - data[3] = 0; - data[4] = 1; + Vector data{1, 1, 0, 0, 1}; ASSERT_EQUAL(thrust::count(data.cbegin(), data.cend(), 0), 2); ASSERT_EQUAL(thrust::count(data.cbegin(), data.cend(), 1), 3); diff --git a/thrust/testing/cuda/swap_ranges.cu b/thrust/testing/cuda/swap_ranges.cu index 2fd1d7c022..ef193a3d4e 100644 --- a/thrust/testing/cuda/swap_ranges.cu +++ b/thrust/testing/cuda/swap_ranges.cu @@ -25,7 +25,7 @@ void TestSwapRangesDevice(ExecutionPolicy exec) ASSERT_EQUAL(cudaSuccess, err); ASSERT_EQUAL(v1, v1_ref); - ASSERT_EQUAL(v2, v1_ref); + ASSERT_EQUAL(v2, v2_ref); } void TestSwapRangesDeviceSeq() @@ -57,7 +57,7 @@ void TestSwapRangesCudaStreams() cudaStreamSynchronize(s); ASSERT_EQUAL(v1, v1_ref); - ASSERT_EQUAL(v2, v1_ref); + ASSERT_EQUAL(v2, v2_ref); cudaStreamDestroy(s); } diff --git a/thrust/testing/dereference.cu b/thrust/testing/dereference.cu index e198cd820d..128dddda00 100644 --- a/thrust/testing/dereference.cu +++ b/thrust/testing/dereference.cu @@ -79,11 +79,8 @@ void TestDeviceDereferenceCountingIterator() simple_copy(first, last, output.begin()); - ASSERT_EQUAL(output[0], 1); - ASSERT_EQUAL(output[1], 2); - ASSERT_EQUAL(output[2], 3); - ASSERT_EQUAL(output[3], 4); - ASSERT_EQUAL(output[4], 5); + thrust::device_vector ref{1, 2, 3, 4, 5}; + ASSERT_EQUAL(output, ref); } DECLARE_UNITTEST(TestDeviceDereferenceCountingIterator); @@ -98,11 +95,8 @@ void TestDeviceDereferenceTransformedCountingIterator() thrust::make_transform_iterator(last, thrust::negate()), output.begin()); - ASSERT_EQUAL(output[0], -1); - ASSERT_EQUAL(output[1], -2); - ASSERT_EQUAL(output[2], -3); - ASSERT_EQUAL(output[3], -4); - ASSERT_EQUAL(output[4], -5); + thrust::device_vector ref{-1, -2, -3, -4, -5}; + ASSERT_EQUAL(output, ref); } DECLARE_UNITTEST(TestDeviceDereferenceTransformedCountingIterator); diff --git a/thrust/testing/equal.cu b/thrust/testing/equal.cu index 901dd7db32..347b8c719d 100644 --- a/thrust/testing/equal.cu +++ b/thrust/testing/equal.cu @@ -11,13 +11,8 @@ void TestEqualSimple() { using T = typename Vector::value_type; - Vector v1(5); - Vector v2(5); - - // clang-format off - v1[0] = 5; v1[1] = 2; v1[2] = 0; v1[3] = 0; v1[4] = 0; - v2[0] = 5; v2[1] = 2; v2[2] = 0; v2[3] = 6; v2[4] = 1; - // clang-format on + Vector v1{5, 2, 0, 0, 0}; + Vector v2{5, 2, 0, 6, 1}; ASSERT_EQUAL(thrust::equal(v1.begin(), v1.end(), v1.begin()), true); ASSERT_EQUAL(thrust::equal(v1.begin(), v1.end(), v2.begin()), false); diff --git a/thrust/testing/fill.cu b/thrust/testing/fill.cu index 883f1b8393..a8cc66050a 100644 --- a/thrust/testing/fill.cu +++ b/thrust/testing/fill.cu @@ -14,44 +14,27 @@ void TestFillSimple() { using T = typename Vector::value_type; - Vector v(5); - v[0] = 0; - v[1] = 1; - v[2] = 2; - v[3] = 3; - v[4] = 4; + Vector v{0, 1, 2, 3, 4}; thrust::fill(v.begin() + 1, v.begin() + 4, (T) 7); - ASSERT_EQUAL(v[0], 0); - ASSERT_EQUAL(v[1], 7); - ASSERT_EQUAL(v[2], 7); - ASSERT_EQUAL(v[3], 7); - ASSERT_EQUAL(v[4], 4); + Vector ref{0, 7, 7, 7, 4}; + ASSERT_EQUAL(v, ref); thrust::fill(v.begin() + 0, v.begin() + 3, (T) 8); - ASSERT_EQUAL(v[0], 8); - ASSERT_EQUAL(v[1], 8); - ASSERT_EQUAL(v[2], 8); - ASSERT_EQUAL(v[3], 7); - ASSERT_EQUAL(v[4], 4); + ref = {8, 8, 8, 7, 4}; + ASSERT_EQUAL(v, ref); thrust::fill(v.begin() + 2, v.end(), (T) 9); - ASSERT_EQUAL(v[0], 8); - ASSERT_EQUAL(v[1], 8); - ASSERT_EQUAL(v[2], 9); - ASSERT_EQUAL(v[3], 9); - ASSERT_EQUAL(v[4], 9); + ref = {8, 8, 9, 9, 9}; + ASSERT_EQUAL(v, ref); thrust::fill(v.begin(), v.end(), (T) 1); - ASSERT_EQUAL(v[0], 1); - ASSERT_EQUAL(v[1], 1); - ASSERT_EQUAL(v[2], 1); - ASSERT_EQUAL(v[3], 1); - ASSERT_EQUAL(v[4], 1); + ref = Vector(5, 1); + ASSERT_EQUAL(v, ref); } DECLARE_VECTOR_UNITTEST(TestFillSimple); @@ -73,17 +56,13 @@ void TestFillMixedTypes() thrust::fill(v.begin(), v.end(), bool(true)); - ASSERT_EQUAL(v[0], 1); - ASSERT_EQUAL(v[1], 1); - ASSERT_EQUAL(v[2], 1); - ASSERT_EQUAL(v[3], 1); + Vector ref(4, 1); + ASSERT_EQUAL(v, ref); thrust::fill(v.begin(), v.end(), char(20)); - ASSERT_EQUAL(v[0], 20); - ASSERT_EQUAL(v[1], 20); - ASSERT_EQUAL(v[2], 20); - ASSERT_EQUAL(v[3], 20); + ref = Vector(4, 20); + ASSERT_EQUAL(v, ref); } DECLARE_VECTOR_UNITTEST(TestFillMixedTypes); @@ -125,47 +104,34 @@ void TestFillNSimple() { using T = typename Vector::value_type; - Vector v(5); - v[0] = 0; - v[1] = 1; - v[2] = 2; - v[3] = 3; - v[4] = 4; + Vector v{0, 1, 2, 3, 4}; typename Vector::iterator iter = thrust::fill_n(v.begin() + 1, 3, (T) 7); - ASSERT_EQUAL(v[0], 0); - ASSERT_EQUAL(v[1], 7); - ASSERT_EQUAL(v[2], 7); - ASSERT_EQUAL(v[3], 7); - ASSERT_EQUAL(v[4], 4); + Vector ref{0, 7, 7, 7, 4}; + ASSERT_EQUAL(v, ref); + ASSERT_EQUAL_QUIET(v.begin() + 4, iter); iter = thrust::fill_n(v.begin() + 0, 3, (T) 8); - ASSERT_EQUAL(v[0], 8); - ASSERT_EQUAL(v[1], 8); - ASSERT_EQUAL(v[2], 8); - ASSERT_EQUAL(v[3], 7); - ASSERT_EQUAL(v[4], 4); + ref = {8, 8, 8, 7, 4}; + ASSERT_EQUAL(v, ref); + ASSERT_EQUAL_QUIET(v.begin() + 3, iter); iter = thrust::fill_n(v.begin() + 2, 3, (T) 9); - ASSERT_EQUAL(v[0], 8); - ASSERT_EQUAL(v[1], 8); - ASSERT_EQUAL(v[2], 9); - ASSERT_EQUAL(v[3], 9); - ASSERT_EQUAL(v[4], 9); + ref = {8, 8, 9, 9, 9}; + ASSERT_EQUAL(v, ref); + ASSERT_EQUAL_QUIET(v.end(), iter); iter = thrust::fill_n(v.begin(), v.size(), (T) 1); - ASSERT_EQUAL(v[0], 1); - ASSERT_EQUAL(v[1], 1); - ASSERT_EQUAL(v[2], 1); - ASSERT_EQUAL(v[3], 1); - ASSERT_EQUAL(v[4], 1); + ref = Vector(5, 1); + ASSERT_EQUAL(v, ref); + ASSERT_EQUAL_QUIET(v.end(), iter); } DECLARE_VECTOR_UNITTEST(TestFillNSimple); @@ -192,18 +158,14 @@ void TestFillNMixedTypes() typename Vector::iterator iter = thrust::fill_n(v.begin(), v.size(), bool(true)); - ASSERT_EQUAL(v[0], 1); - ASSERT_EQUAL(v[1], 1); - ASSERT_EQUAL(v[2], 1); - ASSERT_EQUAL(v[3], 1); + Vector ref(4, 1); + ASSERT_EQUAL(v, ref); ASSERT_EQUAL_QUIET(v.end(), iter); iter = thrust::fill_n(v.begin(), v.size(), char(20)); - ASSERT_EQUAL(v[0], 20); - ASSERT_EQUAL(v[1], 20); - ASSERT_EQUAL(v[2], 20); - ASSERT_EQUAL(v[3], 20); + ref = Vector(4, 20); + ASSERT_EQUAL(v, ref); ASSERT_EQUAL_QUIET(v.end(), iter); } DECLARE_VECTOR_UNITTEST(TestFillNMixedTypes); @@ -258,15 +220,14 @@ void TestFillZipIterator() thrust::make_zip_iterator(thrust::make_tuple(v1.end(), v2.end(), v3.end())), thrust::tuple(4, 7, 13)); - ASSERT_EQUAL(4, v1[0]); - ASSERT_EQUAL(4, v1[1]); - ASSERT_EQUAL(4, v1[2]); - ASSERT_EQUAL(7, v2[0]); - ASSERT_EQUAL(7, v2[1]); - ASSERT_EQUAL(7, v2[2]); - ASSERT_EQUAL(13, v3[0]); - ASSERT_EQUAL(13, v3[1]); - ASSERT_EQUAL(13, v3[2]); + Vector ref1{4, 4, 4}; + ASSERT_EQUAL(ref1, v1); + + Vector ref2{7, 7, 7}; + ASSERT_EQUAL(ref2, v2); + + Vector ref3{13, 13, 13}; + ASSERT_EQUAL(ref3, v3); }; DECLARE_VECTOR_UNITTEST(TestFillZipIterator); diff --git a/thrust/testing/find.cu b/thrust/testing/find.cu index 152bba3842..9901a232fc 100644 --- a/thrust/testing/find.cu +++ b/thrust/testing/find.cu @@ -52,12 +52,7 @@ struct less_than_value_pred template void TestFindSimple() { - Vector vec(5); - vec[0] = 1; - vec[1] = 2; - vec[2] = 3; - vec[3] = 3; - vec[4] = 5; + Vector vec{1, 2, 3, 3, 5}; ASSERT_EQUAL(thrust::find(vec.begin(), vec.end(), 0) - vec.begin(), 5); ASSERT_EQUAL(thrust::find(vec.begin(), vec.end(), 1) - vec.begin(), 0); @@ -108,12 +103,7 @@ void TestFindIfSimple() { using T = typename Vector::value_type; - Vector vec(5); - vec[0] = 1; - vec[1] = 2; - vec[2] = 3; - vec[3] = 3; - vec[4] = 5; + Vector vec{1, 2, 3, 3, 5}; ASSERT_EQUAL(thrust::find_if(vec.begin(), vec.end(), equal_to_value_pred(0)) - vec.begin(), 5); ASSERT_EQUAL(thrust::find_if(vec.begin(), vec.end(), equal_to_value_pred(1)) - vec.begin(), 0); @@ -164,12 +154,7 @@ void TestFindIfNotSimple() { using T = typename Vector::value_type; - Vector vec(5); - vec[0] = 0; - vec[1] = 1; - vec[2] = 2; - vec[3] = 3; - vec[4] = 4; + Vector vec{0, 1, 2, 3, 4}; ASSERT_EQUAL(0, thrust::find_if_not(vec.begin(), vec.end(), less_than_value_pred(0)) - vec.begin()); ASSERT_EQUAL(1, thrust::find_if_not(vec.begin(), vec.end(), less_than_value_pred(1)) - vec.begin());