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
79b91c2a
Commit
79b91c2a
authored
Jun 27, 2013
by
Jakub Pawlik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added the skipWhile linq function
+ created the skipWhile function + added tests for skipWhile function
parent
389a1d10
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
118 additions
and
0 deletions
+118
-0
SkipWhileRangeTest.cpp
boolinq/SkipWhileRangeTest.cpp
+103
-0
boolinq.h
boolinq/boolinq.h
+11
-0
boolinq.vcxproj
boolinq/boolinq.vcxproj
+1
-0
boolinq.vcxproj.filters
boolinq/boolinq.vcxproj.filters
+3
-0
No files found.
boolinq/SkipWhileRangeTest.cpp
0 → 100644
View file @
79b91c2a
#include <vector>
#include <string>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "CommonTests.h"
#include "boolinq.h"
using
namespace
boolinq
;
//////////////////////////////////////////////////////////////////////////
TEST
(
SkipWhileRange
,
ManyToMore
)
{
int
src
[]
=
{
1
,
2
,
3
,
4
,
5
,
6
};
int
ans
[]
=
{
1
,
2
,
3
,
4
,
5
,
6
};
auto
rng
=
from
(
src
);
auto
dst
=
rng
.
skipWhile
([](
int
it
){
return
it
<
0
||
it
>
10
;});
auto
vec
=
dst
.
toVector
();
CheckRangeEqArray
(
dst
,
ans
);
}
TEST
(
SkipWhileRange
,
ManyToMany
)
{
int
src
[]
=
{
1
,
2
,
3
,
4
,
5
,
6
};
int
ans
[]
=
{
1
,
2
,
3
,
4
,
5
,
6
};
auto
rng
=
from
(
src
);
auto
dst
=
rng
.
skipWhile
([](
int
it
){
return
it
<
0
&&
it
>
6
;});
CheckRangeEqArray
(
dst
,
ans
);
}
TEST
(
SkipWhileRange
,
ManyToLess
)
{
int
src
[]
=
{
1
,
2
,
3
,
4
,
5
,
6
};
int
ans
[]
=
{
3
,
4
,
5
,
6
};
auto
rng
=
from
(
src
);
auto
dst
=
rng
.
skipWhile
([](
int
it
){
return
it
<
3
||
it
>
4
;});
CheckRangeEqArray
(
dst
,
ans
);
}
TEST
(
SkipWhileRange
,
ManyToOne
)
{
int
src
[]
=
{
1
,
2
,
3
,
4
,
5
,
6
};
int
ans
[]
=
{
6
};
auto
rng
=
from
(
src
);
auto
dst
=
rng
.
skipWhile
([](
int
it
){
return
it
!=
6
;});
CheckRangeEqArray
(
dst
,
ans
);
}
TEST
(
SkipWhileRange
,
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
);
}
//////////////////////////////////////////////////////////////////////////
TEST
(
SkipWhileRange
,
OneToOne
)
{
int
src
[]
=
{
5
};
int
ans
[]
=
{
5
};
auto
rng
=
from
(
src
);
auto
dst
=
rng
.
skipWhile
([](
int
it
){
return
it
!=
5
;});
CheckRangeEqArray
(
dst
,
ans
);
}
TEST
(
SkipWhileRange
,
OneToZero
)
{
int
src
[]
=
{
5
};
auto
rng
=
from
(
src
);
auto
dst
=
rng
.
skipWhile
([](
int
it
){
return
it
==
5
;});
EXPECT_THROW
(
dst
.
nextObject
(),
EnumeratorEndException
);
}
TEST
(
SkipWhileRange
,
ZeroToZero
)
{
std
::
vector
<
int
>
src
;
auto
rng
=
from
(
src
);
auto
dst
=
rng
.
skipWhile
([](
int
){
return
false
;});
EXPECT_THROW
(
rng
.
nextObject
(),
EnumeratorEndException
);
}
//////////////////////////////////////////////////////////////////////////
boolinq/boolinq.h
View file @
79b91c2a
...
...
@@ -190,6 +190,17 @@ namespace boolinq
return
where_i
([
=
](
T
,
int
i
){
return
i
>=
count
;});
}
LinqObj
<
Enumerator
<
T
,
std
::
pair
<
TE
,
int
>
>
>
skipWhile
(
std
::
function
<
bool
(
T
)
>
predicate
)
const
{
return
Enumerator
<
T
,
std
::
pair
<
TE
,
int
>
>
([
=
](
std
::
pair
<
TE
,
int
>
&
pair
)
->
T
{
T
object
=
pair
.
first
.
nextObject
();;
if
(
0
==
pair
.
second
++
)
while
(
predicate
(
object
))
object
=
pair
.
first
.
nextObject
();
return
object
;
},
std
::
make_pair
(
_enumerator
,
0
));
}
template
<
typename
TRet
>
LinqObj
<
Enumerator
<
TRet
,
std
::
pair
<
TE
,
int
>
>
>
select_i
(
std
::
function
<
TRet
(
T
,
int
)
>
transform
)
const
{
...
...
boolinq/boolinq.vcxproj
View file @
79b91c2a
...
...
@@ -95,6 +95,7 @@
<ClCompile
Include=
"ReverseRangeTest.cpp"
/>
<ClCompile
Include=
"SelectRangeTest.cpp"
/>
<ClCompile
Include=
"SkipRangeTest.cpp"
/>
<ClCompile
Include=
"SkipWhileRangeTest.cpp"
/>
<ClCompile
Include=
"SpeedTest.cpp"
/>
<ClCompile
Include=
"SumTest.cpp"
/>
<ClCompile
Include=
"TakeRangeTest.cpp"
/>
...
...
boolinq/boolinq.vcxproj.filters
View file @
79b91c2a
...
...
@@ -131,6 +131,9 @@
<ClCompile
Include=
"TakeWhileRangeTest.cpp"
>
<Filter>
Test Files\Ranges
</Filter>
</ClCompile>
<ClCompile
Include=
"SkipWhileRangeTest.cpp"
>
<Filter>
Test Files\Ranges
</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude
Include=
"boolinq.h"
>
...
...
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