Commit 89aabe3b authored by Anton Bukov's avatar Anton Bukov

Fix some issues

parent ecab6f46
......@@ -18,7 +18,7 @@ int src[] = {1,2,3,4,5,6,7,8};
auto dst = from(src).where( [](int a){return a%2 == 1;}) // 1,3,5,7
.select([](int a){return a*2;}) // 2,6,10,14
.where( [](int a){return a>2 && a<12;}) // 6,10
.toVector();
.toStdVector();
// dst type: std::vector<int>
// dst items: 6,10
......@@ -45,7 +45,7 @@ Man src[] =
auto dst = from(src).where( [](const Man & man){return man.age < 18;})
.orderBy([](const Man & man){return man.age;})
.select( [](const Man & man){return man.name;})
.toVector();
.toStdVector();
// dst type: std::vector<std::string>
// dst items: "Kevin", "Layer", "Agata"
......@@ -90,14 +90,20 @@ int DenisUniqueContactCount =
- cast&lt;T&gt;()
- take(int)
- takeWhile(int)
- takeWhile_i(int)
- skip(int)
- skipWhile(int)
- skipWhile_i(int)
- concat(range)
- where(lambda)
- where_i(lambda)
- select(lambda)
- select_i(lambda)
- selectMany(lambda)
- reverse()
- orderBy()
- orderBy(lambda)
- groupBy(lambda)
- distinct()
- distinct(lambda)
- for_each(lambda)
......@@ -114,14 +120,16 @@ int DenisUniqueContactCount =
- max()
- max(lambda)
- count()
- count(lambda)
- contains(value)
- elementAt(int)
- toSet()
- toList()
- toDeque()
- toVector()
- toContainer&lt;T&gt;()
- toStdSet()
- toStdList()
- toStdDeque()
- toStdVector()
#### Coming soon:
- groupBy(lambda)
#### Custom:
......@@ -138,10 +146,6 @@ int DenisUniqueContactCount =
- unbits&lt;T,BitOrder&gt;()
- unbits&lt;T,BitOrder,ByteOrder&gt;()
#### Coming soon:
- selectMany(lambda)
#### May be will be:
- gz()
......
......@@ -5,7 +5,9 @@
#include <iterator>
#include <iostream>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
//
......@@ -64,7 +66,7 @@ namespace boolinq {
void foreach(std::function<void(T)> apply) const
{
return foreach_i([apply](T &&value, int index) { return apply(value); });
return foreach_i([apply](T value, int index) { return apply(value); });
}
Linq<LinqIndex<S, T>, T> where_i(std::function<bool(T, int)> filter) const
......@@ -84,7 +86,7 @@ namespace boolinq {
Linq<LinqIndex<S, T>, T> where(std::function<bool(T)> filter) const
{
return where_i([filter](T &&value, int index) { return filter(value); });
return where_i([filter](T value, int index) { return filter(value); });
}
Linq<LinqIndex<S, T>, T> take(int count) const
......@@ -99,7 +101,7 @@ namespace boolinq {
Linq<LinqIndex<S, T>, T> takeWhile_i(std::function<bool(T, int)> predicate) const
{
return where_i([predicate](T &&value, int i) {
return where_i([predicate](T value, int i) {
if (!predicate(value, i)) {
throw LinqEndException();
}
......@@ -109,16 +111,18 @@ namespace boolinq {
Linq<LinqIndex<S, T>, T> takeWhile(std::function<bool(T)> predicate) const
{
return takeWhile_i([predicate](T &&value, int /*i*/) { return predicate(value); });
return takeWhile_i([predicate](T value, int /*i*/) { return predicate(value); });
}
Linq<LinqIndex<S, T>, T> skip(int count) const
{
return where_i([count](T &&value, int i) { return i >= count; });
return where_i([count](T value, int i) { return i >= count; });
}
template<typename SS, typename TT>
struct LinqIndexFlag : public LinqIndex<SS, TT> {
struct LinqIndexFlag {
Linq<SS, TT> linq;
int index;
bool flag;
};
......@@ -142,7 +146,7 @@ namespace boolinq {
Linq<LinqIndexFlag<S, T>, T> skipWhile(std::function<bool(T)> predicate) const
{
return skipWhile_i([predicate](T &&value, int /*i*/) { return predicate(value); });
return skipWhile_i([predicate](T value, int /*i*/) { return predicate(value); });
}
template<typename F, typename _TRet = typename std::result_of<F(T, int)>::type>
......@@ -159,13 +163,37 @@ namespace boolinq {
template<typename F, typename _TRet = typename std::result_of<F(T)>::type>
auto select(F apply) const -> Linq<LinqIndex<S, T>, _TRet>
{
return select_i([apply](T &&value, int index) { return apply(value); });
return select_i([apply](T value, int /*index*/) { return apply(value); });
}
template<typename TRet>
Linq<LinqIndex<S, T>, TRet> cast() const
{
return select([](T &&value) { return TRet(value); });
return select_i([](T value, int /*i*/) { return TRet(value); });
}
template<typename S1, typename T1, typename S2, typename T2>
struct LinqLinq {
Linq<S1, T1> first;
Linq<S2, T2> second;
bool flag;
};
template<typename S2, typename T2>
Linq<LinqLinq<S, T, S2, T2>, T> concat(const Linq<S2, T2> & rhs) const
{
return Linq<LinqLinq<S, T, S2, T2>, T>(
{*this, rhs, false},
[](auto & tuple){
if (!tuple.flag) {
try {
return tuple.first.next();
}
catch (LinqEndException &) {}
}
return tuple.second.next();
}
);
}
template<typename SS, typename TT, typename TCurrent>
......@@ -203,7 +231,7 @@ namespace boolinq {
auto selectMany(F apply) const
-> Linq<LinqCurrentIndexFinished<S, T, _TRet>, typename _TRet::value_type>
{
return selectMany_i([apply](T &&value, int index) { return apply(value); });
return selectMany_i([apply](T value, int index) { return apply(value); });
}
template<typename SS, typename TT, typename TTRet2>
......@@ -212,11 +240,11 @@ namespace boolinq {
std::unordered_set<TTRet2> set;
};
template<typename TRet>
Linq<LinqUnorderedSet<S, T, TRet>, T> distinct(std::function<TRet(T)> transform) const
template<typename F, typename _TRet = typename std::result_of<F(T)>::type>
auto distinct(F transform) const -> Linq<LinqUnorderedSet<S, T, _TRet>, T>
{
return Linq<LinqUnorderedSet<S, T, TRet>, T>(
{*this, std::unordered_set<TRet>()},
return Linq<LinqUnorderedSet<S, T, _TRet>, T>(
{*this, std::unordered_set<_TRet>()},
[transform](auto &tuple) {
while (true) {
T value = tuple.linq.next();
......@@ -230,7 +258,7 @@ namespace boolinq {
Linq<LinqUnorderedSet<S, T, T>, T> distinct() const
{
return distinct([](T &&value) { return value; });
return distinct([](T value) { return value; });
}
template<typename TT>
......@@ -265,7 +293,7 @@ namespace boolinq {
Linq<StdVectorAndIterator<T>, T> orderBy() const
{
return orderBy([](T &&value) { return value; });
return orderBy([](T value) { return value; });
}
template<typename TT>
......@@ -310,9 +338,9 @@ namespace boolinq {
}
template<typename F>
auto sum(F transform) const -> typename std::result_of<F(T, T)>::type
auto sum(F transform) const -> typename std::result_of<F(T)>::type
{
return aggregate<T>(T(), [transform](T accumulator, T &&value) {
return aggregate<T>(T(), [transform](T accumulator, T value) {
return accumulator + transform(value);
});
}
......@@ -327,7 +355,7 @@ namespace boolinq {
auto avg(F transform) const -> typename std::result_of<F(T)>::type
{
int count = 0;
T res = sum([transform, &count](T &&value) {
T res = sum([transform, &count](T value) {
count++;
return transform(value);
});
......@@ -343,7 +371,7 @@ namespace boolinq {
int count() const
{
int index = 0;
foreach([&index](T &&/**/a) { index++; });
foreach([&index](T /**/a) { index++; });
return index;
}
......@@ -354,7 +382,7 @@ namespace boolinq {
int count(const T &item) const
{
return count([item](T &&value) { return item == value; });
return count([item](T value) { return item == value; });
}
// Bool aggregators
......@@ -364,7 +392,7 @@ namespace boolinq {
Linq<S, T> linq = *this;
try {
while (true) {
if (predicate(linq.nextObject()))
if (predicate(linq.next()))
return true;
}
}
......@@ -374,22 +402,22 @@ namespace boolinq {
bool any() const
{
return any([](T &&value) { return static_cast<bool>(value); });
return any([](T value) { return static_cast<bool>(value); });
}
bool all(std::function<bool(T)> predicate) const
{
return !any([predicate](T &&value) { return !predicate(value); });
return !any([predicate](T value) { return !predicate(value); });
}
bool all() const
{
return all([](T &&value) { return static_cast<bool>(value); });
return all([](T value) { return static_cast<bool>(value); });
}
bool contains(const T &item) const
{
return any([&item](T &&value) { return value == item; });
return any([&item](T value) { return value == item; });
}
// Election aggregators
......@@ -418,7 +446,7 @@ namespace boolinq {
T max() const
{
return max([](T &&value) { return value; });
return max([](T value) { return value; });
}
template<typename F>
......@@ -431,7 +459,7 @@ namespace boolinq {
T min() const
{
return min([](T &&value) { return value; });
return min([](T value) { return value; });
}
// Single object returners
......@@ -462,13 +490,13 @@ namespace boolinq {
T firstOrDefault() const
{
firstOrDefault([](T &&/*value*/) { return true; });
firstOrDefault([](T /*value*/) { return true; });
}
T last(std::function<bool(T)> predicate) const
{
T res;
foreach([&res](T &&value) {
foreach([&res](T value) {
res = value;
});
return res;
......@@ -476,7 +504,7 @@ namespace boolinq {
T last() const
{
return last([](T &&/*value*/) { return true; });
return last([](T /*value*/) { return true; });
}
T lastOrDefault(std::function<bool(T)> predicate) const
......@@ -490,7 +518,7 @@ namespace boolinq {
T lastOrDefault() const
{
return lastOrDefault([](T && /*value*/) { return true; });
return lastOrDefault([](T /*value*/) { return true; });
}
// Export to containers
......@@ -498,7 +526,7 @@ namespace boolinq {
std::vector<T> toStdVector() const
{
std::vector<T> items;
foreach([&items](T &&value) {
foreach([&items](T value) {
items.push_back(value);
});
return items;
......@@ -507,12 +535,39 @@ namespace boolinq {
std::list<T> toStdList() const
{
std::list<T> items;
foreach([&items](T &&value) {
foreach([&items](T value) {
items.push_back(value);
});
return items;
}
std::deque<T> toStdDeque() const
{
std::deque<T> items;
foreach([&items](T value) {
items.push_back(value);
});
return items;
}
std::set<T> toStdSet() const
{
std::set<T> items;
foreach([&items](T value) {
items.insert(value);
});
return items;
}
std::unordered_set<T> toStdUnorderedSet() const
{
std::unordered_set<T> items;
foreach([&items](T value) {
items.insert(value);
});
return items;
}
// Bits and bytes
template<typename SS, typename TT>
......@@ -550,7 +605,7 @@ namespace boolinq {
template<typename TRet>
Linq<LinqBytesBitsValueIndex<S, T>, TRet> unbytes(BytesDirection direction = BytesFirstToLast) const
{
return Linq<LinqBytesBitsValueIndex<S, T>, int>(
return Linq<LinqBytesBitsValueIndex<S, T>, TRet>(
{*this, direction, BitsHighToLow, T(), 0},
[](auto & tuple) {
TRet value;
......@@ -598,10 +653,10 @@ namespace boolinq {
);
}
template<typename TRet>
template<typename TRet = uint8_t>
Linq<LinqBytesBitsValueIndex<S, T>, TRet> unbits(BitsDirection bitsDir = BitsHighToLow, BytesDirection bytesDir = BytesFirstToLast) const
{
return Linq<LinqBytesBitsValueIndex<S, T>, int>(
return Linq<LinqBytesBitsValueIndex<S, T>, TRet>(
{*this, bytesDir, bitsDir, T(), 0},
[](auto & tuple) {
TRet value;
......@@ -649,16 +704,16 @@ namespace boolinq {
return Linq<std::pair<T, T>, typename std::iterator_traits<T>::value_type>(
{begin, end},
[](auto &pair) {
if (pair.first < pair.second) {
return *(pair.first++);
}
if (pair.first == pair.second) {
throw LinqEndException();
}
return *(pair.first++);
}
);
}
template<typename T>
Linq<std::pair<T, T>, T> from(T it, int n)
Linq<std::pair<T, T>, typename std::iterator_traits<T>::value_type> from(T it, int n)
{
return from(it, it + n);
}
......
......@@ -36,13 +36,13 @@ namespace boolinq
public:
typedef T value_type;
Enumerator(std::function<T(S&)> nextObject, S data)
: _nextObject(nextObject)
Enumerator(std::function<T(S&)> next, S data)
: _nextObject(next)
, _data(data)
{
}
T nextObject()
T next()
{
return _nextObject(_data);
}
......@@ -57,7 +57,7 @@ namespace boolinq
if (i > 0) {
stream << ' ';
}
stream << enumerator.nextObject();
stream << enumerator.next();
}
}
catch(LinqEndException &) {}
......@@ -133,9 +133,9 @@ namespace boolinq
{
}
T nextObject()
T next()
{
return _enumerator.nextObject();
return _enumerator.next();
}
// Main methods
......@@ -147,7 +147,7 @@ namespace boolinq
try
{
for (;;)
action(en.nextObject(), index++);
action(en.next(), index++);
}
catch(LinqEndException &) {}
}
......@@ -162,7 +162,7 @@ namespace boolinq
return Enumerator<T,std::pair<TE,int> >([=](std::pair<TE,int> & pair)->T{
T object;
do
object = pair.first.nextObject();
object = pair.first.next();
while (!predicate(object, pair.second++));
return object;
}, std::make_pair(_enumerator,0));
......@@ -186,7 +186,7 @@ namespace boolinq
LinqObj<Enumerator<T,std::pair<TE,int> > > takeWhile_i(std::function<bool(T,int)> predicate) const
{
return Enumerator<T,std::pair<TE,int> >([=](std::pair<TE,int> & pair)->T{
T object = pair.first.nextObject();
T object = pair.first.next();
if (!predicate(object,pair.second++)) {
throw LinqEndException();
}
......@@ -208,12 +208,12 @@ namespace boolinq
{
return Enumerator<T,std::pair<TE,int> >([=](std::pair<TE,int> & pair)->T{
if (pair.second != 0) {
return pair.first.nextObject();
return pair.first.next();
}
T object;
do {
object = pair.first.nextObject();
object = pair.first.next();
} while (predicate(object,pair.second++));
return object;
......@@ -229,7 +229,7 @@ namespace boolinq
LinqObj<Enumerator<TRet,std::pair<TE,int> > > select_i(std::function<TRet(T,int)> transform) const
{
return Enumerator<TRet,std::pair<TE,int> >([=](std::pair<TE,int> & pair)->TRet{
return transform(pair.first.nextObject(), pair.second++);
return transform(pair.first.next(), pair.second++);
}, std::make_pair(_enumerator,0));
}
......@@ -264,7 +264,7 @@ namespace boolinq
return Enumerator<T,DataType>([=](DataType & pair)->T{
for (;;) {
T object = pair.first.nextObject();
T object = pair.first.next();
TRet key = transform(object);
if (pair.second.find(key) == pair.second.end()) {
pair.second.insert(key);
......@@ -316,7 +316,7 @@ namespace boolinq
{
auto en = _enumerator;
for (;;) {
objects.insert(en.nextObject());
objects.insert(en.next());
}
}
catch(LinqEndException &) {}
......@@ -351,7 +351,7 @@ namespace boolinq
{
return (pair.first == pair.second.crend())
? throw LinqEndException() : *(pair.first++);
}, DataType(toVector(), [](const std::vector<T> & vec){return vec.crbegin();}));
}, DataType(toStdVector(), [](const std::vector<T> & vec){return vec.crbegin();}));
}
// Aggregators
......@@ -363,7 +363,7 @@ namespace boolinq
{
auto en = _enumerator;
for (;;)
start = accumulate(start, en.nextObject());
start = accumulate(start, en.next());
}
catch(LinqEndException &) {}
return start;
......@@ -444,7 +444,7 @@ namespace boolinq
{
auto en = _enumerator;
for (;;)
if (predicate(en.nextObject()))
if (predicate(en.next()))
return true;
}
catch(LinqEndException &) {}
......@@ -476,11 +476,11 @@ namespace boolinq
T elect(std::function<T(T,T)> accumulate) const
{
auto en = _enumerator;
T result = en.nextObject();
T result = en.next();
try
{
for (;;)
result = accumulate(result, en.nextObject());
result = accumulate(result, en.next());
}
catch(LinqEndException &) {}
return result;
......@@ -526,13 +526,13 @@ namespace boolinq
{
auto en = _enumerator;
for (int i = 0; i < index; i++)
en.nextObject();
return en.nextObject();
en.next();
return en.next();
}
T first(std::function<bool(T)> predicate) const
{
return where(predicate)._enumerator.nextObject();
return where(predicate)._enumerator.next();
}
T first() const
......@@ -555,8 +555,8 @@ namespace boolinq
T last(std::function<bool(T)> predicate) const
{
auto linq = where(predicate);
T object = linq._enumerator.nextObject();
try { for (;;) object = linq._enumerator.nextObject(); }
T object = linq._enumerator.next();
try { for (;;) object = linq._enumerator.next(); }
catch(LinqEndException &) { return object; }
}
......@@ -585,12 +585,12 @@ namespace boolinq
return Enumerator<T,DataType>([=](DataType & pair)->T{
if (pair.first)
return pair.second.second.nextObject();
try { return pair.second.first.nextObject(); }
return pair.second.second.next();
try { return pair.second.first.next(); }
catch(LinqEndException &)
{
pair.first = true;
return pair.second.second.nextObject();
return pair.second.second.next();
}
}, std::make_pair(false, std::make_pair(_enumerator, rhs._enumerator)));
}
......@@ -606,7 +606,7 @@ namespace boolinq
{
auto en = _enumerator;
for (;;)
func(container, en.nextObject());
func(container, en.next());
}
catch(LinqEndException &) {}
return container;
......@@ -614,28 +614,28 @@ namespace boolinq
public:
std::vector<T> toVector() const
std::vector<T> toStdVector() const
{
return exportToContainer<std::vector<T> >([](std::vector<T> &container, const T &value){
container.push_back(value);
});
}
std::list<T> toList() const
std::list<T> toStdList() const
{
return exportToContainer<std::list<T> >([](std::list<T> &container, const T &value){
container.push_back(value);
});
}
std::deque<T> toDeque() const
std::deque<T> toStdDeque() const
{
return exportToContainer<std::deque<T> >([](std::deque<T> &container, const T &value){
container.push_back(value);
});
}
std::set<T> toSet() const
std::set<T> toStdSet() const
{
return exportToContainer<std::set<T> >([](std::set<T> &container, const T &value){
container.insert(value);
......@@ -649,14 +649,14 @@ namespace boolinq
typedef std::pair<int,std::pair<TE,T> > DataType;
auto pair = std::make_pair(_enumerator, T());
pair.second = pair.first.nextObject();
pair.second = pair.first.next();
return Enumerator<int,DataType>([=](DataType & pair_)->int{
if ((direction == BytesFirstToLast && pair_.first == sizeof(T))
|| (direction == BytesLastToFirst && pair_.first == -1))
{
pair_.first = (direction == BytesFirstToLast) ? 0 : sizeof(T)-1;
pair_.second.second = pair_.second.first.nextObject();
pair_.second.second = pair_.second.first.next();
}
unsigned char * ptr = reinterpret_cast<unsigned char *>(&pair_.second.second);
int value = ptr[pair_.first];
......@@ -675,7 +675,7 @@ namespace boolinq
i != ((direction == BytesFirstToLast) ? int(sizeof(TRet)) : -1);
i += (direction == BytesFirstToLast) ? 1 : -1)
{
ptr[i] = en.nextObject();
ptr[i] = en.next();
}
return object;
}, _enumerator);
......@@ -692,13 +692,13 @@ namespace boolinq
|| (direction == BitsHighToLow && pair.first == -1))
{
pair.first = (direction == BitsLowToHigh) ? 0 : CHAR_BIT-1;
pair.second.second = static_cast<unsigned char>(pair.second.first.nextObject());
pair.second.second = static_cast<unsigned char>(pair.second.first.next());
}
int value = 1 & (pair.second.second >> (pair.first % CHAR_BIT));
pair.first += (direction == BitsLowToHigh) ? 1 : -1;
return value;
}, std::make_pair((direction == BitsLowToHigh) ? 0 : CHAR_BIT-1,
std::make_pair(inner, inner.nextObject())));
std::make_pair(inner, inner.next())));
}
LinqObj<Enumerator<unsigned char,TE> > unbits(BitsDirection direction = BitsHighToLow) const
......@@ -709,7 +709,7 @@ namespace boolinq
i != ((direction == BitsLowToHigh) ? CHAR_BIT : -1);
i += (direction == BitsLowToHigh) ? 1 : -1)
{
object |= (en.nextObject() << i);
object |= (en.next() << i);
}
return object;
}, _enumerator);
......
......@@ -14,18 +14,18 @@ template<typename R, typename T, unsigned N, typename F>
void CheckRangeEqArray(R dst, T (&ans)[N], F f)
{
for (unsigned i = 0; i < N; i++)
EXPECT_EQ(f(ans[i]), f(dst.nextObject()));
EXPECT_EQ(f(ans[i]), f(dst.next()));
EXPECT_THROW(dst.nextObject(), LinqEndException);
EXPECT_THROW(dst.next(), LinqEndException);
}
template<typename R, typename T, unsigned N>
void CheckRangeEqArray(R dst, T (&ans)[N])
{
for (unsigned i = 0; i < N; i++)
EXPECT_EQ(ans[i], dst.nextObject());
EXPECT_EQ(ans[i], dst.next());
EXPECT_THROW(dst.nextObject(), LinqEndException);
EXPECT_THROW(dst.next(), LinqEndException);
}
template<typename T, unsigned N>
......@@ -44,7 +44,7 @@ template<typename R, typename T, unsigned N>
void CheckRangeEqSet(R dst, T (&ans)[N])
{
std::set<T> expected = ArrayToSet(ans);
std::set<typename R::value_type> actual = dst.toSet();
std::set<typename R::value_type> actual = dst.toStdSet();
EXPECT_EQ(expected.size(), actual.size());
......
......@@ -41,7 +41,7 @@ TEST(GroupByRange, IntsFront)
CheckRangeEqArray(dst.back(), ans_0);
CheckRangeEqArray(dst.popFront(), ans_0);
EXPECT_THROW(dst.nextObject(), LinqEndException);
EXPECT_THROW(dst.next(), LinqEndException);
}
TEST(GroupByRange, IntsBack)
......@@ -73,7 +73,7 @@ TEST(GroupByRange, IntsBack)
CheckRangeEqArray(dst.back(), ans_1);
CheckRangeEqArray(dst.popBack(), ans_1);
EXPECT_THROW(dst.nextObject(), LinqEndException);
EXPECT_THROW(dst.next(), LinqEndException);
}
//////////////////////////////////////////////////////////////////////////
......@@ -126,7 +126,7 @@ TEST(GroupByRange, CountChildrenByAge)
CheckRangeEqArray(dst.back(), ans_true);
CheckRangeEqArray(dst.popFront(), ans_true);
EXPECT_THROW(dst.nextObject(), LinqEndException);
EXPECT_THROW(dst.next(), LinqEndException);
}
*/
......@@ -27,8 +27,8 @@ TEST(IterRange, ListInt)
int ans[] = {1,2,3,4,5};
CheckRangeEqArray(from(lst), ans);
CheckRangeEqArray(from<int>(lst.begin(), lst.end()), ans);
CheckRangeEqArray(from<int>(lst.cbegin(), lst.cend()), ans);
CheckRangeEqArray(from(lst.begin(), lst.end()), ans);
CheckRangeEqArray(from(lst.cbegin(), lst.cend()), ans);
}
TEST(IterRange, DequeInt)
......@@ -43,8 +43,8 @@ TEST(IterRange, DequeInt)
int ans[] = {1,2,3,4,5};
CheckRangeEqArray(from(dck), ans);
CheckRangeEqArray(from<int>(dck.begin(), dck.end()), ans);
CheckRangeEqArray(from<int>(dck.cbegin(), dck.cend()), ans);
CheckRangeEqArray(from(dck.begin(), dck.end()), ans);
CheckRangeEqArray(from(dck.cbegin(), dck.cend()), ans);
}
TEST(IterRange, VectorInt)
......@@ -59,8 +59,8 @@ TEST(IterRange, VectorInt)
int ans[] = {1,2,3,4,5};
CheckRangeEqArray(from(vec), ans);
CheckRangeEqArray(from<int>(vec.begin(), vec.end()), ans);
CheckRangeEqArray(from<int>(vec.cbegin(), vec.cend()), ans);
CheckRangeEqArray(from(vec.begin(), vec.end()), ans);
CheckRangeEqArray(from(vec.cbegin(), vec.cend()), ans);
}
TEST(IterRange, SetInt)
......@@ -69,22 +69,22 @@ TEST(IterRange, SetInt)
int ans[] = {1,2,3,4,5};
CheckRangeEqSet(from(set), ans);
CheckRangeEqSet(from<int>(set.begin(), set.end()), ans);
CheckRangeEqSet(from<int>(set.cbegin(), set.cend()), ans);
CheckRangeEqSet(from(set.begin(), set.end()), ans);
CheckRangeEqSet(from(set.cbegin(), set.cend()), ans);
}
TEST(IterRange, MapInt)
{
std::map<int, int> map = {{5,1},{4,2},{3,3},{2,4},{1,5}};
std::pair<int, int> ans[] = {{5,1},{4,2},{3,3},{2,4},{1,5}};
CheckRangeEqArray(from(map)
.orderBy([](std::pair<int,int> p){ return p.second; }), ans);
CheckRangeEqArray(from<std::pair<int,int> >(map.begin(), map.end())
.orderBy([](std::pair<int,int> p){ return p.second; }), ans);
CheckRangeEqArray(from<std::pair<int,int> >(map.cbegin(), map.cend())
.orderBy([](std::pair<int,int> p){ return p.second; }), ans);
}
//TEST(IterRange, MapInt)
//{
// std::map<int, int> map = {{5,1},{4,2},{3,3},{2,4},{1,5}};
// std::pair<int, int> ans[] = {{5,1},{4,2},{3,3},{2,4},{1,5}};
//
// CheckRangeEqArray(from(map)
// .orderBy([](std::pair<int,int> p){ return p.second; }), ans);
// CheckRangeEqArray(from(map.begin(), map.end())
// .orderBy([](std::pair<int,int> p){ return p.second; }), ans);
// CheckRangeEqArray(from(map.cbegin(), map.cend())
// .orderBy([](std::pair<int,int> p){ return p.second; }), ans);
//}
TEST(IterRange, StdArrayInt)
{
......@@ -92,8 +92,8 @@ TEST(IterRange, StdArrayInt)
int ans[] = {1,2,3,4,5};
CheckRangeEqArray(from(arr), ans);
CheckRangeEqArray(from<int>(arr.begin(), arr.end()), ans);
CheckRangeEqArray(from<int>(arr.cbegin(), arr.cend()), ans);
CheckRangeEqArray(from(arr.begin(), arr.end()), ans);
CheckRangeEqArray(from(arr.cbegin(), arr.cend()), ans);
}
TEST(IterRange, ArrayInt)
......@@ -104,8 +104,8 @@ TEST(IterRange, ArrayInt)
int ans[] = {1,2,3,4,5};
CheckRangeEqArray(from(arr), ans);
CheckRangeEqArray(from<int>(ptr, 5), ans);
CheckRangeEqArray(from<int>(ptr, ptr+5), ans);
CheckRangeEqArray(from(ptr, 5), ans);
CheckRangeEqArray(from(ptr, ptr + 5), ans);
}
//////////////////////////////////////////////////////////////////////////
......@@ -126,5 +126,5 @@ TEST(IterRange, EmptyVector)
auto rng = from(src);
EXPECT_THROW(rng.nextObject(), LinqEndException);
EXPECT_THROW(rng.next(), LinqEndException);
}
......@@ -25,10 +25,10 @@ TEST(Linq, WhereOdd)
for (int i = 1; i <= 5; i+=2)
{
EXPECT_EQ(i, rng.nextObject());
EXPECT_EQ(i, rng.next());
}
EXPECT_THROW(rng.nextObject(), LinqEndException);
EXPECT_THROW(rng.next(), LinqEndException);
}
TEST(Linq, WhereOdd_WhereLess)
......@@ -48,10 +48,10 @@ TEST(Linq, WhereOdd_WhereLess)
for (int i = 1; i <= 3; i+=2)
{
EXPECT_EQ(i, rng.nextObject());
EXPECT_EQ(i, rng.next());
}
EXPECT_THROW(rng.nextObject(), LinqEndException);
EXPECT_THROW(rng.next(), LinqEndException);
}
TEST(Linq, WhereLess_WhereOdd)
......@@ -68,7 +68,7 @@ TEST(Linq, WhereLess_WhereOdd)
auto rng = from(src).where([](int a){return a < 4;})
.where([](int a){return a%2 == 1;})
.toVector();
.toStdVector();
std::vector<int> ans;
ans.push_back(1);
......@@ -92,7 +92,7 @@ TEST(Linq, WhereLess_WhereOdd_OrderByDesc)
auto rng = from(src).where([](int a){return a < 6;})
.where([](int a){return a%2 == 1;})
.orderBy([](int a){return -a;})
.toVector();
.toStdVector();
std::vector<int> ans;
ans.push_back(5);
......@@ -115,7 +115,7 @@ TEST(Linq, WhereOdd_ToVector)
src.push_back(8);
auto dst = from(src).where([](int a){return a%2 == 1;})
.toVector();
.toStdVector();
std::vector<int> ans;
ans.push_back(1);
......@@ -141,7 +141,7 @@ TEST(Linq, WhereOdd_WhereLess_SelectMul2_ToVector)
auto dst = from(src).where([](int a){return a%2 == 1;})
.where([](int a){return a < 6;})
.select([](int a){return a*2;})
.toVector();
.toStdVector();
std::vector<int> ans;
ans.push_back(2);
......@@ -167,7 +167,7 @@ TEST(Linq, WhereOdd_WhereLess_SelectMul2_Reverse_ToVector)
.where([](int a){return a < 6;})
.select([](int a){return a*2;})
.reverse()
.toVector();
.toStdVector();
std::vector<int> ans;
ans.push_back(10);
......@@ -193,7 +193,7 @@ TEST(Linq, WhereOdd_Reverse_Reverse)
.reverse()
.where([](int a){return a < 4;})
.reverse()
.toVector();
.toStdVector();
std::vector<int> ans;
ans.push_back(1);
......@@ -208,14 +208,14 @@ TEST(Linq, Pointer_Front)
{
int src[] = {1,2,3,4,5};
auto dst = from<int>(static_cast<int *>(src), static_cast<int *>(src) + 5);
auto dst = from(static_cast<int *>(src), static_cast<int *>(src) + 5);
for(int i = 1; i <= 5; i++)
{
EXPECT_EQ(i, dst.nextObject());
EXPECT_EQ(i, dst.next());
}
EXPECT_THROW(dst.nextObject(), LinqEndException);
EXPECT_THROW(dst.next(), LinqEndException);
}
......@@ -229,10 +229,10 @@ TEST(Linq, Array_Front)
for(int i = 1; i <= 5; i++)
{
EXPECT_EQ(i, dst.nextObject());
EXPECT_EQ(i, dst.next());
}
EXPECT_THROW(dst.nextObject(), LinqEndException);
EXPECT_THROW(dst.next(), LinqEndException);
}
//////////////////////////////////////////////////////////////////////////
......@@ -253,12 +253,12 @@ TEST(Linq, Creations)
auto dst_vec = from(vec);
auto dst_arr = from(arr);
//auto dst_carr = from(carr);
auto dst_ptr = from<int>(ptr, ptr+5);
//auto dst_cptr = from<const int>(cptr, cptr+5);
auto dst_ptr_length = from<int>(ptr, 5);
//auto dst_cptr_length = from<const int>(cptr, 5);
auto dst_vec_iter = from<int>(vec.begin(), vec.end());
//auto dst_vec_citer = from<const int>(vec.cbegin(), vec.cend());
auto dst_ptr = from(ptr, ptr+5);
//auto dst_cptr = from(cptr, cptr+5);
auto dst_ptr_length = from(ptr, 5);
//auto dst_cptr_length = from(cptr, 5);
auto dst_vec_iter = from(vec.begin(), vec.end());
//auto dst_vec_citer = from(vec.cbegin(), vec.cend());
}
//////////////////////////////////////////////////////////////////////////
......@@ -301,7 +301,7 @@ TEST(Linq, MessagesCountUniqueContacts)
TEST(Linq, ForwardIterating)
{
std::stringstream stream("0123456789");
auto dst = from<char>(std::istream_iterator<char>(stream),
auto dst = from(std::istream_iterator<char>(stream),
std::istream_iterator<char>())
.where( [](char a){return a % 2 == 0;})
.select([](char a){return std::string(1,a);})
......
......@@ -63,7 +63,7 @@ TEST(OrderByRange, NoElements)
auto rng = from(src);
auto dst = rng.orderBy();
EXPECT_THROW(dst.nextObject(), LinqEndException);
EXPECT_THROW(dst.next(), LinqEndException);
}
//////////////////////////////////////////////////////////////////////////
......
......@@ -50,7 +50,7 @@ TEST(SkipRange, ManyToZero)
auto rng = from(src);
auto dst = rng.skip(6);
EXPECT_THROW(dst.nextObject(), LinqEndException);
EXPECT_THROW(dst.next(), LinqEndException);
}
TEST(SkipRange, ManyToZeroLess)
......@@ -60,7 +60,7 @@ TEST(SkipRange, ManyToZeroLess)
auto rng = from(src);
auto dst = rng.skip(10);
EXPECT_THROW(dst.nextObject(), LinqEndException);
EXPECT_THROW(dst.next(), LinqEndException);
}
//////////////////////////////////////////////////////////////////////////
......@@ -83,7 +83,7 @@ TEST(SkipRange, OneToZero)
auto rng = from(src);
auto dst = rng.skip(1);
EXPECT_THROW(dst.nextObject(), LinqEndException);
EXPECT_THROW(dst.next(), LinqEndException);
}
TEST(SkipRange, OneToZeroLess)
......@@ -93,7 +93,7 @@ TEST(SkipRange, OneToZeroLess)
auto rng = from(src);
auto dst = rng.skip(2);
EXPECT_THROW(dst.nextObject(), LinqEndException);
EXPECT_THROW(dst.next(), LinqEndException);
}
TEST(SkipRange, ZeroToZero)
......@@ -103,7 +103,7 @@ TEST(SkipRange, ZeroToZero)
auto rng = from(src);
auto dst = rng.skip(0);
EXPECT_THROW(rng.nextObject(), LinqEndException);
EXPECT_THROW(rng.next(), LinqEndException);
}
TEST(SkipRange, ZeroToZeroLess)
......@@ -113,7 +113,7 @@ TEST(SkipRange, ZeroToZeroLess)
auto rng = from(src);
auto dst = rng.skip(2);
EXPECT_THROW(rng.nextObject(), LinqEndException);
EXPECT_THROW(rng.next(), LinqEndException);
}
//////////////////////////////////////////////////////////////////////////
......@@ -194,7 +194,7 @@ TEST(SkipWhileRange, ManyToZero)
auto rng = from(src);
auto dst = rng.skipWhile([](int it){return it > 0;});
EXPECT_THROW(dst.nextObject(), LinqEndException);
EXPECT_THROW(dst.next(), LinqEndException);
}
TEST(SkipWhileRange_i, ManyToZeroeByIndex)
......@@ -204,7 +204,7 @@ TEST(SkipWhileRange_i, ManyToZeroeByIndex)
auto rng = from(src);
auto dst = rng.skipWhile_i([](int /*it*/, int idx){return idx < 6;});
EXPECT_THROW(dst.nextObject(), LinqEndException);
EXPECT_THROW(dst.next(), LinqEndException);
}
TEST(SkipWhileRange_i, ManyToZeroByItemValue)
......@@ -214,7 +214,7 @@ TEST(SkipWhileRange_i, ManyToZeroByItemValue)
auto rng = from(src);
auto dst = rng.skipWhile_i([](int it, int /*idx*/){return it > 0;});
EXPECT_THROW(dst.nextObject(), LinqEndException);
EXPECT_THROW(dst.next(), LinqEndException);
}
TEST(SkipWhileRange_i, ManyToZeroIndexAndItemValue)
......@@ -224,7 +224,7 @@ TEST(SkipWhileRange_i, ManyToZeroIndexAndItemValue)
auto rng = from(src);
auto dst = rng.skipWhile_i([](int it, int idx){return idx != it;});
EXPECT_THROW(dst.nextObject(), LinqEndException);
EXPECT_THROW(dst.next(), LinqEndException);
}
//////////////////////////////////////////////////////////////////////////
......@@ -280,7 +280,7 @@ TEST(SkipWhileRange, OneToZero)
auto rng = from(src);
auto dst = rng.skipWhile([](int it){return it == 5;});
EXPECT_THROW(dst.nextObject(), LinqEndException);
EXPECT_THROW(dst.next(), LinqEndException);
}
TEST(SkipWhileRange_i, OneToZeroByIndex)
......@@ -290,7 +290,7 @@ TEST(SkipWhileRange_i, OneToZeroByIndex)
auto rng = from(src);
auto dst = rng.skipWhile_i([](int /*it*/, int idx){return idx < 6;});
EXPECT_THROW(dst.nextObject(), LinqEndException);
EXPECT_THROW(dst.next(), LinqEndException);
}
TEST(SkipWhileRange_i, OneToZeroByItemValue)
......@@ -300,7 +300,7 @@ TEST(SkipWhileRange_i, OneToZeroByItemValue)
auto rng = from(src);
auto dst = rng.skipWhile_i([](int it, int /*idx*/){return it > 0;});
EXPECT_THROW(dst.nextObject(), LinqEndException);
EXPECT_THROW(dst.next(), LinqEndException);
}
TEST(SkipWhileRange_i, OneToZeroIndexAndItemValue)
......@@ -310,7 +310,7 @@ TEST(SkipWhileRange_i, OneToZeroIndexAndItemValue)
auto rng = from(src);
auto dst = rng.skipWhile_i([](int it, int idx){return idx != it;});
EXPECT_THROW(dst.nextObject(), LinqEndException);
EXPECT_THROW(dst.next(), LinqEndException);
}
TEST(SkipWhileRange, ZeroToZero)
......@@ -320,7 +320,7 @@ TEST(SkipWhileRange, ZeroToZero)
auto rng = from(src);
auto dst = rng.skipWhile([](int){return false;});
EXPECT_THROW(rng.nextObject(), LinqEndException);
EXPECT_THROW(rng.next(), LinqEndException);
}
TEST(SkipWhileRange_i, ZeroToZero)
......@@ -330,7 +330,7 @@ TEST(SkipWhileRange_i, ZeroToZero)
auto rng = from(src);
auto dst = rng.skipWhile_i([](int /*it*/, int /*idx*/){return true;});
EXPECT_THROW(rng.nextObject(), LinqEndException);
EXPECT_THROW(rng.next(), LinqEndException);
}
//////////////////////////////////////////////////////////////////////////
......@@ -45,8 +45,8 @@ TEST(Sum, BoolSum)
src.push_back(4);
src.push_back(5);
auto rng1 = from(src).sum<int>([](int a){return a%2 == 0;});
auto rng2 = from(src).sum<int>([](int a){return a%2 == 1;});
auto rng1 = from(src).sum([](int a){return a%2 == 0;});
auto rng2 = from(src).sum([](int a){return a%2 == 1;});
EXPECT_EQ(2, rng1);
EXPECT_EQ(3, rng2);
......
......@@ -61,7 +61,7 @@ TEST(TakeRange, ManyToZero)
auto rng = from(src);
auto dst = rng.take(0);
EXPECT_THROW(dst.nextObject(), LinqEndException);
EXPECT_THROW(dst.next(), LinqEndException);
}
//////////////////////////////////////////////////////////////////////////
......@@ -95,7 +95,7 @@ TEST(TakeRange, OneToZero)
auto rng = from(src);
auto dst = rng.take(0);
EXPECT_THROW(dst.nextObject(), LinqEndException);
EXPECT_THROW(dst.next(), LinqEndException);
}
TEST(TakeRange, ZeroToZero)
......@@ -105,7 +105,7 @@ TEST(TakeRange, ZeroToZero)
auto rng = from(src);
auto dst = rng.take(0);
EXPECT_THROW(rng.nextObject(), LinqEndException);
EXPECT_THROW(rng.next(), LinqEndException);
}
//////////////////////////////////////////////////////////////////////////
......@@ -193,7 +193,7 @@ TEST(TakeWhileRange, ManyToZero)
auto rng = from(src);
auto dst = rng.takeWhile([](int it){return it < 0;});
EXPECT_THROW(dst.nextObject(), LinqEndException);
EXPECT_THROW(dst.next(), LinqEndException);
}
TEST(TakeWhileRange_i, ManyToZeroByIndex)
......@@ -203,7 +203,7 @@ TEST(TakeWhileRange_i, ManyToZeroByIndex)
auto rng = from(src);
auto dst = rng.takeWhile_i([](int /*it*/, int idx){return idx > 0;});
EXPECT_THROW(dst.nextObject(), LinqEndException);
EXPECT_THROW(dst.next(), LinqEndException);
}
TEST(TakeWhileRange_i, ManyToZeroByItemValue)
......@@ -213,7 +213,7 @@ TEST(TakeWhileRange_i, ManyToZeroByItemValue)
auto rng = from(src);
auto dst = rng.takeWhile_i([](int it, int /*idx*/){return it > 2;});
EXPECT_THROW(dst.nextObject(), LinqEndException);
EXPECT_THROW(dst.next(), LinqEndException);
}
TEST(TakeWhileRange_i, ManyToZeroByIdexAndItemValue)
......@@ -223,7 +223,7 @@ TEST(TakeWhileRange_i, ManyToZeroByIdexAndItemValue)
auto rng = from(src);
auto dst = rng.takeWhile_i([](int it, int idx){return it < 0 || idx > 0;});
EXPECT_THROW(dst.nextObject(), LinqEndException);
EXPECT_THROW(dst.next(), LinqEndException);
}
//////////////////////////////////////////////////////////////////////////
......@@ -279,7 +279,7 @@ TEST(TakeWhileRange, OneToZero)
auto rng = from(src);
auto dst = rng.takeWhile([](int){return false;});
EXPECT_THROW(dst.nextObject(), LinqEndException);
EXPECT_THROW(dst.next(), LinqEndException);
}
TEST(TakeWhileRange_i, OneToZeroByIndex)
......@@ -289,7 +289,7 @@ TEST(TakeWhileRange_i, OneToZeroByIndex)
auto rng = from(src);
auto dst = rng.takeWhile_i([](int /*it*/, int idx){return idx > 0;});
EXPECT_THROW(dst.nextObject(), LinqEndException);
EXPECT_THROW(dst.next(), LinqEndException);
}
TEST(TakeWhileRange_i, OneToZeroByItemValue)
......@@ -299,7 +299,7 @@ TEST(TakeWhileRange_i, OneToZeroByItemValue)
auto rng = from(src);
auto dst = rng.takeWhile_i([](int it, int /*idx*/){return it < 5;});
EXPECT_THROW(dst.nextObject(), LinqEndException);
EXPECT_THROW(dst.next(), LinqEndException);
}
TEST(TakeWhileRange_i, OneToZeroByIndexAndItemValue)
......@@ -309,7 +309,7 @@ TEST(TakeWhileRange_i, OneToZeroByIndexAndItemValue)
auto rng = from(src);
auto dst = rng.takeWhile_i([](int it, int idx){return idx == 0 && it > 5;});
EXPECT_THROW(dst.nextObject(), LinqEndException);
EXPECT_THROW(dst.next(), LinqEndException);
}
TEST(TakeWhileRange, ZeroToZero)
......@@ -319,7 +319,7 @@ TEST(TakeWhileRange, ZeroToZero)
auto rng = from(src);
auto dst = rng.takeWhile([](int){return false;});
EXPECT_THROW(rng.nextObject(), LinqEndException);
EXPECT_THROW(rng.next(), LinqEndException);
}
TEST(TakeWhileRange_i, ZeroToZero)
......@@ -329,7 +329,7 @@ TEST(TakeWhileRange_i, ZeroToZero)
auto rng = from(src);
auto dst = rng.takeWhile_i([](int /*it*/, int /*idx*/){return false;});
EXPECT_THROW(dst.nextObject(), LinqEndException);
EXPECT_THROW(dst.next(), LinqEndException);
}
//////////////////////////////////////////////////////////////////////////
......@@ -6,7 +6,7 @@
using namespace boolinq;
TEST(ToDeque, Deque2Deque)
TEST(toStdDeque, Deque2Deque)
{
std::deque<int> src;
src.push_back(100);
......@@ -14,7 +14,7 @@ TEST(ToDeque, Deque2Deque)
src.push_back(300);
auto rng = from(src);
auto dst = rng.toDeque();
auto dst = rng.toStdDeque();
EXPECT_EQ(dst,src);
}
......@@ -6,7 +6,7 @@
using namespace boolinq;
TEST(ToList, List2List)
TEST(toStdList, List2List)
{
std::list<int> src;
src.push_back(100);
......@@ -14,7 +14,7 @@ TEST(ToList, List2List)
src.push_back(300);
auto rng = from(src);
auto dst = rng.toList();
auto dst = rng.toStdList();
EXPECT_EQ(dst,src);
}
......@@ -6,7 +6,7 @@
using namespace boolinq;
TEST(ToSet, Vector2Set)
TEST(toStdSet, Vector2Set)
{
std::vector<int> src;
src.push_back(1);
......@@ -16,7 +16,7 @@ TEST(ToSet, Vector2Set)
src.push_back(2);
auto rng = from(src);
auto dst = rng.toSet();
auto dst = rng.toStdSet();
EXPECT_EQ(3U, dst.size());
EXPECT_NE(dst.end(), dst.find(1));
......
......@@ -6,7 +6,7 @@
using namespace boolinq;
TEST(ToVector, Vector2Vector)
TEST(toStdVector, Vector2Vector)
{
std::vector<int> src;
src.push_back(100);
......@@ -14,7 +14,7 @@ TEST(ToVector, Vector2Vector)
src.push_back(300);
auto rng = from(src);
auto dst = rng.toVector();
auto dst = rng.toStdVector();
EXPECT_EQ(dst,src);
}
......@@ -99,5 +99,5 @@ TEST(UnbytesRange, EmptyDefault)
auto rng = from(src);
auto dst = rng.unbytes<int>();
EXPECT_THROW(dst.nextObject(), LinqEndException);
EXPECT_THROW(dst.next(), LinqEndException);
}
......@@ -77,7 +77,7 @@ TEST(WhereRange, NameAgeLess)
CheckRangeEqArray(dst, ans, [](const NameAge & a){return a.name;});
}
//////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
TEST(WhereRange, MayToOne)
{
......@@ -108,7 +108,7 @@ TEST(WhereRange, ManyToZero)
auto rng = from(src);
auto dst = rng.where([](int a){return a == 5;});
EXPECT_THROW(dst.nextObject(), LinqEndException);
EXPECT_THROW(dst.next(), LinqEndException);
}
TEST(WhereRange, OneToZero)
......@@ -118,7 +118,7 @@ TEST(WhereRange, OneToZero)
auto rng = from(src);
auto dst = rng.where( [](int a){return a>10;});
EXPECT_THROW(dst.nextObject(), LinqEndException);
EXPECT_THROW(dst.next(), LinqEndException);
}
TEST(WhereRange, ZeroToZero)
......@@ -128,5 +128,5 @@ TEST(WhereRange, ZeroToZero)
auto rng = from(src);
auto dst = rng.where( [](int a){return a>0;});
EXPECT_THROW(rng.nextObject(), LinqEndException);
EXPECT_THROW(rng.next(), LinqEndException);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment