Unverified Commit 852193d9 authored by Anton Bukov's avatar Anton Bukov Committed by GitHub

Merge pull request #26 from k06a/feature/v3

Written from scratch v3
parents a32c5293 88293fd3
......@@ -7,3 +7,5 @@ ipch
*.suo
[Bb]uild*
nbproject
.idea
cmake-build-debug
[submodule "externals/googletest"]
path = externals/googletest
url = https://github.com/google/googletest.git
[submodule "externals/benchmark"]
path = externals/benchmark
url = https://github.com/google/benchmark.git
[submodule "externals/gtest"]
path = externals/gtest
url = https://github.com/google/googletest
......@@ -22,6 +22,38 @@ matrix:
sources: &sources
- ubuntu-toolchain-r-test
- llvm-toolchain-precise-3.8
- env: CXX=g++-6 CC=gcc-6 GCOV=gcov-6
addons:
apt:
packages:
- g++-6
sources: &sources
- ubuntu-toolchain-r-test
- llvm-toolchain-precise-3.8
- env: CXX=g++-7 CC=gcc-7 GCOV=gcov-7
addons:
apt:
packages:
- g++-7
sources: &sources
- ubuntu-toolchain-r-test
- llvm-toolchain-precise-3.8
- env: CXX=g++-8 CC=gcc-8 GCOV=gcov-8
addons:
apt:
packages:
- g++-8
sources: &sources
- ubuntu-toolchain-r-test
- llvm-toolchain-precise-3.8
- env: CXX=g++-9 CC=gcc-9 GCOV=gcov-9
addons:
apt:
packages:
- g++-9
sources: &sources
- ubuntu-toolchain-r-test
- llvm-toolchain-precise-3.8
- env: CXX=clang++-3.8 CC=clang-3.8 GCOV=gcov
addons:
apt:
......@@ -46,8 +78,8 @@ script:
- mkdir build
- cd build
- cmake .. && make
- ./test/boolinqtest
- ./benchmark/boolinqbenchmark
- ./test/boolinq-test
- ./bench/boolinq-bench
after_success:
- coveralls --root .. --include include --gcov-options '\-lp' --gcov $GCOV --verbose
# Common variables.
CMAKE_MINIMUM_REQUIRED (VERSION 2.8)
PROJECT (boolinq)
SET (boolinq_VERSION_MAJOR 2)
SET (boolinq_VERSION_MINOR 0)
CMAKE_MINIMUM_REQUIRED (VERSION 3.0)
if (POLICY CMP0048)
cmake_policy(SET CMP0048 NEW)
endif()
PROJECT (boolinq VERSION 3.0.0 LANGUAGES CXX)
SET (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -O0 -ggdb3 -DDEBUG")
......@@ -27,10 +28,9 @@ SET_DIRECTORY_PROPERTIES (PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES ${CppCheck_REPO
# Testing.
ADD_SUBDIRECTORY (externals/gtest)
ADD_SUBDIRECTORY (externals/googletest)
ADD_SUBDIRECTORY (externals/benchmark)
ADD_SUBDIRECTORY (test)
ADD_SUBDIRECTORY (benchmark)
ADD_DEPENDENCIES (boolinqbenchmark gtest)
ADD_DEPENDENCIES (boolinqbenchmark gtest_main)
ADD_DEPENDENCIES (boolinqbenchmark benchmark)
ADD_SUBDIRECTORY (bench)
ADD_DEPENDENCIES ("${PROJECT_NAME}-test" gtest)
ADD_DEPENDENCIES ("${PROJECT_NAME}-bench" benchmark)
Copyright (C) 2013 by Anton Bukov (k06aaa@gmail.com)
Copyright (C) 2019 by Anton Bukov (k06aaa@gmail.com)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
......
# boolinq 2.0
# boolinq 3.0
[![CI Status](https://travis-ci.org/k06a/boolinq.svg?branch=master)](https://travis-ci.org/k06a/boolinq)
[![Coverage Status](https://coveralls.io/repos/github/k06a/boolinq/badge.svg?branch=master)](https://coveralls.io/github/k06a/boolinq?branch=master)
C++ single-file header-only Ranges and LINQ template library
Super tiny C++11 single-file header-only LINQ template library
Just imagine LINQ support for STL/Qt collections :)
Just imagine .NET Framework LINQ support for STL/Qt collections :)
Get source code here: **[boolinq.h](/include/boolinq/boolinq.h)**
### How it looks like?
## Wanna demo?
#### Example with integers
```c++
```C++
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();
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
.toStdVector();
// dst type: std::vector<int>
// dst items: 6,10
......@@ -26,15 +26,13 @@ auto dst = from(src).where( [](int a){return a%2 == 1;}) // 1,3,5,7
#### Example with structs
```c++
struct Man
{
```C++
struct Man {
std::string name;
int age;
};
Man src[] =
{
Man src[] = {
{"Kevin",14},
{"Anton",18},
{"Agata",17},
......@@ -42,10 +40,10 @@ Man src[] =
{"Layer",15},
};
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();
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; })
.toStdVector();
// dst type: std::vector<std::string>
// dst items: "Kevin", "Layer", "Agata"
......@@ -53,16 +51,14 @@ auto dst = from(src).where( [](const Man & man){return man.age < 18;})
#### Interesting example
```c++
struct Message
{
```C++
struct Message {
std::string PhoneA;
std::string PhoneB;
std::string Text;
};
Message messages[] =
{
Message messages[] = {
{"Anton","Troll","Hello, friend!"},
{"Denis","Wride","OLOLO"},
{"Anton","Papay","WTF?"},
......@@ -71,78 +67,60 @@ Message messages[] =
};
int DenisUniqueContactCount =
from(messages).where( [](const Message & msg){return msg.PhoneA == "Denis";})
.distinct([](const Message & msg){return msg.PhoneB;})
from(messages).where( [](const Message & msg) { return msg.PhoneA == "Denis"; })
.distinct([](const Message & msg) { return msg.PhoneB; })
.count();
// DenisUniqueContactCount == 2
```
### Containers supported?
## Containers supported?
- C++: Native arrays, pairs of pointers
- STL: list, stack, queue, vector, deque, set, map, any compatible ....
- Qt: QList, QVector, QSet, QMap.
### Operators supported?
#### Today:
- cast&lt;T&gt;()
- take(int)
- skip(int)
- concat(range)
- where(lambda)
- select(lambda)
- reverse()
- orderBy()
- orderBy(lambda)
- groupBy(lambda)
- distinct()
- distinct(lambda)
- for_each(lambda)
- all()
- all(lambda)
- any()
- any(lambda)
- sum()
- sum(lambda)
- avg()
- avg(lambda)
- min()
- min(lambda)
- max()
- max(lambda)
- count()
- count(lambda)
- contains(value)
- elementAt(int)
- toSet()
- toList()
- toDeque()
- toVector()
- toContainer&lt;T&gt;()
#### Custom:
- bytes()
- bytes&lt;ByteOrder&gt;()
- unbytes&lt;T&gt;()
- unbytes&lt;T,ByteOrder&gt;()
- bits()
- bits&lt;BitOrder&gt;()
- bits&lt;BitOrder,ByteOrder&gt;()
- unbits()
- unbits&lt;BitOrder&gt;()
- unbits&lt;T&gt;()
- unbits&lt;T,BitOrder&gt;()
- unbits&lt;T,BitOrder,ByteOrder&gt;()
## Operators supported?
#### Coming soon:
#### Filters and reorders:
- `where(predicate)`, `where_i(predicate)`
- `take(count)`, `takeWhile(predicate)`, `takeWhile_i(predicate)`
- `skip(count)`, `skipWhile(predicate)`, `skipWhile_i(predicate)`
- `orderBy()`, `orderBy(transform)`
- `distinct()`, `distinct(transform)`
- `append(items)`, `prepend(items)`
- `concat(linq)`
- `reverse()`
- `cast<T>()`
#### Transformers:
- `select(transform)`, `select_i(transform)`
- `groupBy(transform)`
- `selectMany(transfom)`
- selectMany(lambda)
#### Aggregators:
#### May be will be:
- `all()`, `all(predicate)`
- `any()`, `any(lambda)`
- `sum()`, `sum<T>()`, `sum(lambda)`
- `avg()`, `avg<T>()`, `avg(lambda)`
- `min()`, `min(lambda)`
- `max()`, `max(lambda)`
- `count()`, `count(value)`, `count(predicate)`
- `contains(value)`
- `elementAt(index)`
- `toStdSet()`, `toStdList()`, `toStdDeque()`, `toStdVector()`
#### Bits and Bytes:
- `bytes<T>(ByteDirection?)`
- `unbytes<T>(ByteDirection?)`
- `bits(BitsDirection?, BytesDirection?)`
- `unbits<T = unsigned char>(BitsDirection?, BytesDirection?)`
#### Coming soon:
- gz()
- ungz()
......
# Common variables.
#SET (CMAKE_BUILD_TYPE Release)
SET (CMAKE_CXX_STANDARD 11)
SET (CMAKE_CXX_STANDARD_REQUIRED ON)
SET (TARGET "${PROJECT_NAME}-bench" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wmissing-include-dirs -Wfloat-equal -Wshadow")
SET (TARGET "${PROJECT_NAME}-bench" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wdouble-promotion -Winit-self -Weffc++")
SET (TARGET "${PROJECT_NAME}-bench" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Woverloaded-virtual -Wsign-promo")
SET (TARGET "${PROJECT_NAME}-bench" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wvla -Winvalid-pch -Winline -Wredundant-decls")
SET (TARGET "${PROJECT_NAME}-bench" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wcast-align")
SET (TARGET "${PROJECT_NAME}-bench" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wcast-qual -Wpointer-arith")
SET (TARGET "${PROJECT_NAME}-bench" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wold-style-cast")
INCLUDE_DIRECTORIES (${PROJECT_SOURCE_DIR}/include/boolinq)
INCLUDE_DIRECTORIES (${CMAKE_BINARY_DIR}/benchmark-src/include)
INCLUDE_DIRECTORIES (${CMAKE_BINARY_DIR}/googletest-src/googletest/include)
# Benchmarks.
SET (
BoolinqBench_SOURCES
${PROJECT_SOURCE_DIR}/bench/SpeedTest.cpp
)
ADD_EXECUTABLE (
"${PROJECT_NAME}-bench"
${BoolinqBench_SOURCES}
)
TARGET_LINK_LIBRARIES (
"${PROJECT_NAME}-bench"
benchmark
gtest
)
#include <stdlib.h>
#include <math.h>
#include <benchmark/benchmark.h>
#include <gtest/gtest.h>
#include <stdlib.h>
#include <math.h>
#include "boolinq.h"
......@@ -61,10 +62,8 @@ static void BM_CppCode (benchmark::State& state)
while (state.KeepRunning () ) {
double sum = 0;
int count = 0;
for (unsigned i = 0; i < vecCpp.size(); i++)
{
if (vecCpp[i] % 2 == 1)
{
for (unsigned i = 0; i < vecCpp.size(); i++) {
if (vecCpp[i] % 2 == 1) {
sum += vecCpp[i];
count++;
}
......@@ -72,9 +71,11 @@ static void BM_CppCode (benchmark::State& state)
double avgValue = sum / count;
double stdSum = 0;
for (unsigned i = 0; i < vecCpp.size(); i++)
if (vecCpp[i] % 2 == 1)
stdSum += (vecCpp[i] - avgValue)*(vecCpp[i] - avgValue);
for (unsigned i = 0; i < vecCpp.size(); i++) {
if (vecCpp[i] % 2 == 1) {
stdSum += (vecCpp[i] - avgValue) * (vecCpp[i] - avgValue);
}
}
double stdValue = stdSum / count;
// It's no test, instead it's avoiding skip of calculation through optimization.
......@@ -93,10 +94,8 @@ static void BM_CppIterCode (benchmark::State& state)
while (state.KeepRunning () ) {
double sum = 0;
int count = 0;
for (auto it = vecCppIter.begin(); it != vecCppIter.end(); ++it)
{
if (*it % 2 == 1)
{
for (auto it = vecCppIter.begin(); it != vecCppIter.end(); ++it) {
if (*it % 2 == 1) {
sum += *it;
count++;
}
......@@ -104,9 +103,11 @@ static void BM_CppIterCode (benchmark::State& state)
double avgValue = sum / count;
double stdSum = 0;
for (auto it = vecCppIter.begin(); it != vecCppIter.end(); ++it)
if (*it % 2 == 1)
stdSum += (*it - avgValue)*(*it - avgValue);
for (auto it = vecCppIter.begin(); it != vecCppIter.end(); ++it) {
if (*it % 2 == 1) {
stdSum += (*it - avgValue) * (*it - avgValue);
}
}
double stdValue = stdSum / count;
// It's no test, instead it's avoiding skip of calculation through optimization.
......
# Common variables.
SET (CMAKE_BUILD_TYPE Release)
SET (CMAKE_CXX_STANDARD 11)
SET (CMAKE_CXX_STANDARD_REQUIRED ON)
SET (TARGET boolinqbenchmark CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wmissing-include-dirs -Wfloat-equal -Wshadow")
SET (TARGET boolinqbenchmark CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wdouble-promotion -Winit-self -Weffc++")
SET (TARGET boolinqbenchmark CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Woverloaded-virtual -Wsign-promo")
SET (TARGET boolinqbenchmark CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wvla -Winvalid-pch -Winline -Wredundant-decls")
SET (TARGET boolinqbenchmark CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wcast-align")
SET (TARGET boolinqbenchmark CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wcast-qual -Wpointer-arith")
SET (TARGET boolinqbenchmark CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wold-style-cast")
INCLUDE_DIRECTORIES (${PROJECT_SOURCE_DIR}/externals/benchmark/include)
INCLUDE_DIRECTORIES (${PROJECT_SOURCE_DIR}/include/boolinq)
INCLUDE_DIRECTORIES (${PROJECT_SOURCE_DIR}/externals/gtest/include)
# Benchmarks.
SET (
BoolinqBenchmark_SOURCES
${PROJECT_SOURCE_DIR}/benchmark/SpeedTest.cpp
)
ADD_EXECUTABLE (
boolinqbenchmark
${BoolinqBenchmark_SOURCES}
)
TARGET_LINK_LIBRARIES (
boolinqbenchmark
gtest
benchmark
)
Subproject commit 354b14d1a0770da28f1725fa8409af3264de3a79
Subproject commit 090faecb454fbd6e6e17a75ef8146acb037118d4
Subproject commit 2fe3bd994b3189899d93f1d5a881e725e046fdc2
Subproject commit d225acc90bc3a8c420a9bcd1f033033c1ccd7fe0
This diff is collapsed.
#include <vector>
#include <string>
#include <gtest/gtest.h>
#include "CommonTests.h"
#include "boolinq.h"
using namespace boolinq;
TEST(Append, ThreePlusOne)
{
std::vector<int> src = {1,2,3};
auto rng = from(src).append(4);
int ans[] = {1,2,3,4};
CheckRangeEqArray(rng, ans);
}
TEST(Append, ThreePlusTwo)
{
std::vector<int> src = {1,2,3};
auto rng = from(src).append(4, 5);
int ans[] = {1,2,3,4,5};
CheckRangeEqArray(rng, ans);
}
TEST(Append, ZeroPlusTwo)
{
std::vector<int> src;
auto rng = from(src).append(7,8);
int ans[] = {7,8};
CheckRangeEqArray(rng, ans);
}
\ No newline at end of file
......@@ -47,5 +47,5 @@ TEST(Avg, FiveStringsLen)
auto rng = from(src);
EXPECT_EQ(5, rng.avg<int>([](const std::string & str){return str.size();}));
EXPECT_EQ(5, rng.avg([](const std::string & str){return str.size();}));
}
......@@ -10,7 +10,7 @@ using namespace boolinq;
//////////////////////////////////////////////////////////////////////////
TEST(BitsRange, OneByteDefault)
TEST(Bits, OneByteDefault)
{
unsigned char src[] = {0xAA};
int ans[] = {1,0,1,0,1,0,1,0};
......@@ -21,31 +21,31 @@ TEST(BitsRange, OneByteDefault)
CheckRangeEqArray(dst, ans);
}
TEST(BitsRange, OneByteHL)
TEST(Bits, OneByteHL)
{
unsigned char src[] = {0xAA};
int ans[] = {1,0,1,0,1,0,1,0};
auto rng = from(src);
auto dst = rng.bits(HighToLow);
auto dst = rng.bits(BitsHighToLow);
CheckRangeEqArray(dst, ans);
}
TEST(BitsRange, OneByteLH)
TEST(Bits, OneByteLH)
{
unsigned char src[] = {0xAA};
int ans[] = {0,1,0,1,0,1,0,1};
auto rng = from(src);
auto dst = rng.bits(LowToHigh);
auto dst = rng.bits(BitsLowToHigh);
CheckRangeEqArray(dst, ans);
}
//////////////////////////////////////////////////////////////////////////
TEST(BitsRange, OneIntDefault)
TEST(Bits, OneIntDefault)
{
unsigned int src[] = {0x12345678};
int ans[] =
......@@ -62,7 +62,7 @@ TEST(BitsRange, OneIntDefault)
CheckRangeEqArray(dst, ans);
}
TEST(BitsRange, OneIntHL)
TEST(Bits, OneIntHL)
{
unsigned int src[] = {0x12345678};
int ans[] =
......@@ -74,12 +74,12 @@ TEST(BitsRange, OneIntHL)
};
auto rng = from(src);
auto dst = rng.bits(HighToLow);
auto dst = rng.bits(BitsHighToLow);
CheckRangeEqArray(dst, ans);
}
TEST(BitsRange, OneIntLH)
TEST(Bits, OneIntLH)
{
unsigned int src[] = {0x12345678};
int ans[] =
......@@ -91,15 +91,15 @@ TEST(BitsRange, OneIntLH)
};
auto rng = from(src);
auto dst = rng.bits(LowToHigh,FirstToLast);
auto vvv = dst.toVector();
auto dst = rng.bits(BitsLowToHigh,BytesFirstToLast);
auto vvv = dst.toStdVector();
CheckRangeEqArray(dst, ans);
}
//////////////////////////////////////////////////////////////////////////
TEST(BitsRange, IntsDefault)
TEST(Bits, IntsDefault)
{
unsigned int src[] = {0x12345678,0xAABBCCDD};
int ans[] =
......@@ -121,7 +121,7 @@ TEST(BitsRange, IntsDefault)
CheckRangeEqArray(dst, ans);
}
TEST(BitsRange, IntsHL)
TEST(Bits, IntsHL)
{
unsigned int src[] = {0x12345678,0xAABBCCDD};
int ans[] =
......@@ -138,12 +138,12 @@ TEST(BitsRange, IntsHL)
};
auto rng = from(src);
auto dst = rng.bits(HighToLow);
auto dst = rng.bits(BitsHighToLow);
CheckRangeEqArray(dst, ans);
}
TEST(BitsRange, IntsLH)
TEST(Bits, IntsLH)
{
unsigned int src[] = {0x12345678,0xAABBCCDD};
int ans[] =
......@@ -160,7 +160,7 @@ TEST(BitsRange, IntsLH)
};
auto rng = from(src);
auto dst = rng.bits(LowToHigh);
auto dst = rng.bits(BitsLowToHigh);
CheckRangeEqArray(dst, ans);
}
......@@ -10,7 +10,7 @@ using namespace boolinq;
//////////////////////////////////////////////////////////////////////////
TEST(BytesRange, OneByteDefault)
TEST(Bytes, OneByteDefault)
{
unsigned char src[] = {0xAA};
int ans[] = {0xAA};
......@@ -21,31 +21,31 @@ TEST(BytesRange, OneByteDefault)
CheckRangeEqArray(dst, ans);
}
TEST(BytesRange, OneByteFL)
TEST(Bytes, OneByteFL)
{
unsigned char src[] = {0xAA};
int ans[] = {0xAA};
auto rng = from(src);
auto dst = rng.bytes(FirstToLast);
auto dst = rng.bytes(BytesFirstToLast);
CheckRangeEqArray(dst, ans);
}
TEST(BytesRange, OneByteLF)
TEST(Bytes, OneByteLF)
{
unsigned char src[] = {0xAA};
int ans[] = {0xAA};
auto rng = from(src);
auto dst = rng.bytes(LastToFirst);
auto dst = rng.bytes(BytesLastToFirst);
CheckRangeEqArray(dst, ans);
}
//////////////////////////////////////////////////////////////////////////
TEST(BytesRange, OneIntDefault)
TEST(Bytes, OneIntDefault)
{
int src[] = {0x12345678};
int ans[] = {0x78,0x56,0x34,0x12};
......@@ -56,31 +56,31 @@ TEST(BytesRange, OneIntDefault)
CheckRangeEqArray(dst, ans);
}
TEST(BytesRange, OneIntFL)
TEST(Bytes, OneIntFL)
{
int src[] = {0x12345678};
int ans[] = {0x78,0x56,0x34,0x12};
auto rng = from(src);
auto dst = rng.bytes(FirstToLast);
auto dst = rng.bytes(BytesFirstToLast);
CheckRangeEqArray(dst, ans);
}
TEST(BytesRange, OneIntLF)
TEST(Bytes, OneIntLF)
{
int src[] = {0x12345678};
int ans[] = {0x12,0x34,0x56,0x78};
auto rng = from(src);
auto dst = rng.bytes(LastToFirst);
auto dst = rng.bytes(BytesLastToFirst);
CheckRangeEqArray(dst, ans);
}
//////////////////////////////////////////////////////////////////////////
TEST(BytesRange, IntsDefault)
TEST(Bytes, IntsDefault)
{
unsigned src[] = {0x12345678, 0xAABBCCDD};
int ans[] =
......@@ -90,12 +90,12 @@ TEST(BytesRange, IntsDefault)
};
auto rng = from(src);
auto dst = rng.bytes(FirstToLast);
auto dst = rng.bytes(BytesFirstToLast);
CheckRangeEqArray(dst, ans);
}
TEST(BytesRange, IntsFL)
TEST(Bytes, IntsFL)
{
unsigned src[] = {0x12345678, 0xAABBCCDD};
int ans[] =
......@@ -105,12 +105,12 @@ TEST(BytesRange, IntsFL)
};
auto rng = from(src);
auto dst = rng.bytes(FirstToLast);
auto dst = rng.bytes(BytesFirstToLast);
CheckRangeEqArray(dst, ans);
}
TEST(BytesRange, IntsLF)
TEST(Bytes, IntsLF)
{
unsigned src[] = {0x12345678, 0xAABBCCDD};
int ans[] =
......@@ -120,7 +120,7 @@ TEST(BytesRange, IntsLF)
};
auto rng = from(src);
auto dst = rng.bytes(LastToFirst);
auto dst = rng.bytes(BytesLastToFirst);
CheckRangeEqArray(dst, ans);
}
# Common variables.
SET (CMAKE_CXX_STANDARD 11)
SET (CMAKE_CXX_STANDARD_REQUIRED ON)
SET (TARGET boolinqtest CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wmissing-include-dirs -Wfloat-equal -Wshadow")
SET (TARGET boolinqtest CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wdouble-promotion -Winit-self -Weffc++ ")
SET (TARGET boolinqtest CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Woverloaded-virtual -Wsign-promo")
SET (TARGET boolinqtest CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wvla -Winvalid-pch -Winline -Wredundant-decls")
SET (TARGET boolinqtest CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wcast-align")
SET (TARGET boolinqtest CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wcast-qual -Wpointer-arith")
SET (TARGET boolinqtest CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wold-style-cast")
SET (TARGET boolinqtest CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
SET (TARGET "${PROJECT_NAME}-test" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wmissing-include-dirs -Wfloat-equal -Wshadow")
SET (TARGET "${PROJECT_NAME}-test" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wdouble-promotion -Winit-self -Weffc++ ")
SET (TARGET "${PROJECT_NAME}-test" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Woverloaded-virtual -Wsign-promo")
SET (TARGET "${PROJECT_NAME}-test" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wvla -Winvalid-pch -Winline -Wredundant-decls")
SET (TARGET "${PROJECT_NAME}-test" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wcast-align")
SET (TARGET "${PROJECT_NAME}-test" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wcast-qual -Wpointer-arith")
SET (TARGET "${PROJECT_NAME}-test" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wold-style-cast")
SET (TARGET "${PROJECT_NAME}-test" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
SET (CMAKE_SHARED_LINKER_FLAGS "-fprofile-arcs -ftest-coverage")
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
INCLUDE_DIRECTORIES (${PROJECT_SOURCE_DIR}/include/boolinq)
INCLUDE_DIRECTORIES (${PROJECT_SOURCE_DIR}/externals/gtest/include)
INCLUDE_DIRECTORIES (${CMAKE_BINARY_DIR}/googletest-src/googletest/include)
# Unit tests.
SET (
......@@ -23,47 +22,54 @@ SET (
${PROJECT_SOURCE_DIR}/test/AllTest.cpp
${PROJECT_SOURCE_DIR}/test/AnyTest.cpp
${PROJECT_SOURCE_DIR}/test/AvgTest.cpp
${PROJECT_SOURCE_DIR}/test/BitsRangeTest.cpp
${PROJECT_SOURCE_DIR}/test/BytesRangeTest.cpp
${PROJECT_SOURCE_DIR}/test/ConcatRangeTest.cpp
${PROJECT_SOURCE_DIR}/test/AppendTest.cpp
${PROJECT_SOURCE_DIR}/test/BitsTest.cpp
${PROJECT_SOURCE_DIR}/test/BytesTest.cpp
${PROJECT_SOURCE_DIR}/test/ConcatTest.cpp
${PROJECT_SOURCE_DIR}/test/ContainsTest.cpp
${PROJECT_SOURCE_DIR}/test/CountTest.cpp
${PROJECT_SOURCE_DIR}/test/DistinctRangeTest.cpp
${PROJECT_SOURCE_DIR}/test/DistinctTest.cpp
${PROJECT_SOURCE_DIR}/test/DotCallTest.cpp
${PROJECT_SOURCE_DIR}/test/ElementAtTest.cpp
${PROJECT_SOURCE_DIR}/test/ForeachTest.cpp
${PROJECT_SOURCE_DIR}/test/GroupByRangeTest.cpp
${PROJECT_SOURCE_DIR}/test/IterRangeTest.cpp
${PROJECT_SOURCE_DIR}/test/FirstTest.cpp
${PROJECT_SOURCE_DIR}/test/ForEachTest.cpp
${PROJECT_SOURCE_DIR}/test/GroupByTest.cpp
${PROJECT_SOURCE_DIR}/test/CtorTest.cpp
${PROJECT_SOURCE_DIR}/test/LastTest.cpp
${PROJECT_SOURCE_DIR}/test/LinqTest.cpp
${PROJECT_SOURCE_DIR}/test/MaxTest.cpp
${PROJECT_SOURCE_DIR}/test/MinTest.cpp
${PROJECT_SOURCE_DIR}/test/OrderByRangeTest.cpp
${PROJECT_SOURCE_DIR}/test/ReverseRangeTest.cpp
${PROJECT_SOURCE_DIR}/test/SelectRangeTest.cpp
${PROJECT_SOURCE_DIR}/test/SkipRangeTest.cpp
${PROJECT_SOURCE_DIR}/test/SkipWhileRangeTest.cpp
${PROJECT_SOURCE_DIR}/test/OrderByTest.cpp
${PROJECT_SOURCE_DIR}/test/PrependTest.cpp
${PROJECT_SOURCE_DIR}/test/RangeTest.cpp
${PROJECT_SOURCE_DIR}/test/ReverseTest.cpp
${PROJECT_SOURCE_DIR}/test/SelectTest.cpp
${PROJECT_SOURCE_DIR}/test/SelectManyTest.cpp
${PROJECT_SOURCE_DIR}/test/SkipTest.cpp
${PROJECT_SOURCE_DIR}/test/SkipWhileTest.cpp
${PROJECT_SOURCE_DIR}/test/SumTest.cpp
${PROJECT_SOURCE_DIR}/test/TakeRangeTest.cpp
${PROJECT_SOURCE_DIR}/test/TakeWhileRangeTest.cpp
${PROJECT_SOURCE_DIR}/test/ToDequeTest.cpp
${PROJECT_SOURCE_DIR}/test/ToListTest.cpp
${PROJECT_SOURCE_DIR}/test/ToSetTest.cpp
${PROJECT_SOURCE_DIR}/test/ToVectorTest.cpp
${PROJECT_SOURCE_DIR}/test/UnbitsRangeTest.cpp
${PROJECT_SOURCE_DIR}/test/UnbytesRangeTest.cpp
${PROJECT_SOURCE_DIR}/test/WhereRangeTest.cpp
${PROJECT_SOURCE_DIR}/test/TakeTest.cpp
${PROJECT_SOURCE_DIR}/test/TakeWhileTest.cpp
${PROJECT_SOURCE_DIR}/test/ToStdDequeTest.cpp
${PROJECT_SOURCE_DIR}/test/ToStdListTest.cpp
${PROJECT_SOURCE_DIR}/test/ToStdSetTest.cpp
${PROJECT_SOURCE_DIR}/test/ToStdVectorTest.cpp
${PROJECT_SOURCE_DIR}/test/UnbitsTest.cpp
${PROJECT_SOURCE_DIR}/test/UnbytesTest.cpp
${PROJECT_SOURCE_DIR}/test/WhereTest.cpp
)
ADD_EXECUTABLE (
boolinqtest
"${PROJECT_NAME}-test"
${BoolinqTest_SOURCES}
)
TARGET_LINK_LIBRARIES (
boolinqtest
"${PROJECT_NAME}-test"
gtest_main
gtest
#gcov
)
ENABLE_TESTING ()
ADD_TEST (BoolinqTest boolinqtest)
ADD_TEST (BoolinqTest "${PROJECT_NAME}-test")
# Test coverage report.
......@@ -74,7 +80,7 @@ ADD_CUSTOM_COMMAND (
COMMAND lcov -q -c -f -b . -d ${PROJECT_BINARY_DIR}/boolinq -o ${Coverage_REPORT}
COMMAND lcov -e ${Coverage_REPORT} '${PROJECT_SOURCE_DIR}/boolinq/*' -o ${Coverage_REPORT}
COMMAND genhtml ${Coverage_REPORT} --legend --demangle-cpp -f -q -o ${Coverage_DIR}
DEPENDS boolinqtest
DEPENDS "${PROJECT_NAME}-test"
)
ADD_CUSTOM_TARGET (coverage DEPENDS ${Coverage_REPORT})
# FIXME: Doesn't work correctly (require explicit call cmake when files appear).
......
......@@ -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(), EnumeratorEndException);
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(), EnumeratorEndException);
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());
......
......@@ -5,7 +5,7 @@
using namespace boolinq;
TEST(ConcatRange, ArrayArray)
TEST(Concat, ArrayArray)
{
int src1[] = {1,2,3,4,5};
int src2[] = {6,7,8,9};
......@@ -19,7 +19,7 @@ TEST(ConcatRange, ArrayArray)
CheckRangeEqArray(dst, ans);
}
TEST(ConcatRange, ArrayVector)
TEST(Concat, ArrayVector)
{
int src1[] = {1,2,3,4,5};
std::vector<int> src2;
......@@ -37,7 +37,7 @@ TEST(ConcatRange, ArrayVector)
CheckRangeEqArray(dst, ans);
}
TEST(ConcatRange, ArrayVectorArray)
TEST(Concat, ArrayVectorArray)
{
int src1[] = {1,2,3,4,5};
std::vector<int> src2;
......
......@@ -15,7 +15,7 @@ using namespace boolinq;
//////////////////////////////////////////////////////////////////////////
TEST(IterRange, ListInt)
TEST(Ctor, ListInt)
{
std::list<int> lst;
lst.push_back(1);
......@@ -27,11 +27,11 @@ 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)
TEST(Ctor, DequeInt)
{
std::deque<int> dck;
dck.push_back(1);
......@@ -43,11 +43,11 @@ 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)
TEST(Ctor, VectorInt)
{
std::vector<int> vec;
vec.push_back(1);
......@@ -59,44 +59,44 @@ 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)
TEST(Ctor, SetInt)
{
std::set<int> set = {1,2,3,4,5};
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, StdArrayInt)
//TEST(Ctor, 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(Ctor, StdArrayInt)
{
std::array<int, 5> arr = { {1,2,3,4,5} };
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)
TEST(Ctor, ArrayInt)
{
int arr[] = {1,2,3,4,5};
int * ptr = static_cast<int *>(arr);
......@@ -104,13 +104,13 @@ 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);
}
//////////////////////////////////////////////////////////////////////////
TEST(IterRange, OneElement)
TEST(Ctor, OneElement)
{
int src[] = {5};
int ans[] = {5};
......@@ -120,11 +120,11 @@ TEST(IterRange, OneElement)
CheckRangeEqArray(rng, ans);
}
TEST(IterRange, EmptyVector)
TEST(Ctor, EmptyVector)
{
std::vector<int> src;
auto rng = from(src);
EXPECT_THROW(rng.nextObject(), EnumeratorEndException);
EXPECT_THROW(rng.next(), LinqEndException);
}
......@@ -10,7 +10,7 @@ using namespace boolinq;
//////////////////////////////////////////////////////////////////////////
TEST(DistinctRange, Ints1to6)
TEST(Distinct, Ints1to6)
{
int src[] = {4,5,3,1,4,2,1,4,6};
int ans[] = {1,2,3,4,5,6};
......@@ -21,7 +21,7 @@ TEST(DistinctRange, Ints1to6)
CheckRangeEqSet(dst, ans);
}
TEST(DistinctRange, IntMirrorFront)
TEST(Distinct, IntMirrorFront)
{
int src[] = {3,2,1,0,1,2,3};
int ans[] = {0,1,2,3};
......@@ -32,7 +32,7 @@ TEST(DistinctRange, IntMirrorFront)
CheckRangeEqSet(dst, ans);
}
TEST(DistinctRange, ManyEqualsFront)
TEST(Distinct, ManyEqualsFront)
{
int src[] = {1,1,1,1};
int ans[] = {1};
......@@ -43,7 +43,7 @@ TEST(DistinctRange, ManyEqualsFront)
CheckRangeEqSet(dst, ans);
}
TEST(DistinctRange, ManyEqualsWithOneFront)
TEST(Distinct, ManyEqualsWithOneFront)
{
int src[] = {1,1,2,1};
int ans[] = {1,2};
......@@ -54,7 +54,7 @@ TEST(DistinctRange, ManyEqualsWithOneFront)
CheckRangeEqSet(dst, ans);
}
TEST(DistinctRange, OneFieldFront)
TEST(Distinct, OneFieldFront)
{
struct Man
{
......
......@@ -27,8 +27,8 @@ TEST(DotCall, BytesRange)
};
auto dstFL1 = from(src).bytes();
auto dstFL2 = from(src).bytes(FirstToLast);
auto dstLF1 = from(src).bytes(LastToFirst);
auto dstFL2 = from(src).bytes(BytesFirstToLast);
auto dstLF1 = from(src).bytes(BytesLastToFirst);
CheckRangeEqArray(dstFL1, ansFL);
CheckRangeEqArray(dstFL2, ansFL);
......@@ -48,8 +48,8 @@ TEST(DotCall, UnbytesRange)
unsigned ansLF[] = {0x78563412,0xDDCCBBAA};
auto dstFL1 = from(src).unbytes<unsigned>();
auto dstFL2 = from(src).unbytes<unsigned>(FirstToLast);
auto dstLF1 = from(src).unbytes<unsigned>(LastToFirst);
auto dstFL2 = from(src).unbytes<unsigned>(BytesFirstToLast);
auto dstLF1 = from(src).unbytes<unsigned>(BytesLastToFirst);
CheckRangeEqArray(dstFL1, ansFL);
CheckRangeEqArray(dstFL2, ansFL);
......@@ -77,9 +77,9 @@ TEST(DotCall, BitsRangeHL)
};
auto dstFL1 = from(src).bits();
auto dstFL2 = from(src).bits(HighToLow);
auto dstFL3 = from(src).bits(HighToLow,FirstToLast);
auto dstLF1 = from(src).bits(HighToLow,LastToFirst);
auto dstFL2 = from(src).bits(BitsHighToLow);
auto dstFL3 = from(src).bits(BitsHighToLow, BytesFirstToLast);
auto dstLF1 = from(src).bits(BitsHighToLow, BytesLastToFirst);
CheckRangeEqArray(dstFL1, ansFL);
CheckRangeEqArray(dstFL2, ansFL);
......@@ -105,9 +105,9 @@ TEST(DotCall, BitsRangeLH)
1,0,1,1,1,0,1,1,
};
auto dstFL1 = from(src).bits(LowToHigh);
auto dstFL2 = from(src).bits(LowToHigh,FirstToLast);
auto dstLF1 = from(src).bits(LowToHigh,LastToFirst);
auto dstFL1 = from(src).bits(BitsLowToHigh);
auto dstFL2 = from(src).bits(BitsLowToHigh, BytesFirstToLast);
auto dstLF1 = from(src).bits(BitsLowToHigh, BytesLastToFirst);
CheckRangeEqArray(dstFL1, ansFL);
CheckRangeEqArray(dstFL2, ansFL);
......@@ -130,10 +130,10 @@ TEST(DotCall, UnbitsRangeHLFL)
unsigned ansLF_1i[] = {0xDDCCBBAA};
auto dst1_4b = from(src).unbits();
auto dst2_4b = from(src).unbits(HighToLow);
auto dst1_1i = from(src).unbits<unsigned>(HighToLow);
auto dst2_1i = from(src).unbits<unsigned>(HighToLow,FirstToLast);
auto dst3_1i = from(src).unbits<unsigned>(HighToLow,LastToFirst);
auto dst2_4b = from(src).unbits(BitsHighToLow);
auto dst1_1i = from(src).unbits<unsigned>(BitsHighToLow);
auto dst2_1i = from(src).unbits<unsigned>(BitsHighToLow, BytesFirstToLast);
auto dst3_1i = from(src).unbits<unsigned>(BitsHighToLow, BytesLastToFirst);
CheckRangeEqArray(dst1_4b, ans_4b);
CheckRangeEqArray(dst2_4b, ans_4b);
......@@ -160,9 +160,9 @@ TEST(DotCall, UnbitsRangeHLFL)
// 1,0,1,1,1,0,1,1,
// };
//
// auto dstFL1 = from(src).bits<LowToHigh>();
// auto dstFL2 = from(src).bits<LowToHigh,FirstToLast>();
// auto dstLF1 = from(src).bits<LowToHigh,LastToFirst>();
// auto dstFL1 = from(src).bits<BitsLowToHigh>();
// auto dstFL2 = from(src).bits<BitsLowToHigh,BytesFirstToLast>();
// auto dstLF1 = from(src).bits<BitsLowToHigh,BytesLastToFirst>();
//
// CheckRangeEqArray(dstFL1, ansFL);
// CheckRangeEqArray(dstFL2, ansFL);
......
#include <list>
#include <vector>
#include <string>
#include <gtest/gtest.h>
#include "boolinq.h"
using namespace boolinq;
TEST(First, ThreeElements)
{
std::vector<int> src = {1,2,3};
EXPECT_EQ(1, from(src).first());
EXPECT_EQ(2, from(src).first([](int a){return a%2 == 0;}));
EXPECT_EQ(1, from(src).firstOrDefault());
EXPECT_EQ(2, from(src).firstOrDefault([](int a){return a%2 == 0;}));
}
TEST(First, OneElement)
{
std::vector<int> src = {1};
EXPECT_EQ(1, from(src).first());
EXPECT_THROW(from(src).first([](int a){return a%2 == 0;}), LinqEndException);
EXPECT_EQ(1, from(src).firstOrDefault());
EXPECT_EQ(0, from(src).firstOrDefault([](int a){return a%2 == 0;}));
}
TEST(First, NoneElements)
{
std::vector<int> src = {};
EXPECT_THROW(from(src).first(), LinqEndException);
EXPECT_THROW(from(src).first([](int a){return a%2 == 0;}), LinqEndException);
EXPECT_EQ(0, from(src).firstOrDefault());
EXPECT_EQ(0, from(src).firstOrDefault([](int a){return a%2 == 0;}));
}
......@@ -16,7 +16,7 @@ TEST(ForEach, ThreeCharsSum)
src.push_back('c');
std::string str = "";
from(src).foreach([&](char a){str += a;});
from(src).for_each([&](char a){str += a;});
EXPECT_EQ("abc", str);
}
......@@ -29,7 +29,7 @@ TEST(ForEach, ThreeCharsUpperSum)
src.push_back('c');
std::string str = "";
from(src).foreach([&](char a){str += a + ('A' - 'a');});
from(src).for_each([&](char a){str += a + ('A' - 'a');});
EXPECT_EQ("ABC", str);
}
......@@ -42,7 +42,7 @@ TEST(ForEach, ThreeIntsSum)
src.push_back(30);
int sum = 0;
from(src).foreach([&](int a){sum += a;});
from(src).for_each([&](int a){sum += a;});
EXPECT_EQ(60, sum);
}
#include <vector>
#include <string>
#include <gtest/gtest.h>
#include "CommonTests.h"
#include "boolinq.h"
using namespace boolinq;
//////////////////////////////////////////////////////////////////////////
/*
TEST(GroupByRange, IntsFront)
{
int arr[] = {0,1,2,3,4,5,6,7,8,9};
int ans_1[] = {1,4,7};
int ans_2[] = {2,5,8};
int ans_0[] = {0,3,6,9};
auto rng = from(arr);
auto dst = rng.groupBy([](int a){return a % 3;});
EXPECT_EQ(1, dst.front().key());
EXPECT_EQ(0, dst.back().key());
CheckRangeEqArray(dst.front(), ans_1);
CheckRangeEqArray(dst.back(), ans_0);
CheckRangeEqArray(dst.popFront(), ans_1);
EXPECT_EQ(2, dst.front().key());
EXPECT_EQ(0, dst.back().key());
CheckRangeEqArray(dst.front(), ans_2);
CheckRangeEqArray(dst.back(), ans_0);
CheckRangeEqArray(dst.popFront(), ans_2);
EXPECT_EQ(0, dst.front().key());
EXPECT_EQ(0, dst.back().key());
CheckRangeEqArray(dst.front(), ans_0);
CheckRangeEqArray(dst.back(), ans_0);
CheckRangeEqArray(dst.popFront(), ans_0);
EXPECT_THROW(dst.nextObject(), EnumeratorEndException);
}
TEST(GroupByRange, IntsBack)
{
int arr[] = {0,1,2,3,4,5,6,7,8,9};
int ans_1[] = {1,4,7};
int ans_2[] = {2,5,8};
int ans_0[] = {0,3,6,9};
auto rng = from(arr);
auto dst = groupBy(rng, [](int a){return a % 3;});
EXPECT_EQ(1, dst.front().key());
EXPECT_EQ(0, dst.back().key());
CheckRangeEqArray(dst.front(), ans_1);
CheckRangeEqArray(dst.back(), ans_0);
CheckRangeEqArray(dst.popBack(), ans_0);
EXPECT_EQ(1, dst.front().key());
EXPECT_EQ(2, dst.back().key());
CheckRangeEqArray(dst.front(), ans_1);
CheckRangeEqArray(dst.back(), ans_2);
CheckRangeEqArray(dst.popBack(), ans_2);
EXPECT_EQ(1, dst.front().key());
EXPECT_EQ(1, dst.back().key());
CheckRangeEqArray(dst.front(), ans_1);
CheckRangeEqArray(dst.back(), ans_1);
CheckRangeEqArray(dst.popBack(), ans_1);
EXPECT_THROW(dst.nextObject(), EnumeratorEndException);
}
//////////////////////////////////////////////////////////////////////////
TEST(GroupByRange, CountChildrenByAge)
{
struct Child
{
std::string name;
int age;
bool operator == (const Child & rhs) const
{
return (name == rhs.name) && (age == rhs.age);
}
};
Child children[] =
{
{"Piter", 12},
{"Bella", 14},
{"Torry", 15},
{"Holly", 12},
{"Zamza", 13},
};
Child ans_false[] =
{
{"Bella", 14},
{"Torry", 15},
};
Child ans_true[] =
{
{"Piter", 12},
{"Holly", 12},
{"Zamza", 13},
};
auto rng = from(children);
auto dst = groupBy(rng, [](const Child & a){return a.age < 14;});
EXPECT_EQ(false, dst.front().key());
CheckRangeEqArray(dst.front(), ans_false);
CheckRangeEqArray(dst.back(), ans_true);
CheckRangeEqArray(dst.popFront(), ans_false);
EXPECT_EQ(true, dst.front().key());
CheckRangeEqArray(dst.front(), ans_true);
CheckRangeEqArray(dst.back(), ans_true);
CheckRangeEqArray(dst.popFront(), ans_true);
EXPECT_THROW(dst.nextObject(), EnumeratorEndException);
}
*/
#include <vector>
#include <string>
#include <gtest/gtest.h>
#include "CommonTests.h"
#include "boolinq.h"
using namespace boolinq;
//////////////////////////////////////////////////////////////////////////
TEST(GroupBy, Ints)
{
int arr[] = {0,1,2,3,4,5,6,7,8,9};
int ans_0[] = {0,3,6,9};
int ans_1[] = {1,4,7};
int ans_2[] = {2,5,8};
auto dst = from(arr).groupBy([](int a){return a % 3;});
EXPECT_EQ(0, dst.elementAt(0).first);
EXPECT_EQ(1, dst.elementAt(1).first);
EXPECT_EQ(2, dst.elementAt(2).first);
CheckRangeEqArray(dst.elementAt(0).second, ans_0);
CheckRangeEqArray(dst.elementAt(1).second, ans_1);
CheckRangeEqArray(dst.elementAt(2).second, ans_2);
EXPECT_THROW(dst.elementAt(3), LinqEndException);
}
//////////////////////////////////////////////////////////////////////////
TEST(GroupBy, CountChildrenByAge)
{
struct Child
{
std::string name;
int age;
bool operator == (const Child & rhs) const
{
return (name == rhs.name) && (age == rhs.age);
}
};
Child children[] = {
{"Piter", 12},
{"Bella", 14},
{"Torry", 15},
{"Holly", 12},
{"Zamza", 13},
};
Child ans_false[] = {
{"Bella", 14},
{"Torry", 15},
};
Child ans_true[] = {
{"Piter", 12},
{"Holly", 12},
{"Zamza", 13},
};
auto dst = from(children).groupBy([](const Child & a){return a.age < 14;});
EXPECT_EQ(true, dst.elementAt(0).first);
EXPECT_EQ(false, dst.elementAt(1).first);
CheckRangeEqArray(dst.elementAt(0).second, ans_true);
CheckRangeEqArray(dst.elementAt(1).second, ans_false);
EXPECT_THROW(dst.elementAt(2), LinqEndException);
}
#include <list>
#include <vector>
#include <string>
#include <gtest/gtest.h>
#include "boolinq.h"
using namespace boolinq;
TEST(Last, ThreeElements)
{
std::vector<int> src = {1,2,3};
EXPECT_EQ(3, from(src).last());
EXPECT_EQ(2, from(src).last([](int a){return a%2 == 0;}));
EXPECT_EQ(3, from(src).lastOrDefault());
EXPECT_EQ(2, from(src).lastOrDefault([](int a){return a%2 == 0;}));
}
TEST(Last, OneElement)
{
std::vector<int> src = {1};
EXPECT_EQ(1, from(src).last());
EXPECT_THROW(from(src).last([](int a){return a%2 == 0;}), LinqEndException);
EXPECT_EQ(1, from(src).lastOrDefault());
EXPECT_EQ(0, from(src).lastOrDefault([](int a){return a%2 == 0;}));
}
TEST(Last, NoneElements)
{
std::vector<int> src = {};
EXPECT_THROW(from(src).last(), LinqEndException);
EXPECT_THROW(from(src).last([](int a){return a%2 == 0;}), LinqEndException);
EXPECT_EQ(0, from(src).lastOrDefault());
EXPECT_EQ(0, from(src).lastOrDefault([](int a){return a%2 == 0;}));
}
......@@ -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(), EnumeratorEndException);
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(), EnumeratorEndException);
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(), EnumeratorEndException);
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(), EnumeratorEndException);
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);})
......
......@@ -10,7 +10,7 @@ using namespace boolinq;
//////////////////////////////////////////////////////////////////////////
TEST(OrderByRange, RandomIntsWithDuplicates)
TEST(OrderBy, RandomIntsWithDuplicates)
{
int src[] = {4,5,3,1,4,2,1,4,6};
int ans[] = {1,1,2,3,4,4,4,5,6};
......@@ -21,7 +21,7 @@ TEST(OrderByRange, RandomIntsWithDuplicates)
CheckRangeEqArray(dst, ans);
}
TEST(OrderByRange, ReverseInts)
TEST(OrderBy, ReverseInts)
{
int src[] = {4,3,2,1};
int ans[] = {1,2,3,4};
......@@ -32,7 +32,7 @@ TEST(OrderByRange, ReverseInts)
CheckRangeEqArray(dst, ans);
}
TEST(OrderByRange, ThreeElements)
TEST(OrderBy, ThreeElements)
{
int src[] = {1,3,2};
int ans[] = {1,2,3};
......@@ -45,7 +45,7 @@ TEST(OrderByRange, ThreeElements)
//////////////////////////////////////////////////////////////////////////
TEST(OrderByRange, OneElement)
TEST(OrderBy, OneElement)
{
int src[] = {5};
int ans[] = {5};
......@@ -56,19 +56,19 @@ TEST(OrderByRange, OneElement)
CheckRangeEqArray(dst, ans);
}
TEST(OrderByRange, NoElements)
TEST(OrderBy, NoElements)
{
std::vector<int> src;
auto rng = from(src);
auto dst = rng.orderBy();
EXPECT_THROW(dst.nextObject(), EnumeratorEndException);
EXPECT_THROW(dst.next(), LinqEndException);
}
//////////////////////////////////////////////////////////////////////////
TEST(OrderByRange, RandomStringByContent)
TEST(OrderBy, RandomStringByContent)
{
std::string src[] =
{
......@@ -96,7 +96,7 @@ TEST(OrderByRange, RandomStringByContent)
CheckRangeEqArray(dst, ans);
}
TEST(OrderByRange, RandomStringByLength)
TEST(OrderBy, RandomStringByLength)
{
std::string src[] =
{
......
#include <vector>
#include <string>
#include <gtest/gtest.h>
#include "CommonTests.h"
#include "boolinq.h"
using namespace boolinq;
TEST(Prepend, ThreePlusOne)
{
std::vector<int> src = {1,2,3};
auto rng = from(src).prepend(4);
int ans[] = {4,1,2,3};
CheckRangeEqArray(rng, ans);
}
TEST(Prepend, ThreePlusTwo)
{
std::vector<int> src = {1,2,3};
auto rng = from(src).prepend(4, 5);
int ans[] = {4,5,1,2,3};
CheckRangeEqArray(rng, ans);
}
TEST(Prepend, ZeroPlusTwo)
{
std::vector<int> src;
auto rng = from(src).prepend(7,8);
int ans[] = {7,8};
CheckRangeEqArray(rng, ans);
}
\ No newline at end of file
#include <vector>
#include <string>
#include <gtest/gtest.h>
#include "CommonTests.h"
#include "boolinq.h"
using namespace boolinq;
TEST(Range, OneToFive)
{
int ans[] = {1,2,3,4};
CheckRangeEqArray(range(1,5,1), ans);
}
TEST(Range, OneToFiveStep2)
{
int ans[] = {1,3};
CheckRangeEqArray(range(1,5,2), ans);
}
\ No newline at end of file
......@@ -10,7 +10,7 @@
using namespace boolinq;
TEST(ReverseRange, IntVector)
TEST(Reverse, IntVector)
{
int src[] = {1,2,3,4};
int ans[] = {4,3,2,1};
......@@ -21,7 +21,7 @@ TEST(ReverseRange, IntVector)
CheckRangeEqArray(dst, ans);
}
TEST(ReverseRange, DoubleReverse)
TEST(Reverse, DoubleReverse)
{
int src[] = {1,2,3,4};
int ans[] = {1,2,3,4};
......
#include <vector>
#include <string>
#include <gtest/gtest.h>
#include "CommonTests.h"
#include "boolinq.h"
using namespace boolinq;
TEST(SelectMany, AxA)
{
int src[] = {1,2,3};
int ans[] = {1,2,2,3,3,3};
auto rng = from(src);
auto dst = rng.selectMany([](int a){return repeat(a, a);});
CheckRangeEqArray(dst, ans);
}
TEST(SelectMany, OneTwoThree)
{
int src[] = {1,2,3};
int ans[] = {1,2,3,2,4,6,3,6,9};
auto rng = from(src);
auto dst = rng.selectMany([&src](int a){
return from(src).select([a](int v){return a*v;});
});
CheckRangeEqArray(dst, ans);
}
\ No newline at end of file
......@@ -8,7 +8,7 @@
using namespace boolinq;
TEST(SelectRange, Mul2)
TEST(Select, Mul2)
{
int src[] = {1,2,3,4};
int ans[] = {2,4,6,8};
......@@ -19,7 +19,7 @@ TEST(SelectRange, Mul2)
CheckRangeEqArray(dst, ans);
}
TEST(SelectRange, MakeChar)
TEST(Select, MakeChar)
{
int src[] = {1,2,3,4};
char ans[] = {'1','2','3','4'};
......@@ -30,7 +30,7 @@ TEST(SelectRange, MakeChar)
CheckRangeEqArray(dst, ans);
}
TEST(SelectRange, MakeString)
TEST(Select, MakeString)
{
int src[] = {1,2,3,4};
......
......@@ -10,7 +10,7 @@ using namespace boolinq;
//////////////////////////////////////////////////////////////////////////
TEST(SkipRange, ManyToMany)
TEST(Skip, ManyToMany)
{
int src[] = {1,2,3,4,5,6};
int ans[] = {1,2,3,4,5,6};
......@@ -21,7 +21,7 @@ TEST(SkipRange, ManyToMany)
CheckRangeEqArray(dst, ans);
}
TEST(SkipRange, ManyToLess)
TEST(Skip, ManyToLess)
{
int src[] = {1,2,3,4,5,6};
int ans[] = {4,5,6};
......@@ -32,7 +32,7 @@ TEST(SkipRange, ManyToLess)
CheckRangeEqArray(dst, ans);
}
TEST(SkipRange, ManyToOne)
TEST(Skip, ManyToOne)
{
int src[] = {1,2,3,4,5,6};
int ans[] = {6};
......@@ -43,29 +43,29 @@ TEST(SkipRange, ManyToOne)
CheckRangeEqArray(dst, ans);
}
TEST(SkipRange, ManyToZero)
TEST(Skip, ManyToZero)
{
int src[] = {1,2,3,4,5,6};
auto rng = from(src);
auto dst = rng.skip(6);
EXPECT_THROW(dst.nextObject(), EnumeratorEndException);
EXPECT_THROW(dst.next(), LinqEndException);
}
TEST(SkipRange, ManyToZeroLess)
TEST(Skip, ManyToZeroLess)
{
int src[] = {1,2,3,4,5,6};
auto rng = from(src);
auto dst = rng.skip(10);
EXPECT_THROW(dst.nextObject(), EnumeratorEndException);
EXPECT_THROW(dst.next(), LinqEndException);
}
//////////////////////////////////////////////////////////////////////////
TEST(SkipRange, OneToOne)
TEST(Skip, OneToOne)
{
int src[] = {5};
int ans[] = {5};
......@@ -76,44 +76,44 @@ TEST(SkipRange, OneToOne)
CheckRangeEqArray(dst, ans);
}
TEST(SkipRange, OneToZero)
TEST(Skip, OneToZero)
{
int src[] = {5};
auto rng = from(src);
auto dst = rng.skip(1);
EXPECT_THROW(dst.nextObject(), EnumeratorEndException);
EXPECT_THROW(dst.next(), LinqEndException);
}
TEST(SkipRange, OneToZeroLess)
TEST(Skip, OneToZeroLess)
{
int src[] = {5};
auto rng = from(src);
auto dst = rng.skip(2);
EXPECT_THROW(dst.nextObject(), EnumeratorEndException);
EXPECT_THROW(dst.next(), LinqEndException);
}
TEST(SkipRange, ZeroToZero)
TEST(Skip, ZeroToZero)
{
std::vector<int> src;
auto rng = from(src);
auto dst = rng.skip(0);
EXPECT_THROW(rng.nextObject(), EnumeratorEndException);
EXPECT_THROW(rng.next(), LinqEndException);
}
TEST(SkipRange, ZeroToZeroLess)
TEST(Skip, ZeroToZeroLess)
{
std::vector<int> src;
auto rng = from(src);
auto dst = rng.skip(2);
EXPECT_THROW(rng.nextObject(), EnumeratorEndException);
EXPECT_THROW(rng.next(), LinqEndException);
}
//////////////////////////////////////////////////////////////////////////
......@@ -10,7 +10,7 @@ using namespace boolinq;
//////////////////////////////////////////////////////////////////////////
TEST(SkipWhileRange, ManyToMore)
TEST(SkipWhile, ManyToMore)
{
int src[] = {1,2,3,4,5,6};
int ans[] = {1,2,3,4,5,6};
......@@ -54,7 +54,7 @@ TEST(SkipWhileRange_i, ManyToMoreByIndexAndItemValue)
CheckRangeEqArray(dst, ans);
}
TEST(SkipWhileRange, ManyToMany)
TEST(SkipWhile, ManyToMany)
{
int src[] = {1,2,3,4,5,6};
int ans[] = {1,2,3,4,5,6};
......@@ -99,7 +99,7 @@ TEST(SkipWhileRange_i, ManyToManyByIndexAndItemValue)
}
TEST(SkipWhileRange, ManyToLess)
TEST(SkipWhile, ManyToLess)
{
int src[] = {1,2,3,4,5,6};
int ans[] = {3,4,5,6};
......@@ -143,7 +143,7 @@ TEST(SkipWhileRange_i, ManyToLessByIndexAndItemValue)
CheckRangeEqArray(dst, ans);
}
TEST(SkipWhileRange, ManyToOne)
TEST(SkipWhile, ManyToOne)
{
int src[] = {1,2,3,4,5,6};
int ans[] = {6};
......@@ -187,14 +187,14 @@ TEST(SkipWhileRange_i, ManyToOneByIndexAndItemValue)
CheckRangeEqArray(dst, ans);
}
TEST(SkipWhileRange, ManyToZero)
TEST(SkipWhile, ManyToZero)
{
int src[] = {1,2,3,4,5,6};
auto rng = from(src);
auto dst = rng.skipWhile([](int it){return it > 0;});
EXPECT_THROW(dst.nextObject(), EnumeratorEndException);
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(), EnumeratorEndException);
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(), EnumeratorEndException);
EXPECT_THROW(dst.next(), LinqEndException);
}
TEST(SkipWhileRange_i, ManyToZeroIndexAndItemValue)
......@@ -224,12 +224,12 @@ TEST(SkipWhileRange_i, ManyToZeroIndexAndItemValue)
auto rng = from(src);
auto dst = rng.skipWhile_i([](int it, int idx){return idx != it;});
EXPECT_THROW(dst.nextObject(), EnumeratorEndException);
EXPECT_THROW(dst.next(), LinqEndException);
}
//////////////////////////////////////////////////////////////////////////
TEST(SkipWhileRange, OneToOne)
TEST(SkipWhile, OneToOne)
{
int src[] = {5};
int ans[] = {5};
......@@ -273,14 +273,14 @@ TEST(SkipWhileRange_i, OneToOneByIndexAndItemValue)
CheckRangeEqArray(dst, ans);
}
TEST(SkipWhileRange, OneToZero)
TEST(SkipWhile, OneToZero)
{
int src[] = {5};
auto rng = from(src);
auto dst = rng.skipWhile([](int it){return it == 5;});
EXPECT_THROW(dst.nextObject(), EnumeratorEndException);
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(), EnumeratorEndException);
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(), EnumeratorEndException);
EXPECT_THROW(dst.next(), LinqEndException);
}
TEST(SkipWhileRange_i, OneToZeroIndexAndItemValue)
......@@ -310,17 +310,17 @@ TEST(SkipWhileRange_i, OneToZeroIndexAndItemValue)
auto rng = from(src);
auto dst = rng.skipWhile_i([](int it, int idx){return idx != it;});
EXPECT_THROW(dst.nextObject(), EnumeratorEndException);
EXPECT_THROW(dst.next(), LinqEndException);
}
TEST(SkipWhileRange, ZeroToZero)
TEST(SkipWhile, ZeroToZero)
{
std::vector<int> src;
auto rng = from(src);
auto dst = rng.skipWhile([](int){return false;});
EXPECT_THROW(rng.nextObject(), EnumeratorEndException);
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(), EnumeratorEndException);
EXPECT_THROW(rng.next(), LinqEndException);
}
//////////////////////////////////////////////////////////////////////////
......@@ -36,7 +36,7 @@ TEST(Sum, FiveInts)
EXPECT_EQ(9, dst1);
}
TEST(Sum, BoolSum)
TEST(Sum, TransformSum)
{
std::vector<int> src;
src.push_back(1);
......@@ -45,10 +45,10 @@ 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;});
auto rng2 = from(src).sum([](int a){return a%2;});
EXPECT_EQ(2, rng1);
EXPECT_EQ(6, rng1);
EXPECT_EQ(3, rng2);
}
......@@ -81,3 +81,17 @@ TEST(Sum, FiveStringsData)
EXPECT_EQ(ans, rng);
}
TEST(Sum, TransfromStringSum)
{
std::vector<std::string> src;
src.push_back("hello");
src.push_back("apple");
src.push_back("nokia");
src.push_back("oracle");
src.push_back("ponny");
auto sum = from(src).sum([](std::string s) { return s.size(); });
EXPECT_EQ(26, sum);
}
......@@ -10,7 +10,7 @@ using namespace boolinq;
//////////////////////////////////////////////////////////////////////////
TEST(TakeRange, ManyToMore)
TEST(Take, ManyToMore)
{
int src[] = {1,2,3,4,5,6};
int ans[] = {1,2,3,4,5,6};
......@@ -21,7 +21,7 @@ TEST(TakeRange, ManyToMore)
CheckRangeEqArray(dst, ans);
}
TEST(TakeRange, ManyToMany)
TEST(Take, ManyToMany)
{
int src[] = {1,2,3,4,5,6};
int ans[] = {1,2,3,4,5,6};
......@@ -32,7 +32,7 @@ TEST(TakeRange, ManyToMany)
CheckRangeEqArray(dst, ans);
}
TEST(TakeRange, ManyToLess)
TEST(Take, ManyToLess)
{
int src[] = {1,2,3,4,5,6};
int ans[] = {1,2,3};
......@@ -43,7 +43,7 @@ TEST(TakeRange, ManyToLess)
CheckRangeEqArray(dst, ans);
}
TEST(TakeRange, ManyToOne)
TEST(Take, ManyToOne)
{
int src[] = {1,2,3,4,5,6};
int ans[] = {1};
......@@ -54,19 +54,19 @@ TEST(TakeRange, ManyToOne)
CheckRangeEqArray(dst, ans);
}
TEST(TakeRange, ManyToZero)
TEST(Take, ManyToZero)
{
int src[] = {1,2,3,4,5,6};
auto rng = from(src);
auto dst = rng.take(0);
EXPECT_THROW(dst.nextObject(), EnumeratorEndException);
EXPECT_THROW(dst.next(), LinqEndException);
}
//////////////////////////////////////////////////////////////////////////
TEST(TakeRange, OneToMore)
TEST(Take, OneToMore)
{
int src[] = {5};
int ans[] = {5};
......@@ -77,7 +77,7 @@ TEST(TakeRange, OneToMore)
CheckRangeEqArray(dst, ans);
}
TEST(TakeRange, OneToOne)
TEST(Take, OneToOne)
{
int src[] = {5};
int ans[] = {5};
......@@ -88,24 +88,24 @@ TEST(TakeRange, OneToOne)
CheckRangeEqArray(dst, ans);
}
TEST(TakeRange, OneToZero)
TEST(Take, OneToZero)
{
int src[] = {5};
auto rng = from(src);
auto dst = rng.take(0);
EXPECT_THROW(dst.nextObject(), EnumeratorEndException);
EXPECT_THROW(dst.next(), LinqEndException);
}
TEST(TakeRange, ZeroToZero)
TEST(Take, ZeroToZero)
{
std::vector<int> src;
auto rng = from(src);
auto dst = rng.take(0);
EXPECT_THROW(rng.nextObject(), EnumeratorEndException);
EXPECT_THROW(rng.next(), LinqEndException);
}
//////////////////////////////////////////////////////////////////////////
......@@ -10,7 +10,7 @@ using namespace boolinq;
//////////////////////////////////////////////////////////////////////////
TEST(TakeWhileRange, ManyToMore)
TEST(TakeWhile, ManyToMore)
{
int src[] = {1,2,3,4,5,6};
int ans[] = {1,2,3,4,5,6};
......@@ -54,7 +54,7 @@ TEST(TakeWhileRange_i, ManyToMoreByIndexAndItemValue)
CheckRangeEqArray(dst, ans);
}
TEST(TakeWhileRange, ManyToMany)
TEST(TakeWhile, ManyToMany)
{
int src[] = {1,2,3,4,5,6};
int ans[] = {1,2,3,4,5,6};
......@@ -98,7 +98,7 @@ TEST(TakeWhileRange_i, ManyToManyByIndexAndItemValue)
CheckRangeEqArray(dst, ans);
}
TEST(TakeWhileRange, ManyToLess)
TEST(TakeWhile, ManyToLess)
{
int src[] = {1,2,3,4,5,6};
int ans[] = {1,2,3};
......@@ -142,7 +142,7 @@ TEST(TakeWhileRange_i, ManyToLessByIndexAndItemValue)
CheckRangeEqArray(dst, ans);
}
TEST(TakeWhileRange, ManyToOne)
TEST(TakeWhile, ManyToOne)
{
int src[] = {1,2,3,4,5,6};
int ans[] = {1};
......@@ -186,14 +186,14 @@ TEST(TakeWhileRange_i, ManyToOneByIndexAndItemValue)
CheckRangeEqArray(dst, ans);
}
TEST(TakeWhileRange, ManyToZero)
TEST(TakeWhile, ManyToZero)
{
int src[] = {1,2,3,4,5,6};
auto rng = from(src);
auto dst = rng.takeWhile([](int it){return it < 0;});
EXPECT_THROW(dst.nextObject(), EnumeratorEndException);
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(), EnumeratorEndException);
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(), EnumeratorEndException);
EXPECT_THROW(dst.next(), LinqEndException);
}
TEST(TakeWhileRange_i, ManyToZeroByIdexAndItemValue)
......@@ -223,12 +223,12 @@ 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(), EnumeratorEndException);
EXPECT_THROW(dst.next(), LinqEndException);
}
//////////////////////////////////////////////////////////////////////////
TEST(TakeWhileRange, OneToOne)
TEST(TakeWhile, OneToOne)
{
int src[] = {5};
int ans[] = {5};
......@@ -272,14 +272,14 @@ TEST(TakeWhileRange_i, OneToOneByIndexAndItemValue)
CheckRangeEqArray(dst, ans);
}
TEST(TakeWhileRange, OneToZero)
TEST(TakeWhile, OneToZero)
{
int src[] = {5};
auto rng = from(src);
auto dst = rng.takeWhile([](int){return false;});
EXPECT_THROW(dst.nextObject(), EnumeratorEndException);
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(), EnumeratorEndException);
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(), EnumeratorEndException);
EXPECT_THROW(dst.next(), LinqEndException);
}
TEST(TakeWhileRange_i, OneToZeroByIndexAndItemValue)
......@@ -309,17 +309,17 @@ 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(), EnumeratorEndException);
EXPECT_THROW(dst.next(), LinqEndException);
}
TEST(TakeWhileRange, ZeroToZero)
TEST(TakeWhile, ZeroToZero)
{
std::vector<int> src;
auto rng = from(src);
auto dst = rng.takeWhile([](int){return false;});
EXPECT_THROW(rng.nextObject(), EnumeratorEndException);
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(), EnumeratorEndException);
EXPECT_THROW(dst.next(), LinqEndException);
}
//////////////////////////////////////////////////////////////////////////
#include <list>
#include <deque>
#include <vector>
#include <gtest/gtest.h>
#include "CommonTests.h"
#include "IterRange.h"
#include "ToContainer.h"
using namespace boolinq;
//////////////////////////////////////////////////////////////////////////
TEST(ToContainer, Array2List)
{
int src[] = {100,200,300};
auto rng = range(src);
auto dst = toContainer<std::list>(rng);
EXPECT_EQ(3, dst.size());
EXPECT_EQ(100, dst.front()); dst.pop_front();
EXPECT_EQ(200, dst.front()); dst.pop_front();
EXPECT_EQ(300, dst.front()); dst.pop_front();
}
TEST(ToContainer, Array2Deque)
{
int src[] = {100,200,300};
auto rng = range(src);
auto dst = toContainer<std::deque>(rng);
EXPECT_EQ(3, dst.size());
EXPECT_EQ(100, dst.front()); dst.pop_front();
EXPECT_EQ(200, dst.front()); dst.pop_front();
EXPECT_EQ(300, dst.front()); dst.pop_front();
}
TEST(ToContainer, Array2Vector)
{
int src[] = {100,200,300};
auto rng = range(src);
auto dst = toContainer<std::vector>(rng);
EXPECT_EQ(3, dst.size());
EXPECT_EQ(100, dst[0]);
EXPECT_EQ(200, dst[1]);
EXPECT_EQ(300, dst[2]);
}
//////////////////////////////////////////////////////////////////////////
TEST(ToContainer, List2List)
{
std::list<int> src;
src.push_back(100);
src.push_back(200);
src.push_back(300);
auto rng = range(src);
auto dst = toContainer<std::list>(rng);
EXPECT_EQ(dst,src);
}
TEST(ToContainer, Deque2Deque)
{
std::deque<int> src;
src.push_back(100);
src.push_back(200);
src.push_back(300);
auto rng = range(src);
auto dst = toContainer<std::deque>(rng);
EXPECT_EQ(dst,src);
}
TEST(ToContainer, Vector2Vector)
{
std::vector<int> src;
src.push_back(100);
src.push_back(200);
src.push_back(300);
auto rng = range(src);
auto dst = toContainer<std::vector>(rng);
EXPECT_EQ(dst,src);
}
//////////////////////////////////////////////////////////////////////////
......@@ -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);
}
......@@ -10,7 +10,7 @@ using namespace boolinq;
//////////////////////////////////////////////////////////////////////////
TEST(UnbitsRange, OneByteDefault)
TEST(Unbits, OneByteDefault)
{
int src[] = {1,0,1,0,1,0,1,0};
int ans[] = {0xAA};
......@@ -21,24 +21,24 @@ TEST(UnbitsRange, OneByteDefault)
CheckRangeEqArray(dst, ans);
}
TEST(UnbitsRange, OneByteHL)
TEST(Unbits, OneByteHL)
{
int src[] = {1,0,1,0,1,0,1,0};
int ans[] = {0xAA};
auto rng = from(src);
auto dst = rng.unbits(HighToLow);
auto dst = rng.unbits(BitsHighToLow);
CheckRangeEqArray(dst, ans);
}
TEST(UnbitsRange, OneByteLH)
TEST(Unbits, OneByteLH)
{
int src[] = {0,1,0,1,0,1,0,1};
int ans[] = {0xAA};
auto rng = from(src);
auto dst = rng.unbits(LowToHigh);
auto dst = rng.unbits(BitsLowToHigh);
CheckRangeEqArray(dst, ans);
}
......@@ -10,7 +10,7 @@ using namespace boolinq;
//////////////////////////////////////////////////////////////////////////
TEST(UnbytesRange, OneIntDefault)
TEST(Unbytes, OneIntDefault)
{
unsigned char src[] = {0xAA,0xBB,0xCC,0xDD};
unsigned ans[] = {0xDDCCBBAA};
......@@ -21,31 +21,31 @@ TEST(UnbytesRange, OneIntDefault)
CheckRangeEqArray(dst, ans);
}
TEST(UnbytesRange, OneIntFL)
TEST(Unbytes, OneIntFL)
{
unsigned char src[] = {0xAA,0xBB,0xCC,0xDD};
unsigned ans[] = {0xDDCCBBAA};
auto rng = from(src);
auto dst = rng.unbytes<unsigned>(FirstToLast);
auto dst = rng.unbytes<unsigned>(BytesFirstToLast);
CheckRangeEqArray(dst, ans);
}
TEST(UnbytesRange, OneIntLF)
TEST(Unbytes, OneIntLF)
{
unsigned char src[] = {0xAA,0xBB,0xCC,0xDD};
unsigned ans[] = {0xAABBCCDD};
auto rng = from(src);
auto dst = rng.unbytes<unsigned>(LastToFirst);
auto dst = rng.unbytes<unsigned>(BytesLastToFirst);
CheckRangeEqArray(dst, ans);
}
//////////////////////////////////////////////////////////////////////////
TEST(UnbytesRange, TwoIntsDefault)
TEST(Unbytes, TwoIntsDefault)
{
unsigned char src[] =
{
......@@ -60,7 +60,7 @@ TEST(UnbytesRange, TwoIntsDefault)
CheckRangeEqArray(dst, ans);
}
TEST(UnbytesRange, TwoIntsFL)
TEST(Unbytes, TwoIntsFL)
{
unsigned char src[] =
{
......@@ -70,12 +70,12 @@ TEST(UnbytesRange, TwoIntsFL)
unsigned ans[] = {0x12345678,0xDDCCBBAA};
auto rng = from(src);
auto dst = rng.unbytes<unsigned>(FirstToLast);
auto dst = rng.unbytes<unsigned>(BytesFirstToLast);
CheckRangeEqArray(dst, ans);
}
TEST(UnbytesRange, TwoIntsLF)
TEST(Unbytes, TwoIntsLF)
{
unsigned char src[] =
{
......@@ -85,19 +85,19 @@ TEST(UnbytesRange, TwoIntsLF)
unsigned ans[] = {0x78563412,0xAABBCCDD};
auto rng = from(src);
auto dst = rng.unbytes<unsigned>(LastToFirst);
auto dst = rng.unbytes<unsigned>(BytesLastToFirst);
CheckRangeEqArray(dst, ans);
}
//////////////////////////////////////////////////////////////////////////
TEST(UnbytesRange, EmptyDefault)
TEST(Unbytes, EmptyDefault)
{
std::vector<unsigned char> src;
auto rng = from(src);
auto dst = rng.unbytes<int>();
EXPECT_THROW(dst.nextObject(), EnumeratorEndException);
EXPECT_THROW(dst.next(), LinqEndException);
}
......@@ -10,7 +10,7 @@ using namespace boolinq;
//////////////////////////////////////////////////////////////////////////
TEST(WhereRange, IntOdd)
TEST(Where, IntOdd)
{
int src[] = {1,2,3,4,5,6};
int ans[] = {1, 3, 5};
......@@ -23,7 +23,7 @@ TEST(WhereRange, IntOdd)
//////////////////////////////////////////////////////////////////////////
TEST(WhereRange, FirstLetterFront)
TEST(Where, FirstLetterFront)
{
std::string src[] =
{
......@@ -48,7 +48,7 @@ TEST(WhereRange, FirstLetterFront)
//////////////////////////////////////////////////////////////////////////
TEST(WhereRange, NameAgeLess)
TEST(Where, NameAgeLess)
{
struct NameAge
{
......@@ -77,9 +77,9 @@ TEST(WhereRange, NameAgeLess)
CheckRangeEqArray(dst, ans, [](const NameAge & a){return a.name;});
}
//////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
TEST(WhereRange, MayToOne)
TEST(Where, MayToOne)
{
int src[] = {0,1,2};
int ans[] = {1};
......@@ -90,7 +90,7 @@ TEST(WhereRange, MayToOne)
CheckRangeEqArray(dst, ans);
}
TEST(WhereRange, OneToOne)
TEST(Where, OneToOne)
{
int src[] = {5};
int ans[] = {5};
......@@ -101,32 +101,32 @@ TEST(WhereRange, OneToOne)
CheckRangeEqArray(dst, ans);
}
TEST(WhereRange, ManyToZero)
TEST(Where, ManyToZero)
{
int src[] = {0,1,2};
auto rng = from(src);
auto dst = rng.where([](int a){return a == 5;});
EXPECT_THROW(dst.nextObject(), EnumeratorEndException);
EXPECT_THROW(dst.next(), LinqEndException);
}
TEST(WhereRange, OneToZero)
TEST(Where, OneToZero)
{
int src[] = {5};
auto rng = from(src);
auto dst = rng.where( [](int a){return a>10;});
EXPECT_THROW(dst.nextObject(), EnumeratorEndException);
EXPECT_THROW(dst.next(), LinqEndException);
}
TEST(WhereRange, ZeroToZero)
TEST(Where, ZeroToZero)
{
std::vector<int> src;
auto rng = from(src);
auto dst = rng.where( [](int a){return a>0;});
EXPECT_THROW(rng.nextObject(), EnumeratorEndException);
EXPECT_THROW(rng.next(), LinqEndException);
}
#include <gtest/gtest.h>
////////////////////////////////////////////////////////////////
/*
template<class R, class T>
R find(R r, T value)
{
for (; !r.empty(); r.popFront())
if (value == r.front()) break;
return r;
}
template<class R, class T>
R find_end(R r, T value)
{
return retro(find(retro(r), value));
}
*/
////////////////////////////////////////////////////////////////
int main(int argc, char * argv[])
{
::testing::InitGoogleMock(&argc, argv);
......
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