init
Some checks failed
Docker. / Ubuntu (push) Has been cancelled
User-agent updater. / User-agent (push) Failing after 15s
Lock Threads / lock (push) Failing after 10s
Waiting for answer. / waiting-for-answer (push) Failing after 22s
Needs user action. / needs-user-action (push) Failing after 8s
Can't reproduce. / cant-reproduce (push) Failing after 8s
Close stale issues and PRs / stale (push) Has been cancelled
Some checks failed
Docker. / Ubuntu (push) Has been cancelled
User-agent updater. / User-agent (push) Failing after 15s
Lock Threads / lock (push) Failing after 10s
Waiting for answer. / waiting-for-answer (push) Failing after 22s
Needs user action. / needs-user-action (push) Failing after 8s
Can't reproduce. / cant-reproduce (push) Failing after 8s
Close stale issues and PRs / stale (push) Has been cancelled
This commit is contained in:
7
Telegram/ThirdParty/range-v3/test/numeric/CMakeLists.txt
vendored
Normal file
7
Telegram/ThirdParty/range-v3/test/numeric/CMakeLists.txt
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
set(CMAKE_FOLDER "${CMAKE_FOLDER}/numeric")
|
||||
|
||||
rv3_add_test(test.num.accumulate num.accumulate accumulate.cpp)
|
||||
rv3_add_test(test.num.adjacent_difference num.adjacent_difference adjacent_difference.cpp)
|
||||
rv3_add_test(test.num.inner_product num.inner_product inner_product.cpp)
|
||||
rv3_add_test(test.num.iota num.iota iota.cpp)
|
||||
rv3_add_test(test.num.partial_sum num.partial_sum partial_sum.cpp)
|
||||
75
Telegram/ThirdParty/range-v3/test/numeric/accumulate.cpp
vendored
Normal file
75
Telegram/ThirdParty/range-v3/test/numeric/accumulate.cpp
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
// Range v3 library
|
||||
//
|
||||
// Copyright Eric Niebler 2014-present
|
||||
//
|
||||
// Use, modification and distribution is subject to the
|
||||
// Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// Project home: https://github.com/ericniebler/range-v3
|
||||
//
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include <range/v3/core.hpp>
|
||||
#include <range/v3/numeric/accumulate.hpp>
|
||||
#include "../simple_test.hpp"
|
||||
#include "../test_iterators.hpp"
|
||||
|
||||
struct S
|
||||
{
|
||||
int i;
|
||||
S add(int j) const
|
||||
{
|
||||
return S{i + j};
|
||||
}
|
||||
};
|
||||
|
||||
template<class Iter, class Sent = Iter>
|
||||
void test()
|
||||
{
|
||||
int ia[] = {1, 2, 3, 4, 5, 6};
|
||||
constexpr auto sc = ranges::size(ia);
|
||||
CHECK(ranges::accumulate(Iter(ia), Sent(ia), 0) == 0);
|
||||
CHECK(ranges::accumulate(Iter(ia), Sent(ia), 10) == 10);
|
||||
CHECK(ranges::accumulate(Iter(ia), Sent(ia+1), 0) == 1);
|
||||
CHECK(ranges::accumulate(Iter(ia), Sent(ia+1), 10) == 11);
|
||||
CHECK(ranges::accumulate(Iter(ia), Sent(ia+2), 0) == 3);
|
||||
CHECK(ranges::accumulate(Iter(ia), Sent(ia+2), 10) == 13);
|
||||
CHECK(ranges::accumulate(Iter(ia), Sent(ia+sc), 0) == 21);
|
||||
CHECK(ranges::accumulate(Iter(ia), Sent(ia+sc), 10) == 31);
|
||||
|
||||
using ranges::make_subrange;
|
||||
CHECK(ranges::accumulate(make_subrange(Iter(ia), Sent(ia)), 0) == 0);
|
||||
CHECK(ranges::accumulate(make_subrange(Iter(ia), Sent(ia)), 10) == 10);
|
||||
CHECK(ranges::accumulate(make_subrange(Iter(ia), Sent(ia+1)), 0) == 1);
|
||||
CHECK(ranges::accumulate(make_subrange(Iter(ia), Sent(ia+1)), 10) == 11);
|
||||
CHECK(ranges::accumulate(make_subrange(Iter(ia), Sent(ia+2)), 0) == 3);
|
||||
CHECK(ranges::accumulate(make_subrange(Iter(ia), Sent(ia+2)), 10) == 13);
|
||||
CHECK(ranges::accumulate(make_subrange(Iter(ia), Sent(ia+sc)), 0) == 21);
|
||||
CHECK(ranges::accumulate(make_subrange(Iter(ia), Sent(ia+sc)), 10) == 31);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test<InputIterator<const int*> >();
|
||||
test<ForwardIterator<const int*> >();
|
||||
test<BidirectionalIterator<const int*> >();
|
||||
test<RandomAccessIterator<const int*> >();
|
||||
test<const int*>();
|
||||
|
||||
test<InputIterator<const int*>, Sentinel<const int*> >();
|
||||
test<ForwardIterator<const int*>, Sentinel<const int*> >();
|
||||
test<BidirectionalIterator<const int*>, Sentinel<const int*> >();
|
||||
test<RandomAccessIterator<const int*>, Sentinel<const int*> >();
|
||||
|
||||
return ::test_result();
|
||||
}
|
||||
179
Telegram/ThirdParty/range-v3/test/numeric/adjacent_difference.cpp
vendored
Normal file
179
Telegram/ThirdParty/range-v3/test/numeric/adjacent_difference.cpp
vendored
Normal file
@@ -0,0 +1,179 @@
|
||||
// Range v3 library
|
||||
//
|
||||
// Copyright Eric Niebler 2014-present
|
||||
// Copyright Gonzalo Brito Gadeschi 2014
|
||||
//
|
||||
// Use, modification and distribution is subject to the
|
||||
// Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// Project home: https://github.com/ericniebler/range-v3
|
||||
//
|
||||
// Implementation based on the code in libc++
|
||||
// http://http://libcxx.llvm.org/
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include <range/v3/core.hpp>
|
||||
#include <range/v3/numeric/adjacent_difference.hpp>
|
||||
#include "../simple_test.hpp"
|
||||
#include "../test_iterators.hpp"
|
||||
|
||||
struct S
|
||||
{
|
||||
int i;
|
||||
};
|
||||
|
||||
template<class InIter, class OutIter, class InSent = InIter> void test()
|
||||
{
|
||||
using ranges::adjacent_difference;
|
||||
using ranges::make_subrange;
|
||||
{ // iterator
|
||||
int ia[] = {15, 10, 6, 3, 1};
|
||||
int ir[] = {15, -5, -4, -3, -2};
|
||||
const unsigned s = sizeof(ia) / sizeof(ia[0]);
|
||||
int ib[s] = {0};
|
||||
auto r = adjacent_difference(InIter(ia), InSent(ia + s), OutIter(ib));
|
||||
CHECK(base(r.in) == ia + s);
|
||||
CHECK(base(r.out) == ib + s);
|
||||
for(unsigned i = 0; i < s; ++i)
|
||||
{
|
||||
CHECK(ib[i] == ir[i]);
|
||||
}
|
||||
}
|
||||
|
||||
{ // range + output iterator
|
||||
int ia[] = {15, 10, 6, 3, 1};
|
||||
int ir[] = {15, -5, -4, -3, -2};
|
||||
const unsigned s = sizeof(ia) / sizeof(ia[0]);
|
||||
int ib[s] = {0};
|
||||
auto rng = make_subrange(InIter(ia), InSent(ia + s));
|
||||
auto r = adjacent_difference(rng, OutIter(ib));
|
||||
CHECK(base(r.in) == ia + s);
|
||||
CHECK(base(r.out) == ib + s);
|
||||
for(unsigned i = 0; i < s; ++i)
|
||||
{
|
||||
CHECK(ib[i] == ir[i]);
|
||||
}
|
||||
}
|
||||
|
||||
{ // range + output range
|
||||
int ia[] = {15, 10, 6, 3, 1};
|
||||
int ir[] = {15, -5, -4, -3, -2};
|
||||
const unsigned s = sizeof(ia) / sizeof(ia[0]);
|
||||
int ib[s] = {0};
|
||||
auto rng = make_subrange(InIter(ia), InSent(ia + s));
|
||||
auto orng = make_subrange(OutIter(ib), OutIter(ib + s));
|
||||
auto r = adjacent_difference(rng, orng);
|
||||
CHECK(base(r.in) == ia + s);
|
||||
CHECK(base(r.out) == ib + s);
|
||||
for(unsigned i = 0; i < s; ++i)
|
||||
{
|
||||
CHECK(ib[i] == ir[i]);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
int ia[] = {15, 10, 6, 3, 1};
|
||||
int ir[] = {15, 25, 16, 9, 4};
|
||||
const unsigned s = sizeof(ia) / sizeof(ia[0]);
|
||||
int ib[s] = {0};
|
||||
auto rng = make_subrange(InIter(ia), InSent(ia + s));
|
||||
auto orng = make_subrange(OutIter(ib), OutIter(ib + s));
|
||||
auto r = adjacent_difference(rng, orng, std::plus<int>());
|
||||
CHECK(base(r.in) == ia + s);
|
||||
CHECK(base(r.out) == ib + s);
|
||||
for(unsigned i = 0; i < s; ++i)
|
||||
{
|
||||
CHECK(ib[i] == ir[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test<InputIterator<const int *>, InputIterator<int *>>();
|
||||
test<InputIterator<const int *>, ForwardIterator<int *>>();
|
||||
test<InputIterator<const int *>, BidirectionalIterator<int *>>();
|
||||
test<InputIterator<const int *>, RandomAccessIterator<int *>>();
|
||||
test<InputIterator<const int *>, int *>();
|
||||
|
||||
test<ForwardIterator<const int *>, InputIterator<int *>>();
|
||||
test<ForwardIterator<const int *>, ForwardIterator<int *>>();
|
||||
test<ForwardIterator<const int *>, BidirectionalIterator<int *>>();
|
||||
test<ForwardIterator<const int *>, RandomAccessIterator<int *>>();
|
||||
test<ForwardIterator<const int *>, int *>();
|
||||
|
||||
test<BidirectionalIterator<const int *>, InputIterator<int *>>();
|
||||
test<BidirectionalIterator<const int *>, ForwardIterator<int *>>();
|
||||
test<BidirectionalIterator<const int *>, BidirectionalIterator<int *>>();
|
||||
test<BidirectionalIterator<const int *>, RandomAccessIterator<int *>>();
|
||||
test<BidirectionalIterator<const int *>, int *>();
|
||||
|
||||
test<RandomAccessIterator<const int *>, InputIterator<int *>>();
|
||||
test<RandomAccessIterator<const int *>, ForwardIterator<int *>>();
|
||||
test<RandomAccessIterator<const int *>, BidirectionalIterator<int *>>();
|
||||
test<RandomAccessIterator<const int *>, RandomAccessIterator<int *>>();
|
||||
test<RandomAccessIterator<const int *>, int *>();
|
||||
|
||||
test<const int *, InputIterator<int *>>();
|
||||
test<const int *, ForwardIterator<int *>>();
|
||||
test<const int *, BidirectionalIterator<int *>>();
|
||||
test<const int *, RandomAccessIterator<int *>>();
|
||||
test<const int *, int *>();
|
||||
|
||||
using ranges::adjacent_difference;
|
||||
|
||||
{ // Test projections
|
||||
S ia[] = {{15}, {10}, {6}, {3}, {1}};
|
||||
int ir[] = {15, -5, -4, -3, -2};
|
||||
const unsigned s = sizeof(ir) / sizeof(ir[0]);
|
||||
int ib[s] = {0};
|
||||
auto r = adjacent_difference(ranges::begin(ia), ranges::begin(ia) + s,
|
||||
ranges::begin(ib), std::minus<int>(), &S::i);
|
||||
CHECK(base(r.in) == ia + s);
|
||||
CHECK(base(r.out) == ib + s);
|
||||
for(unsigned i = 0; i < s; ++i)
|
||||
{
|
||||
CHECK(ib[i] == ir[i]);
|
||||
}
|
||||
}
|
||||
|
||||
{ // Test BinaryOp
|
||||
int ia[] = {15, 10, 6, 3, 1};
|
||||
int ir[] = {15, 25, 16, 9, 4};
|
||||
const unsigned s = sizeof(ir) / sizeof(ir[0]);
|
||||
int ib[s] = {0};
|
||||
auto r = adjacent_difference(ia, ranges::begin(ib), std::plus<int>());
|
||||
CHECK(base(r.in) == ia + s);
|
||||
CHECK(base(r.out) == ib + s);
|
||||
for(unsigned i = 0; i < s; ++i)
|
||||
{
|
||||
CHECK(ib[i] == ir[i]);
|
||||
}
|
||||
}
|
||||
|
||||
{ // Test calling it with an array
|
||||
int ia[] = {15, 10, 6, 3, 1};
|
||||
int ir[] = {15, 25, 16, 9, 4};
|
||||
const unsigned s = sizeof(ir) / sizeof(ir[0]);
|
||||
int ib[s] = {0};
|
||||
auto r = adjacent_difference(ia, ib, std::plus<int>());
|
||||
CHECK(base(r.in) == ia + s);
|
||||
CHECK(base(r.out) == ib + s);
|
||||
for(unsigned i = 0; i < s; ++i)
|
||||
{
|
||||
CHECK(ib[i] == ir[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return ::test_result();
|
||||
}
|
||||
191
Telegram/ThirdParty/range-v3/test/numeric/inner_product.cpp
vendored
Normal file
191
Telegram/ThirdParty/range-v3/test/numeric/inner_product.cpp
vendored
Normal file
@@ -0,0 +1,191 @@
|
||||
// Range v3 library
|
||||
//
|
||||
// Copyright Eric Niebler 2014-present
|
||||
// Copyright Gonzalo Brito Gadeschi 2014
|
||||
//
|
||||
// Use, modification and distribution is subject to the
|
||||
// Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// Project home: https://github.com/ericniebler/range-v3
|
||||
//
|
||||
// Implementation based on the code in libc++
|
||||
// http://http://libcxx.llvm.org/
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include <range/v3/core.hpp>
|
||||
#include <range/v3/numeric/inner_product.hpp>
|
||||
#include <range/v3/algorithm/equal.hpp>
|
||||
#include "../simple_test.hpp"
|
||||
#include "../test_iterators.hpp"
|
||||
|
||||
RANGES_DIAGNOSTIC_IGNORE_SIGN_CONVERSION
|
||||
|
||||
namespace
|
||||
{
|
||||
struct S
|
||||
{
|
||||
int i;
|
||||
};
|
||||
|
||||
template<class Iter1, class Iter2, class Sent1 = Iter1>
|
||||
void test()
|
||||
{
|
||||
int a[] = {1, 2, 3, 4, 5, 6};
|
||||
int b[] = {6, 5, 4, 3, 2, 1};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
|
||||
// iterator test:
|
||||
auto it3 = [](int* b1, int l1, int* b2, int i)
|
||||
{
|
||||
return ranges::inner_product(Iter1(b1), Sent1(b1+l1), Iter2(b2), i);
|
||||
};
|
||||
CHECK(it3(a, 0, b, 0) == 0);
|
||||
CHECK(it3(a, 0, b, 10) == 10);
|
||||
CHECK(it3(a, 1, b, 0) == 6);
|
||||
CHECK(it3(a, 1, b, 10) == 16);
|
||||
CHECK(it3(a, 2, b, 0) == 16);
|
||||
CHECK(it3(a, 2, b, 10) == 26);
|
||||
CHECK(it3(a, sa, b, 0) == 56);
|
||||
CHECK(it3(a, sa, b, 10) == 66);
|
||||
|
||||
auto it4 = [](int* b1, int l1, int* b2, int i)
|
||||
{
|
||||
return ranges::inner_product(Iter1(b1), Sent1(b1+l1), Iter2(b2), Iter2(b2+l1), i);
|
||||
};
|
||||
CHECK(it4(a, 0, b, 0) == 0);
|
||||
CHECK(it4(a, 0, b, 10) == 10);
|
||||
CHECK(it4(a, 1, b, 0) == 6);
|
||||
CHECK(it4(a, 1, b, 10) == 16);
|
||||
CHECK(it4(a, 2, b, 0) == 16);
|
||||
CHECK(it4(a, 2, b, 10) == 26);
|
||||
CHECK(it4(a, sa, b, 0) == 56);
|
||||
CHECK(it4(a, sa, b, 10) == 66);
|
||||
|
||||
// rng test:
|
||||
auto rng3 = [](int* b1, int l1, int* b2, int i)
|
||||
{
|
||||
return ranges::inner_product(ranges::make_subrange(Iter1(b1), Sent1(b1+l1)), Iter2(b2), i);
|
||||
};
|
||||
CHECK(rng3(a, 0, b, 0) == 0);
|
||||
CHECK(rng3(a, 0, b, 10) == 10);
|
||||
CHECK(rng3(a, 1, b, 0) == 6);
|
||||
CHECK(rng3(a, 1, b, 10) == 16);
|
||||
CHECK(rng3(a, 2, b, 0) == 16);
|
||||
CHECK(rng3(a, 2, b, 10) == 26);
|
||||
CHECK(rng3(a, sa, b, 0) == 56);
|
||||
CHECK(rng3(a, sa, b, 10) == 66);
|
||||
|
||||
auto rng4 = [](int* b1, int l1, int* b2, int i)
|
||||
{
|
||||
return ranges::inner_product(ranges::make_subrange(Iter1(b1), Sent1(b1+l1)),
|
||||
ranges::make_subrange(Iter2(b2), Iter2(b2+l1)), i);
|
||||
};
|
||||
CHECK(rng4(a, 0, b, 0) == 0);
|
||||
CHECK(rng4(a, 0, b, 10) == 10);
|
||||
CHECK(rng4(a, 1, b, 0) == 6);
|
||||
CHECK(rng4(a, 1, b, 10) == 16);
|
||||
CHECK(rng4(a, 2, b, 0) == 16);
|
||||
CHECK(rng4(a, 2, b, 10) == 26);
|
||||
CHECK(rng4(a, sa, b, 0) == 56);
|
||||
CHECK(rng4(a, sa, b, 10) == 66);
|
||||
|
||||
// rng + bops:
|
||||
auto bops = [](int* b1, int l1, int* b2, int i)
|
||||
{
|
||||
return ranges::inner_product(ranges::make_subrange(Iter1(b1), Sent1(b1+l1)),
|
||||
ranges::make_subrange(Iter2(b2), Iter2(b2+l1)), i,
|
||||
std::multiplies<int>(), std::plus<int>());
|
||||
};
|
||||
CHECK(bops(a, 0, b, 1) == 1);
|
||||
CHECK(bops(a, 0, b, 10) == 10);
|
||||
CHECK(bops(a, 1, b, 1) == 7);
|
||||
CHECK(bops(a, 1, b, 10) == 70);
|
||||
CHECK(bops(a, 2, b, 1) == 49);
|
||||
CHECK(bops(a, 2, b, 10) == 490);
|
||||
CHECK(bops(a, sa, b, 1) == 117649);
|
||||
CHECK(bops(a, sa, b, 10) == 1176490);
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test<InputIterator<const int*>, InputIterator<const int*> >();
|
||||
test<InputIterator<const int*>, ForwardIterator<const int*> >();
|
||||
test<InputIterator<const int*>, BidirectionalIterator<const int*> >();
|
||||
test<InputIterator<const int*>, RandomAccessIterator<const int*> >();
|
||||
test<InputIterator<const int*>, const int*>();
|
||||
|
||||
test<ForwardIterator<const int*>, InputIterator<const int*> >();
|
||||
test<ForwardIterator<const int*>, ForwardIterator<const int*> >();
|
||||
test<ForwardIterator<const int*>, BidirectionalIterator<const int*> >();
|
||||
test<ForwardIterator<const int*>, RandomAccessIterator<const int*> >();
|
||||
test<ForwardIterator<const int*>, const int*>();
|
||||
|
||||
test<BidirectionalIterator<const int*>, InputIterator<const int*> >();
|
||||
test<BidirectionalIterator<const int*>, ForwardIterator<const int*> >();
|
||||
test<BidirectionalIterator<const int*>, BidirectionalIterator<const int*> >();
|
||||
test<BidirectionalIterator<const int*>, RandomAccessIterator<const int*> >();
|
||||
test<BidirectionalIterator<const int*>, const int*>();
|
||||
|
||||
test<RandomAccessIterator<const int*>, InputIterator<const int*> >();
|
||||
test<RandomAccessIterator<const int*>, ForwardIterator<const int*> >();
|
||||
test<RandomAccessIterator<const int*>, BidirectionalIterator<const int*> >();
|
||||
test<RandomAccessIterator<const int*>, RandomAccessIterator<const int*> >();
|
||||
test<RandomAccessIterator<const int*>, const int*>();
|
||||
|
||||
test<const int*, InputIterator<const int*> >();
|
||||
test<const int*, ForwardIterator<const int*> >();
|
||||
test<const int*, BidirectionalIterator<const int*> >();
|
||||
test<const int*, RandomAccessIterator<const int*> >();
|
||||
test<const int*, const int*>();
|
||||
|
||||
// test projections:
|
||||
{
|
||||
S a[] = {{1}, {2}, {3}, {4}, {5}, {6}};
|
||||
S b[] = {{6}, {5}, {4}, {3}, {2}, {1}};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
|
||||
using Iter1 = InputIterator<const S*>;
|
||||
using Sent1 = InputIterator<const S*>;
|
||||
using Iter2 = Iter1;
|
||||
|
||||
// rng + bops:
|
||||
auto bops = [&](S* b1, int l1, S* b2, int i)
|
||||
{
|
||||
return ranges::inner_product(ranges::make_subrange(Iter1(b1), Sent1(b1+l1)),
|
||||
ranges::make_subrange(Iter2(b2), Iter2(b2+l1)), i,
|
||||
std::multiplies<int>(), std::plus<int>(),
|
||||
&S::i, &S::i);
|
||||
};
|
||||
|
||||
CHECK(bops(a, 0, b, 1) == 1);
|
||||
CHECK(bops(a, 0, b, 10) == 10);
|
||||
CHECK(bops(a, 1, b, 1) == 7);
|
||||
CHECK(bops(a, 1, b, 10) == 70);
|
||||
CHECK(bops(a, 2, b, 1) == 49);
|
||||
CHECK(bops(a, 2, b, 10) == 490);
|
||||
CHECK(bops(a, sa, b, 1) == 117649);
|
||||
CHECK(bops(a, sa, b, 10) == 1176490);
|
||||
}
|
||||
|
||||
{
|
||||
int a[] = {1, 2, 3, 4, 5, 6};
|
||||
int b[] = {6, 5, 4, 3, 2, 1};
|
||||
|
||||
// raw array test:
|
||||
CHECK(ranges::inner_product(a, b, 0) == 56);
|
||||
CHECK(ranges::inner_product(a, b, 10) == 66);
|
||||
}
|
||||
|
||||
return ::test_result();
|
||||
}
|
||||
64
Telegram/ThirdParty/range-v3/test/numeric/iota.cpp
vendored
Normal file
64
Telegram/ThirdParty/range-v3/test/numeric/iota.cpp
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
// Range v3 library
|
||||
//
|
||||
// Copyright Eric Niebler 2014-present
|
||||
// Copyright Gonzalo Brito Gadeschi 2014
|
||||
//
|
||||
// Use, modification and distribution is subject to the
|
||||
// Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// Project home: https://github.com/ericniebler/range-v3
|
||||
//
|
||||
// Implementation based on the code in libc++
|
||||
// http://http://libcxx.llvm.org/
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include <range/v3/core.hpp>
|
||||
#include <range/v3/numeric/iota.hpp>
|
||||
#include <range/v3/algorithm/equal.hpp>
|
||||
#include "../simple_test.hpp"
|
||||
#include "../test_iterators.hpp"
|
||||
|
||||
template<class Iter, class Sent = Iter>
|
||||
void test()
|
||||
{
|
||||
int ir[] = {5, 6, 7, 8, 9};
|
||||
constexpr auto s = ranges::size(ir);
|
||||
{
|
||||
int ia[] = {1, 2, 3, 4, 5};
|
||||
ranges::iota(Iter(ia), Sent(ia + s), 5);
|
||||
CHECK(ranges::equal(ia, ir));
|
||||
}
|
||||
|
||||
{
|
||||
int ia[] = {1, 2, 3, 4, 5};
|
||||
auto rng = ranges::make_subrange(Iter(ia), Sent(ia + s));
|
||||
ranges::iota(rng, 5);
|
||||
CHECK(ranges::equal(ia, ir));
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test<InputIterator<int*> >();
|
||||
test<ForwardIterator<int*> >();
|
||||
test<BidirectionalIterator<int*> >();
|
||||
test<RandomAccessIterator<int*> >();
|
||||
test<int*>();
|
||||
|
||||
test<InputIterator<int*>, Sentinel<int*> >();
|
||||
test<ForwardIterator<int*>, Sentinel<int*> >();
|
||||
test<BidirectionalIterator<int*>, Sentinel<int*> >();
|
||||
test<RandomAccessIterator<int*>, Sentinel<int*> >();
|
||||
|
||||
return ::test_result();
|
||||
}
|
||||
198
Telegram/ThirdParty/range-v3/test/numeric/partial_sum.cpp
vendored
Normal file
198
Telegram/ThirdParty/range-v3/test/numeric/partial_sum.cpp
vendored
Normal file
@@ -0,0 +1,198 @@
|
||||
// Range v3 library
|
||||
//
|
||||
// Copyright Eric Niebler 2014-present
|
||||
// Copyright Gonzalo Brito Gadeschi 2014
|
||||
//
|
||||
// Use, modification and distribution is subject to the
|
||||
// Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// Project home: https://github.com/ericniebler/range-v3
|
||||
//
|
||||
// Implementation based on the code in libc++
|
||||
// http://http://libcxx.llvm.org/
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include <range/v3/core.hpp>
|
||||
#include <range/v3/numeric/partial_sum.hpp>
|
||||
#include <range/v3/view/zip.hpp>
|
||||
#include "../simple_test.hpp"
|
||||
#include "../test_iterators.hpp"
|
||||
|
||||
struct S
|
||||
{
|
||||
int i;
|
||||
};
|
||||
|
||||
template<class InIter, class OutIter, class InSent = InIter> void test()
|
||||
{
|
||||
using ranges::partial_sum;
|
||||
using ranges::make_subrange;
|
||||
{ // iterator
|
||||
int ir[] = {1, 3, 6, 10, 15};
|
||||
const unsigned s = sizeof(ir) / sizeof(ir[0]);
|
||||
int ia[] = {1, 2, 3, 4, 5};
|
||||
int ib[s] = {0};
|
||||
auto r = partial_sum(InIter(ia), InSent(ia + s), OutIter(ib));
|
||||
CHECK(base(r.in) == ia + s);
|
||||
CHECK(base(r.out) == ib + s);
|
||||
for(unsigned i = 0; i < s; ++i)
|
||||
{
|
||||
CHECK(ib[i] == ir[i]);
|
||||
}
|
||||
}
|
||||
|
||||
{ // range + output iterator
|
||||
int ir[] = {1, 3, 6, 10, 15};
|
||||
const unsigned s = sizeof(ir) / sizeof(ir[0]);
|
||||
int ia[] = {1, 2, 3, 4, 5};
|
||||
int ib[s] = {0};
|
||||
auto rng = make_subrange(InIter(ia), InSent(ia + s));
|
||||
auto r = partial_sum(rng, OutIter(ib));
|
||||
CHECK(base(r.in) == ia + s);
|
||||
CHECK(base(r.out) == ib + s);
|
||||
for(unsigned i = 0; i < s; ++i)
|
||||
{
|
||||
CHECK(ib[i] == ir[i]);
|
||||
}
|
||||
}
|
||||
|
||||
{ // range + output range
|
||||
int ir[] = {1, 3, 6, 10, 15};
|
||||
const unsigned s = sizeof(ir) / sizeof(ir[0]);
|
||||
int ia[] = {1, 2, 3, 4, 5};
|
||||
int ib[s] = {0};
|
||||
auto rng = make_subrange(InIter(ia), InSent(ia + s));
|
||||
auto orng = make_subrange(OutIter(ib), OutIter(ib + s));
|
||||
auto r = partial_sum(rng, orng);
|
||||
CHECK(base(r.in) == ia + s);
|
||||
CHECK(base(r.out) == ib + s);
|
||||
for(unsigned i = 0; i < s; ++i)
|
||||
{
|
||||
CHECK(ib[i] == ir[i]);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
int ia[] = {1, 2, 3, 4, 5};
|
||||
int ir[] = {1, -1, -4, -8, -13};
|
||||
const unsigned s = sizeof(ia) / sizeof(ia[0]);
|
||||
int ib[s] = {0};
|
||||
auto rng = make_subrange(InIter(ia), InSent(ia + s));
|
||||
auto orng = make_subrange(OutIter(ib), OutIter(ib + s));
|
||||
auto r = partial_sum(rng, orng, std::minus<int>());
|
||||
CHECK(base(r.in) == ia + s);
|
||||
CHECK(base(r.out) == ib + s);
|
||||
for(unsigned i = 0; i < s; ++i)
|
||||
{
|
||||
CHECK(ib[i] == ir[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test<InputIterator<const int *>, InputIterator<int *>>();
|
||||
test<InputIterator<const int *>, ForwardIterator<int *>>();
|
||||
test<InputIterator<const int *>, BidirectionalIterator<int *>>();
|
||||
test<InputIterator<const int *>, RandomAccessIterator<int *>>();
|
||||
test<InputIterator<const int *>, int *>();
|
||||
|
||||
test<ForwardIterator<const int *>, InputIterator<int *>>();
|
||||
test<ForwardIterator<const int *>, ForwardIterator<int *>>();
|
||||
test<ForwardIterator<const int *>, BidirectionalIterator<int *>>();
|
||||
test<ForwardIterator<const int *>, RandomAccessIterator<int *>>();
|
||||
test<ForwardIterator<const int *>, int *>();
|
||||
|
||||
test<BidirectionalIterator<const int *>, InputIterator<int *>>();
|
||||
test<BidirectionalIterator<const int *>, ForwardIterator<int *>>();
|
||||
test<BidirectionalIterator<const int *>, BidirectionalIterator<int *>>();
|
||||
test<BidirectionalIterator<const int *>, RandomAccessIterator<int *>>();
|
||||
test<BidirectionalIterator<const int *>, int *>();
|
||||
|
||||
test<RandomAccessIterator<const int *>, InputIterator<int *>>();
|
||||
test<RandomAccessIterator<const int *>, ForwardIterator<int *>>();
|
||||
test<RandomAccessIterator<const int *>, BidirectionalIterator<int *>>();
|
||||
test<RandomAccessIterator<const int *>, RandomAccessIterator<int *>>();
|
||||
test<RandomAccessIterator<const int *>, int *>();
|
||||
|
||||
test<const int *, InputIterator<int *>>();
|
||||
test<const int *, ForwardIterator<int *>>();
|
||||
test<const int *, BidirectionalIterator<int *>>();
|
||||
test<const int *, RandomAccessIterator<int *>>();
|
||||
test<const int *, int *>();
|
||||
|
||||
using ranges::partial_sum;
|
||||
|
||||
{ // Test projections
|
||||
S ia[] = {{1}, {2}, {3}, {4}, {5}};
|
||||
int ir[] = {1, 3, 6, 10, 15};
|
||||
const unsigned s = sizeof(ir) / sizeof(ir[0]);
|
||||
int ib[s] = {0};
|
||||
auto r = partial_sum(ranges::begin(ia), ranges::begin(ia) + s, ranges::begin(ib),
|
||||
std::plus<int>(), &S::i);
|
||||
CHECK(base(r.in) == ia + s);
|
||||
CHECK(base(r.out) == ib + s);
|
||||
for(unsigned i = 0; i < s; ++i)
|
||||
{
|
||||
CHECK(ib[i] == ir[i]);
|
||||
}
|
||||
}
|
||||
|
||||
{ // Test BinaryOp
|
||||
int ia[] = {1, 2, 3, 4, 5};
|
||||
int ir[] = {1, 2, 6, 24, 120};
|
||||
const unsigned s = sizeof(ir) / sizeof(ir[0]);
|
||||
int ib[s] = {0};
|
||||
auto r = partial_sum(ia, ranges::begin(ib), std::multiplies<int>());
|
||||
CHECK(base(r.in) == ia + s);
|
||||
CHECK(base(r.out) == ib + s);
|
||||
for(unsigned i = 0; i < s; ++i)
|
||||
{
|
||||
CHECK(ib[i] == ir[i]);
|
||||
}
|
||||
}
|
||||
|
||||
{ // Test calling it with an array
|
||||
int ia[] = {1, 2, 3, 4, 5};
|
||||
int ir[] = {1, 2, 6, 24, 120};
|
||||
const unsigned s = sizeof(ir) / sizeof(ir[0]);
|
||||
int ib[s] = {0};
|
||||
auto r = partial_sum(ia, ib, std::multiplies<int>());
|
||||
CHECK(base(r.in) == ia + s);
|
||||
CHECK(base(r.out) == ib + s);
|
||||
for(unsigned i = 0; i < s; ++i)
|
||||
{
|
||||
CHECK(ib[i] == ir[i]);
|
||||
}
|
||||
}
|
||||
|
||||
{ // Test calling it with proxy iterators
|
||||
using namespace ranges;
|
||||
int ia[] = {1, 2, 3, 4, 5};
|
||||
int ib[] = {99, 99, 99, 99, 99};
|
||||
int ir[] = {1, 2, 6, 24, 120};
|
||||
const unsigned s = sizeof(ir) / sizeof(ir[0]);
|
||||
int ic[s] = {0};
|
||||
auto rng = views::zip(ia, ib);
|
||||
using CR = iter_common_reference_t<iterator_t<decltype(rng)>>;
|
||||
auto r = partial_sum(rng, ic, std::multiplies<int>(), [](CR p) {return p.first;});
|
||||
CHECK(base(r.in) == ranges::begin(rng) + s);
|
||||
CHECK(base(r.out) == ic + s);
|
||||
for(unsigned i = 0; i < s; ++i)
|
||||
{
|
||||
CHECK(ic[i] == ir[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return ::test_result();
|
||||
}
|
||||
Reference in New Issue
Block a user