Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
B
boolinq
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
boolinq
Commits
7d8da6a0
Commit
7d8da6a0
authored
Jun 29, 2019
by
Anton Bukov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add groupBy tests and fixes
parent
68892852
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
80 additions
and
139 deletions
+80
-139
boolinq.h
include/boolinq/boolinq.h
+4
-6
CMakeLists.txt
test/CMakeLists.txt
+1
-1
GroupByRangeTest.cpp
test/GroupByRangeTest.cpp
+0
-132
GroupByTest.cpp
test/GroupByTest.cpp
+75
-0
No files found.
include/boolinq/boolinq.h
View file @
7d8da6a0
...
...
@@ -257,7 +257,7 @@ namespace boolinq {
>
Linq
<
LinqCopyUnorderedSet
<
S
,
T
,
_TKey
>
,
std
::
pair
<
_TKey
,
_TValue
>
>
groupBy
(
F
apply
)
const
{
return
Linq
<
LinqCopyUnorderedSet
<
S
,
T
,
_TKey
>
,
std
::
pair
<
_TKey
,
Linq
<
S
,
T
>
>
>
(
return
Linq
<
LinqCopyUnorderedSet
<
S
,
T
,
_TKey
>
,
std
::
pair
<
_TKey
,
_TValue
>
>
(
{
*
this
,
*
this
,
std
::
unordered_set
<
_TKey
>
()},
[
apply
](
LinqCopyUnorderedSet
<
S
,
T
,
_TKey
>
&
tuple
){
T
value
=
tuple
.
linq
.
next
();
...
...
@@ -267,6 +267,7 @@ namespace boolinq {
return
apply
(
v
)
==
key
;
}));
}
throw
LinqEndException
();
}
);
}
...
...
@@ -710,11 +711,8 @@ namespace boolinq {
bitIndex
=
CHAR_BIT
-
1
-
bitIndex
;
}
if
(
tuple
.
linq
.
next
())
{
ptr
[
byteIndex
]
|=
(
1
<<
bitIndex
);
}
else
{
ptr
[
byteIndex
]
&=
(
~
0
^
(
1
<<
bitIndex
));
}
ptr
[
byteIndex
]
&=
~
(
1
<<
bitIndex
);
ptr
[
byteIndex
]
|=
bool
(
tuple
.
linq
.
next
())
<<
bitIndex
;
}
return
value
;
...
...
test/CMakeLists.txt
View file @
7d8da6a0
...
...
@@ -32,7 +32,7 @@ SET (
${
PROJECT_SOURCE_DIR
}
/test/DotCallTest.cpp
${
PROJECT_SOURCE_DIR
}
/test/ElementAtTest.cpp
${
PROJECT_SOURCE_DIR
}
/test/ForeachTest.cpp
${
PROJECT_SOURCE_DIR
}
/test/GroupBy
Range
Test.cpp
${
PROJECT_SOURCE_DIR
}
/test/GroupByTest.cpp
${
PROJECT_SOURCE_DIR
}
/test/IterRangeTest.cpp
${
PROJECT_SOURCE_DIR
}
/test/LinqTest.cpp
${
PROJECT_SOURCE_DIR
}
/test/MaxTest.cpp
...
...
test/GroupByRangeTest.cpp
deleted
100644 → 0
View file @
68892852
#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.next(), LinqEndException);
}
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.next(), LinqEndException);
}
//////////////////////////////////////////////////////////////////////////
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.next(), LinqEndException);
}
*/
test/GroupByTest.cpp
0 → 100644
View file @
7d8da6a0
#include <vector>
#include <string>
#include <gtest/gtest.h>
#include "CommonTests.h"
#include "boolinq.h"
using
namespace
boolinq
;
//////////////////////////////////////////////////////////////////////////
TEST
(
GroupByRange
,
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
(
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
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
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment