Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pybind11
Overview
Overview
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
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open
pybind11
Commits
5f46e47d
Unverified
Commit
5f46e47d
authored
Sep 23, 2021
by
Henry Schreiner
Committed by
GitHub
Sep 23, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tests: check simple iteration of pairs (#3296)
parent
2fa3fcfd
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
0 deletions
+22
-0
tests/test_sequences_and_iterators.cpp
+13
-0
tests/test_sequences_and_iterators.py
+9
-0
No files found.
tests/test_sequences_and_iterators.cpp
View file @
5f46e47d
...
@@ -295,6 +295,8 @@ TEST_SUBMODULE(sequences_and_iterators, m) {
...
@@ -295,6 +295,8 @@ TEST_SUBMODULE(sequences_and_iterators, m) {
public
:
public
:
explicit
IntPairs
(
std
::
vector
<
std
::
pair
<
int
,
int
>>
data
)
:
data_
(
std
::
move
(
data
))
{}
explicit
IntPairs
(
std
::
vector
<
std
::
pair
<
int
,
int
>>
data
)
:
data_
(
std
::
move
(
data
))
{}
const
std
::
pair
<
int
,
int
>*
begin
()
const
{
return
data_
.
data
();
}
const
std
::
pair
<
int
,
int
>*
begin
()
const
{
return
data_
.
data
();
}
// .end() only required for py::make_iterator(self) overload
const
std
::
pair
<
int
,
int
>*
end
()
const
{
return
data_
.
data
()
+
data_
.
size
();
}
private
:
private
:
std
::
vector
<
std
::
pair
<
int
,
int
>>
data_
;
std
::
vector
<
std
::
pair
<
int
,
int
>>
data_
;
};
};
...
@@ -306,6 +308,17 @@ TEST_SUBMODULE(sequences_and_iterators, m) {
...
@@ -306,6 +308,17 @@ TEST_SUBMODULE(sequences_and_iterators, m) {
.
def
(
"nonzero_keys"
,
[](
const
IntPairs
&
s
)
{
.
def
(
"nonzero_keys"
,
[](
const
IntPairs
&
s
)
{
return
py
::
make_key_iterator
(
NonZeroIterator
<
std
::
pair
<
int
,
int
>>
(
s
.
begin
()),
NonZeroSentinel
());
return
py
::
make_key_iterator
(
NonZeroIterator
<
std
::
pair
<
int
,
int
>>
(
s
.
begin
()),
NonZeroSentinel
());
},
py
::
keep_alive
<
0
,
1
>
())
},
py
::
keep_alive
<
0
,
1
>
())
.
def
(
"simple_iterator"
,
[](
IntPairs
&
self
)
{
return
py
::
make_iterator
(
self
);
},
py
::
keep_alive
<
0
,
1
>
())
.
def
(
"simple_keys"
,
[](
IntPairs
&
self
)
{
return
py
::
make_key_iterator
(
self
);
},
py
::
keep_alive
<
0
,
1
>
())
// test iterator with keep_alive (doesn't work so not used at runtime, but tests compile)
.
def
(
"make_iterator_keep_alive"
,
[](
IntPairs
&
self
)
{
return
py
::
make_iterator
(
self
,
py
::
keep_alive
<
0
,
1
>
());
},
py
::
keep_alive
<
0
,
1
>
())
;
;
...
...
tests/test_sequences_and_iterators.py
View file @
5f46e47d
...
@@ -48,6 +48,15 @@ def test_generalized_iterators():
...
@@ -48,6 +48,15 @@ def test_generalized_iterators():
next
(
it
)
next
(
it
)
def
test_generalized_iterators_simple
():
assert
list
(
m
.
IntPairs
([(
1
,
2
),
(
3
,
4
),
(
0
,
5
)])
.
simple_iterator
())
==
[
(
1
,
2
),
(
3
,
4
),
(
0
,
5
),
]
assert
list
(
m
.
IntPairs
([(
1
,
2
),
(
3
,
4
),
(
0
,
5
)])
.
simple_keys
())
==
[
1
,
3
,
0
]
def
test_sliceable
():
def
test_sliceable
():
sliceable
=
m
.
Sliceable
(
100
)
sliceable
=
m
.
Sliceable
(
100
)
assert
sliceable
[::]
==
(
0
,
100
,
1
)
assert
sliceable
[::]
==
(
0
,
100
,
1
)
...
...
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