Commit ad187c07 authored by Anton Bukov's avatar Anton Bukov

Merge pull request #17 from k06a/feature/travis-ci

Configure travis-ci.org service
parents 0de328bb fc9be1c6
language: none
sudo: false
cache:
apt: true
directories:
- /tmp/tools
env:
global:
- PATH="$HOME/bin:$PATH"
- CMAKE_VERSION_PREFIX=3.5
- CMAKE_VERSION_FULL=3.5.2
matrix:
include:
- env: CXX=g++-5 CC=gcc-5
addons:
apt:
packages:
- g++-5
sources: &sources
- ubuntu-toolchain-r-test
- llvm-toolchain-precise-3.8
- env: CXX=clang++-3.8 CC=clang-3.8
addons:
apt:
packages:
- clang-3.8
sources: *sources
before_install:
- pip install --user cpp-coveralls
install:
- mkdir -p /tmp/tools
- pushd /tmp/tools
- if [[ ! -f "cmake-$CMAKE_VERSION_FULL-Linux-x86_64.sh" ]]; then
curl -SOL "https://cmake.org/files/v$CMAKE_VERSION_PREFIX/cmake-$CMAKE_VERSION_FULL-Linux-x86_64.sh";
chmod +x "cmake-$CMAKE_VERSION_FULL-Linux-x86_64.sh";
fi
- ./"cmake-$CMAKE_VERSION_FULL-Linux-x86_64.sh" --prefix="$HOME" --exclude-subdir --skip-license
- popd
script:
- mkdir build
- cd build
- cmake .. && make
- ./test/boolinqtest
- ./benchmark/boolinqbenchmark
- cd ..
after_success:
- coveralls --gcov-options '\-lp'
# Common variables.
SET (CMAKE_BUILD_TYPE "Release")
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wmissing-include-dirs -Wundef -Wfloat-equal -Wshadow -Wunsafe-loop-optimizations")
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wdouble-promotion -Winit-self -Wvector-operation-performance -Wnoexcept -Weffc++ -Wstrict-null-sentinel")
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Woverloaded-virtual -Wsign-promo")
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wvla -Winvalid-pch -Winline -Wredundant-decls")
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wlogical-op -Wcast-align")
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wcast-qual -Wpointer-arith -Wtrampolines")
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wold-style-cast")
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wzero-as-null-pointer-constant")
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)
......
......@@ -2,6 +2,7 @@
#include <gtest/gtest.h>
#include <stdlib.h>
#include <math.h>
#include "boolinq.h"
......@@ -38,17 +39,17 @@ int main (int argc, char ** argv)
static void BM_BoolinqCode (benchmark::State& state)
{
while (state.KeepRunning () ) {
double avgValue = from(vecBoolinq).where( [](int a){return a%2 == 1;})
.avg<double>();
double avgValue = from(vecBoolinq).where([](int a){return a%2 == 1;})
.avg();
double disper = from(vecBoolinq).where( [](int a){return a%2 == 1;})
.select([=](int a){return (double)((a-avgValue)*(a-avgValue));})
.avg<double>();
// It's no test, instead it's avoiding skip of calculation throgh optimization.
double stdValue = from(vecBoolinq).where([](int a){return a%2 == 1;})
.avg([=](int a){return (a - avgValue)*(a - avgValue);});
// It's no test, instead it's avoiding skip of calculation through optimization.
state.PauseTiming ();
EXPECT_TRUE(avgValue);
EXPECT_TRUE(disper);
state.ResumeTiming ();
EXPECT_TRUE(stdValue);
state.ResumeTiming();
}
}
BENCHMARK(BM_BoolinqCode);
......@@ -70,16 +71,16 @@ static void BM_CppCode (benchmark::State& state)
}
double avgValue = sum / count;
double disperSum = 0;
double stdSum = 0;
for (unsigned i = 0; i < vecCpp.size(); i++)
if (vecCpp[i] % 2 == 1)
disperSum += (vecCpp[i] - avgValue)*(vecCpp[i] - avgValue);
double disper = disperSum / count;
stdSum += (vecCpp[i] - avgValue)*(vecCpp[i] - avgValue);
double stdValue = stdSum / count;
// It's no test, instead it's avoiding skip of calculation throgh optimization.
// It's no test, instead it's avoiding skip of calculation through optimization.
state.PauseTiming ();
EXPECT_TRUE(avgValue);
EXPECT_TRUE(disper);
EXPECT_TRUE(stdValue);
state.ResumeTiming ();
}
}
......@@ -102,16 +103,16 @@ static void BM_CppIterCode (benchmark::State& state)
}
double avgValue = sum / count;
double disperSum = 0;
double stdSum = 0;
for (auto it = vecCppIter.begin(); it != vecCppIter.end(); ++it)
if (*it % 2 == 1)
disperSum += (*it - avgValue)*(*it - avgValue);
double disper = disperSum / count;
stdSum += (*it - avgValue)*(*it - avgValue);
double stdValue = stdSum / count;
// It's no test, instead it's avoiding skip of calculation throgh optimization.
// It's no test, instead it's avoiding skip of calculation through optimization.
state.PauseTiming ();
EXPECT_TRUE(avgValue);
EXPECT_TRUE(disper);
EXPECT_TRUE(stdValue);
state.ResumeTiming ();
}
}
......
Subproject commit 0a439623f75c029912728d80cb7f1b8b48739ca4
Subproject commit d225acc90bc3a8c420a9bcd1f033033c1ccd7fe0
......@@ -16,7 +16,7 @@ TEST(Avg, ThreeInts)
auto rng = from(src);
EXPECT_EQ(2, rng.avg<double>());
EXPECT_NEAR(2.0, rng.avg<double>(), DBL_EPSILON);
}
TEST(Avg, FiveInts)
......@@ -32,8 +32,8 @@ TEST(Avg, FiveInts)
auto dst0 = rng.where([](int a){return a%2 == 0;});
auto dst1 = rng.where([](int a){return a%2 == 1;});
EXPECT_EQ(3, dst0.avg<double>());
EXPECT_EQ(3, dst1.avg<double>());
EXPECT_NEAR(3.0, dst0.avg<double>(), DBL_EPSILON);
EXPECT_NEAR(3.0, dst1.avg<double>(), DBL_EPSILON);
}
TEST(Avg, FiveStringsLen)
......
# Common variables.
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wmissing-include-dirs -Wundef -Wfloat-equal -Wshadow -Wunsafe-loop-optimizations")
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wdouble-promotion -Winit-self -Wvector-operation-performance -Wnoexcept -Weffc++ -Wstrict-null-sentinel")
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Woverloaded-virtual -Wsign-promo")
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wvla -Winvalid-pch -Winline -Wredundant-decls")
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wlogical-op -Wcast-align")
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wcast-qual -Wpointer-arith -Wtrampolines")
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wold-style-cast")
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wzero-as-null-pointer-constant")
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
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 (CMAKE_SHARED_LINKER_FLAGS "-fprofile-arcs -ftest-coverage")
......
......@@ -10,29 +10,29 @@ using namespace boolinq;
// Compare Range with array
//////////////////////////////////////////////////////////////////////////
template<typename R, typename T, int N, typename F>
template<typename R, typename T, unsigned N, typename F>
void CheckRangeEqArray(R dst, T (&ans)[N], F f)
{
for (int i = 0; i < N; i++)
for (unsigned i = 0; i < N; i++)
EXPECT_EQ(f(ans[i]), f(dst.nextObject()));
EXPECT_THROW(dst.nextObject(), EnumeratorEndException);
}
template<typename R, typename T, int N>
template<typename R, typename T, unsigned N>
void CheckRangeEqArray(R dst, T (&ans)[N])
{
for (int i = 0; i < N; i++)
for (unsigned i = 0; i < N; i++)
EXPECT_EQ(ans[i], dst.nextObject());
EXPECT_THROW(dst.nextObject(), EnumeratorEndException);
}
template<typename T, int N>
template<typename T, unsigned N>
std::set<T> ArrayToSet(T (&ans)[N])
{
std::set<T> res;
for(int i = 0; i < N; i++)
for(unsigned i = 0; i < N; i++)
res.insert(ans[i]);
EXPECT_EQ(N, res.size());
......@@ -40,7 +40,7 @@ std::set<T> ArrayToSet(T (&ans)[N])
return res;
}
template<typename R, typename T, int N>
template<typename R, typename T, unsigned N>
void CheckRangeEqSet(R dst, T (&ans)[N])
{
std::set<T> expected = ArrayToSet(ans);
......
......@@ -72,9 +72,9 @@ TEST(DistinctRange, OneFieldFront)
return (name == man.name);
}
bool operator == (const std::string & name) const
bool operator == (const std::string & manName) const
{
return (this->name == name);
return (this->name == manName);
}
};
......
......@@ -47,9 +47,9 @@ TEST(DotCall, UnbytesRange)
unsigned ansFL[] = {0x12345678,0xAABBCCDD};
unsigned ansLF[] = {0x78563412,0xDDCCBBAA};
auto dstFL1 = from(src).unbytes<int>();
auto dstFL2 = from(src).unbytes<int>(FirstToLast);
auto dstLF1 = from(src).unbytes<int>(LastToFirst);
auto dstFL1 = from(src).unbytes<unsigned>();
auto dstFL2 = from(src).unbytes<unsigned>(FirstToLast);
auto dstLF1 = from(src).unbytes<unsigned>(LastToFirst);
CheckRangeEqArray(dstFL1, ansFL);
CheckRangeEqArray(dstFL2, ansFL);
......@@ -131,9 +131,9 @@ TEST(DotCall, UnbitsRangeHLFL)
auto dst1_4b = from(src).unbits();
auto dst2_4b = from(src).unbits(HighToLow);
auto dst1_1i = from(src).unbits<int>(HighToLow);
auto dst2_1i = from(src).unbits<int>(HighToLow,FirstToLast);
auto dst3_1i = from(src).unbits<int>(HighToLow,LastToFirst);
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);
CheckRangeEqArray(dst1_4b, ans_4b);
CheckRangeEqArray(dst2_4b, ans_4b);
......
......@@ -88,7 +88,7 @@ TEST(IterRange, MapInt)
TEST(IterRange, StdArrayInt)
{
std::array<int, 5> arr = {1,2,3,4,5};
std::array<int, 5> arr = { {1,2,3,4,5} };
int ans[] = {1,2,3,4,5};
CheckRangeEqArray(from(arr), ans);
......@@ -99,7 +99,7 @@ TEST(IterRange, StdArrayInt)
TEST(IterRange, ArrayInt)
{
int arr[] = {1,2,3,4,5};
int * ptr = (int*)arr;
int * ptr = static_cast<int *>(arr);
int ans[] = {1,2,3,4,5};
......
......@@ -208,7 +208,7 @@ TEST(Linq, Pointer_Front)
{
int src[] = {1,2,3,4,5};
auto dst = from<int>((int*)src, (int*)src+5);
auto dst = from<int>(static_cast<int *>(src), static_cast<int *>(src) + 5);
for(int i = 1; i <= 5; i++)
{
......@@ -246,19 +246,11 @@ TEST(Linq, Creations)
vec.push_back(4);
vec.push_back(5);
int arr[] = {1,2,3,4,5};
int * ptr = (int*)arr;
//std::vector<const int> cvec;
//cvec.push_back(1);
//cvec.push_back(2);
//cvec.push_back(3);
//cvec.push_back(4);
//cvec.push_back(5);
const int carr[] = {1,2,3,4,5};
const int * cptr = (const int*)carr;
//const int carr[] = {1,2,3,4,5};
int * ptr = static_cast<int *>(arr);
//const int * cptr = const_cast<int *>(arr);
auto dst_vec = from(vec);
//auto dst_cvec = from(cvec);
auto dst_arr = from(arr);
//auto dst_carr = from(carr);
auto dst_ptr = from<int>(ptr, ptr+5);
......@@ -267,8 +259,6 @@ TEST(Linq, Creations)
//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_cvec_iter = from<const int>(cvec.begin(), cvec.end());
//auto dst_cvec_citer = from<const int>(cvec.cbegin(), cvec.cend());
}
//////////////////////////////////////////////////////////////////////////
......@@ -284,8 +274,8 @@ TEST(Linq, MessagesCountUniqueContacts)
bool operator < (const Message & rhs) const
{
return (PhoneA < rhs.PhoneA)
|| (PhoneA == rhs.PhoneA) && (PhoneB < rhs.PhoneB)
|| (PhoneA == rhs.PhoneA) && (PhoneB == rhs.PhoneB) && (Text < rhs.Text);
|| ((PhoneA == rhs.PhoneA) && (PhoneB < rhs.PhoneB))
|| ((PhoneA == rhs.PhoneA) && (PhoneB == rhs.PhoneB) && (Text < rhs.Text));
}
};
......
......@@ -25,7 +25,7 @@ TEST(SelectRange, MakeChar)
char ans[] = {'1','2','3','4'};
auto rng = from(src);
auto dst = rng.select([](int a){return (char)(a+'0');});
auto dst = rng.select([](int a){return static_cast<char>('0' + a);});
CheckRangeEqArray(dst, ans);
}
......
......@@ -63,7 +63,7 @@ TEST(Sum, FiveStringsLen)
auto rng = from(src).sum([](const std::string & str){return str.size();});
EXPECT_EQ(26, rng);
EXPECT_EQ(26U, rng);
}
TEST(Sum, FiveStringsData)
......
......@@ -93,7 +93,7 @@ TEST(TakeWhileRange_i, ManyToManyByIndexAndItemValue)
int ans[] = {1,3,5,7,9,11};
auto rng = from(src);
auto dst = rng.takeWhile_i([](int it, int idx){return idx < 3 || it > 5 && it < 12;});
auto dst = rng.takeWhile_i([](int it, int idx){return idx < 3 || (it > 5 && it < 12);});
CheckRangeEqArray(dst, ans);
}
......
......@@ -18,7 +18,7 @@ TEST(ToSet, Vector2Set)
auto rng = from(src);
auto dst = rng.toSet();
EXPECT_EQ(3, dst.size());
EXPECT_EQ(3U, dst.size());
EXPECT_NE(dst.end(), dst.find(1));
EXPECT_NE(dst.end(), dst.find(2));
EXPECT_NE(dst.end(), dst.find(3));
......
......@@ -16,7 +16,7 @@ TEST(UnbytesRange, OneIntDefault)
unsigned ans[] = {0xDDCCBBAA};
auto rng = from(src);
auto dst = rng.unbytes<int>();
auto dst = rng.unbytes<unsigned>();
CheckRangeEqArray(dst, ans);
}
......
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