forked from k06a/boolinq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CountTest.cpp
65 lines (50 loc) · 1.1 KB
/
CountTest.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <list>
#include <vector>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "boolinq.h"
using namespace boolinq;
TEST(Count, ThreeIntsVector)
{
std::vector<int> src;
src.push_back(1);
src.push_back(2);
src.push_back(3);
auto rng = from(src);
EXPECT_EQ(3, rng.count());
}
TEST(Count, ThreeIntsList)
{
std::list<int> src;
src.push_back(1);
src.push_back(2);
src.push_back(3);
auto rng = from(src);
EXPECT_EQ(3, rng.count());
}
TEST(Count, FiveInts)
{
std::vector<int> src;
src.push_back(1);
src.push_back(2);
src.push_back(3);
src.push_back(4);
src.push_back(5);
auto rng = from(src);
auto dst0 = rng.where([](int a){return a%2 == 0;});
auto dst1 = rng.where([](int a){return a%2 == 1;});
EXPECT_EQ(2, dst0.count());
EXPECT_EQ(3, dst1.count());
}
TEST(Count, OddCount)
{
std::vector<int> src;
src.push_back(1);
src.push_back(0);
src.push_back(1);
src.push_back(0);
src.push_back(1);
auto rng = from(src);
EXPECT_EQ(2, rng.count(0));
EXPECT_EQ(3, rng.count(1));
}