Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gwenaël Samain
cython
Commits
17bdd442
Commit
17bdd442
authored
Jun 29, 2012
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
C++ stl conversion tests.
parent
a716b4d1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
98 additions
and
0 deletions
+98
-0
tests/run/cpp_stl_conversion.pyx
tests/run/cpp_stl_conversion.pyx
+98
-0
No files found.
tests/run/cpp_stl_conversion.pyx
0 → 100644
View file @
17bdd442
# tag: cpp
import
sys
from
libcpp.map
cimport
map
from
libcpp.set
cimport
set
as
cpp_set
from
libcpp.string
cimport
string
from
libcpp.pair
cimport
pair
from
libcpp.vector
cimport
vector
py_set
=
set
cdef
string
add_strings
(
string
a
,
string
b
):
return
a
+
b
def
normalize
(
bytes
b
):
if
sys
.
version_info
[
0
]
>=
3
:
return
b
.
decode
(
"ascii"
)
else
:
return
b
def
test_string
(
o
):
"""
>>> normalize(test_string(b"abc"))
'abc'
>>> normalize(test_string(b"abc
\
\
x00def"))
'abc
\
\
x00def'
"""
cdef
string
s
=
o
return
o
def
test_string_call
(
a
,
b
):
"""
>>> normalize(test_string_call("abc", "xyz"))
'abcxyz'
"""
return
add_strings
(
a
,
b
)
def
test_int_vector
(
o
):
"""
>>> test_int_vector([1, 2, 3])
[1, 2, 3]
>>> test_int_vector((1, 10, 100))
[1, 10, 100]
>>> test_int_vector([10**20])
Traceback (most recent call last):
...
OverflowError: Python int too large to convert to C long
"""
cdef
vector
[
int
]
v
=
o
return
v
def
test_double_vector
(
o
):
"""
>>> test_double_vector([1, 2, 3])
[1.0, 2.0, 3.0]
>>> test_double_vector([10**20])
[1e+20]
"""
cdef
vector
[
double
]
v
=
o
return
v
def
test_pair
(
o
):
"""
>>> test_pair((1, 2))
(1, 2.0)
"""
cdef
pair
[
long
,
double
]
p
=
o
return
p
def
test_set
(
o
):
"""
>>> sorted(test_set([1, 2, 3]))
[1, 2, 3]
>>> sorted(test_set([1, 2, 3, 3]))
[1, 2, 3]
>>> type(test_set([])) is py_set
True
"""
cdef
cpp_set
[
long
]
s
=
o
return
s
def
test_map
(
o
):
"""
>>> test_map({1: 1.0, 2: 0.5, 3: 0.25})
{1: 1.0, 2: 0.5, 3: 0.25}
"""
cdef
map
[
int
,
double
]
m
=
o
return
m
def
test_nested
(
o
):
"""
>>> test_nested({})
{}
>>> test_nested({(1.0, 2.0): [1, 2, 3], (1.0, 0.5): [1, 10, 100]})
{(1.0, 2.0): [1, 2, 3], (1.0, 0.5): [1, 10, 100]}
"""
cdef
map
[
pair
[
double
,
double
],
vector
[
int
]]
m
=
o
return
m
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