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
Kirill Smelkov
cython
Commits
d19f6252
Commit
d19f6252
authored
Oct 08, 2008
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
struct conversion tests
parent
1a3b1fba
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
60 additions
and
0 deletions
+60
-0
tests/run/struct_conversion.pyx
tests/run/struct_conversion.pyx
+60
-0
No files found.
tests/run/struct_conversion.pyx
0 → 100644
View file @
d19f6252
__doc__
=
"""
>>> test_constructor(1,2,255)
{'y': 2.0, 'x': 1.0, 'color': 255}
>>> test_constructor(1,None,255)
Traceback (most recent call last):
...
TypeError: a float is required
>>> test_constructor_kwds(1.25, 2.5, 128)
{'y': 2.5, 'x': 1.25, 'color': 128}
>>> test_constructor_kwds(1.25, 2.5, None)
Traceback (most recent call last):
...
TypeError: an integer is required
>>> test_dict_construction(4, 5, 64)
{'y': 5.0, 'x': 4.0, 'color': 64}
>>> test_dict_construction("foo", 5, 64)
Traceback (most recent call last):
...
TypeError: a float is required
>>> test_pointers(100, 2.71828)
100
2.71828
True
"""
cdef
struct
Point
:
double
x
double
y
int
color
def
test_constructor
(
x
,
y
,
color
):
cdef
Point
p
=
Point
(
x
,
y
,
color
)
return
p
def
test_constructor_kwds
(
x
,
y
,
color
):
cdef
Point
p
=
Point
(
x
=
x
,
y
=
y
,
color
=
color
)
return
p
def
test_dict_construction
(
x
,
y
,
color
):
cdef
Point
p
=
{
color
:
color
,
x
:
x
,
y
:
y
}
return
p
cdef
union
int_or_float
:
int
n
double
x
cdef
struct
with_pointers
:
bint
is_integral
int_or_float
data
void
*
ptr
def
test_pointers
(
int
n
,
double
x
):
cdef
with_pointers
a
=
[
True
,
{
n
:
n
},
NULL
]
cdef
with_pointers
b
=
with_pointers
(
False
,
{
x
:
x
},
NULL
)
print
a
.
data
.
n
print
b
.
data
.
x
print
a
.
ptr
==
b
.
ptr
==
NULL
\ No newline at end of file
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