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
350ff18d
Commit
350ff18d
authored
Jun 29, 2019
by
Anton Bukov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix sum tests
parent
49a90223
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
23 deletions
+39
-23
boolinq.h
include/boolinq/boolinq.h
+15
-13
DotCallTest.cpp
test/DotCallTest.cpp
+6
-6
SumTest.cpp
test/SumTest.cpp
+18
-4
No files found.
include/boolinq/boolinq.h
View file @
350ff18d
...
...
@@ -637,7 +637,7 @@ namespace boolinq {
tuple
.
index
=
0
;
}
u
int8_t
*
ptr
=
reinterpret_cast
<
uint8_t
*>
(
&
tuple
.
value
);
u
nsigned
char
*
ptr
=
reinterpret_cast
<
unsigned
char
*>
(
&
tuple
.
value
);
int
byteIndex
=
tuple
.
index
;
if
(
tuple
.
bytesDirection
==
BytesLastToFirst
)
{
...
...
@@ -657,7 +657,7 @@ namespace boolinq {
{
*
this
,
direction
,
BitsHighToLow
,
T
(),
0
},
[](
LinqBytesBitsValueIndex
<
S
,
T
>
&
tuple
)
{
TRet
value
;
u
int8_t
*
ptr
=
reinterpret_cast
<
uint8_t
*>
(
&
value
);
u
nsigned
char
*
ptr
=
reinterpret_cast
<
unsigned
char
*>
(
&
value
);
for
(
int
i
=
0
;
i
<
sizeof
(
TRet
);
i
++
)
{
int
byteIndex
=
i
;
...
...
@@ -683,45 +683,47 @@ namespace boolinq {
tuple
.
index
=
0
;
}
u
int8_t
*
ptr
=
reinterpret_cast
<
uint8_t
*>
(
&
tuple
.
value
);
u
nsigned
char
*
ptr
=
reinterpret_cast
<
unsigned
char
*>
(
&
tuple
.
value
);
int
byteIndex
=
tuple
.
index
/
8
;
int
byteIndex
=
tuple
.
index
/
CHAR_BIT
;
if
(
tuple
.
bytesDirection
==
BytesLastToFirst
)
{
byteIndex
=
sizeof
(
T
)
-
1
-
byteIndex
;
}
int
bitIndex
=
tuple
.
index
%
8
;
int
bitIndex
=
tuple
.
index
%
CHAR_BIT
;
if
(
tuple
.
bitsDirection
==
BitsHighToLow
)
{
bitIndex
=
7
-
bitIndex
;
bitIndex
=
CHAR_BIT
-
1
-
bitIndex
;
}
tuple
.
index
++
;
return
(
ptr
[
byteIndex
]
&
(
1
<<
bitIndex
))
!=
0
;
return
(
(
ptr
[
byteIndex
]
&
(
1
<<
bitIndex
))
!=
0
)
?
1
:
0
;
}
);
}
template
<
typename
TRet
=
u
int8_t
>
template
<
typename
TRet
=
u
nsigned
char
>
Linq
<
LinqBytesBitsValueIndex
<
S
,
T
>
,
TRet
>
unbits
(
BitsDirection
bitsDir
=
BitsHighToLow
,
BytesDirection
bytesDir
=
BytesFirstToLast
)
const
{
return
Linq
<
LinqBytesBitsValueIndex
<
S
,
T
>
,
TRet
>
(
{
*
this
,
bytesDir
,
bitsDir
,
T
(),
0
},
[](
LinqBytesBitsValueIndex
<
S
,
T
>
&
tuple
)
{
TRet
value
;
u
int8_t
*
ptr
=
reinterpret_cast
<
uint8_t
*>
(
&
value
);
u
nsigned
char
*
ptr
=
reinterpret_cast
<
unsigned
char
*>
(
&
value
);
for
(
int
i
=
0
;
i
<
sizeof
(
TRet
);
i
++
)
{
int
byteIndex
=
i
/
8
;
int
byteIndex
=
i
/
CHAR_BIT
;
if
(
tuple
.
bytesDirection
==
BytesLastToFirst
)
{
byteIndex
=
sizeof
(
TRet
)
-
1
-
byteIndex
;
}
int
bitIndex
=
i
%
8
;
int
bitIndex
=
i
%
CHAR_BIT
;
if
(
tuple
.
bitsDirection
==
BitsHighToLow
)
{
bitIndex
=
7
-
bitIndex
;
bitIndex
=
CHAR_BIT
-
1
-
bitIndex
;
}
ptr
[
byteIndex
]
|=
(
tuple
.
linq
.
next
()
?
1
:
0
)
<<
bitIndex
;
if
(
tuple
.
linq
.
next
())
{
ptr
[
byteIndex
]
|=
1
<<
bitIndex
;
}
}
return
value
;
...
...
test/DotCallTest.cpp
View file @
350ff18d
...
...
@@ -78,8 +78,8 @@ TEST(DotCall, BitsRangeHL)
auto
dstFL1
=
from
(
src
).
bits
();
auto
dstFL2
=
from
(
src
).
bits
(
BitsHighToLow
);
auto
dstFL3
=
from
(
src
).
bits
(
BitsHighToLow
,
BytesFirstToLast
);
auto
dstLF1
=
from
(
src
).
bits
(
BitsHighToLow
,
BytesLastToFirst
);
auto
dstFL3
=
from
(
src
).
bits
(
BitsHighToLow
,
BytesFirstToLast
);
auto
dstLF1
=
from
(
src
).
bits
(
BitsHighToLow
,
BytesLastToFirst
);
CheckRangeEqArray
(
dstFL1
,
ansFL
);
CheckRangeEqArray
(
dstFL2
,
ansFL
);
...
...
@@ -106,8 +106,8 @@ TEST(DotCall, BitsRangeLH)
};
auto
dstFL1
=
from
(
src
).
bits
(
BitsLowToHigh
);
auto
dstFL2
=
from
(
src
).
bits
(
BitsLowToHigh
,
BytesFirstToLast
);
auto
dstLF1
=
from
(
src
).
bits
(
BitsLowToHigh
,
BytesLastToFirst
);
auto
dstFL2
=
from
(
src
).
bits
(
BitsLowToHigh
,
BytesFirstToLast
);
auto
dstLF1
=
from
(
src
).
bits
(
BitsLowToHigh
,
BytesLastToFirst
);
CheckRangeEqArray
(
dstFL1
,
ansFL
);
CheckRangeEqArray
(
dstFL2
,
ansFL
);
...
...
@@ -132,8 +132,8 @@ TEST(DotCall, UnbitsRangeHLFL)
auto
dst1_4b
=
from
(
src
).
unbits
();
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
);
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
);
...
...
test/SumTest.cpp
View file @
350ff18d
...
...
@@ -36,7 +36,7 @@ TEST(Sum, FiveInts)
EXPECT_EQ
(
9
,
dst1
);
}
TEST
(
Sum
,
Bool
Sum
)
TEST
(
Sum
,
Transform
Sum
)
{
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
a
){
return
a
%
2
==
0
;});
auto
rng2
=
from
(
src
).
sum
([](
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
);
}
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