#include #include #include #include #include void TestConstantIteratorConstructFromConvertibleSystem(void) { using namespace thrust; constant_iterator default_system(13); constant_iterator host_system = default_system; ASSERT_EQUAL(*default_system, *host_system); constant_iterator device_system = default_system; ASSERT_EQUAL(*default_system, *device_system); } DECLARE_UNITTEST(TestConstantIteratorConstructFromConvertibleSystem); void TestConstantIteratorIncrement(void) { using namespace thrust; constant_iterator lhs(0,0); constant_iterator rhs(0,0); ASSERT_EQUAL(0, lhs - rhs); lhs++; ASSERT_EQUAL(1, lhs - rhs); lhs++; lhs++; ASSERT_EQUAL(3, lhs - rhs); lhs += 5; ASSERT_EQUAL(8, lhs - rhs); lhs -= 10; ASSERT_EQUAL(-2, lhs - rhs); } DECLARE_UNITTEST(TestConstantIteratorIncrement); void TestConstantIteratorIncrementBig(void) { long long int n = 10000000000ULL; thrust::constant_iterator begin(1); thrust::constant_iterator end = begin + n; ASSERT_EQUAL(thrust::distance(begin, end), n); } DECLARE_UNITTEST(TestConstantIteratorIncrementBig); void TestConstantIteratorComparison(void) { using namespace thrust; constant_iterator iter1(0); constant_iterator iter2(0); ASSERT_EQUAL(0, iter1 - iter2); ASSERT_EQUAL(true, iter1 == iter2); iter1++; ASSERT_EQUAL(1, iter1 - iter2); ASSERT_EQUAL(false, iter1 == iter2); iter2++; ASSERT_EQUAL(0, iter1 - iter2); ASSERT_EQUAL(true, iter1 == iter2); iter1 += 100; iter2 += 100; ASSERT_EQUAL(0, iter1 - iter2); ASSERT_EQUAL(true, iter1 == iter2); } DECLARE_UNITTEST(TestConstantIteratorComparison); void TestMakeConstantIterator(void) { using namespace thrust; // test one argument version constant_iterator iter0 = make_constant_iterator(13); ASSERT_EQUAL(13, *iter0); // test two argument version constant_iterator iter1 = make_constant_iterator(13, 7); ASSERT_EQUAL(13, *iter1); ASSERT_EQUAL(7, iter1 - iter0); } DECLARE_UNITTEST(TestMakeConstantIterator); template void TestConstantIteratorCopy(void) { using namespace thrust; using ValueType = typename Vector::value_type; using ConstIter = constant_iterator; Vector result(4); ConstIter first = make_constant_iterator(7); 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]); }; DECLARE_VECTOR_UNITTEST(TestConstantIteratorCopy); template void TestConstantIteratorTransform(void) { using namespace thrust; typedef typename Vector::value_type T; typedef constant_iterator ConstIter; Vector result(4); ConstIter first1 = make_constant_iterator(7); ConstIter last1 = first1 + result.size(); ConstIter first2 = make_constant_iterator(3); 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]); 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]); }; DECLARE_VECTOR_UNITTEST(TestConstantIteratorTransform); void TestConstantIteratorReduce(void) { using namespace thrust; typedef int T; typedef constant_iterator ConstIter; ConstIter first = make_constant_iterator(7); ConstIter last = first + 4; T sum = thrust::reduce(first, last); ASSERT_EQUAL(sum, 4 * 7); }; DECLARE_UNITTEST(TestConstantIteratorReduce);