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
c7aa65ab
Commit
c7aa65ab
authored
May 07, 2012
by
Andreas van Cranenburgh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
moved doctests to individual functions.
parent
8a4faf57
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
57 additions
and
42 deletions
+57
-42
tests/run/pyarray.pyx
tests/run/pyarray.pyx
+57
-42
No files found.
tests/run/pyarray.pyx
View file @
c7aa65ab
# tag: array
# tag: array
__doc__
=
u"""
>>> len(a)
3
>>> test_len(a)
3L
>>> test_copy(a)
array('f', [1.0, 2.0, 3.0])
>>> a[2]
3.5
>>> test_fast_access(a)
>>> test_new_zero(a)
array('f', [0.0, 0.0, 0.0])
>>> test_set_zero(a)
array('f', [0.0, 0.0, 0.0])
>>> test_resize(a)
>> test_likes(a)
array('f', [0.0, 0.0, 0.0])
>>> test_view()
>>> test_extend()
>>> test_extend_buffer()
array('c', 'abcdefghij')
"""
import
array
# Python builtin module
import
array
# Python builtin module
from
cpython
cimport
array
# array.pxd / arrayarray.h
from
cpython
cimport
array
# array.pxd / arrayarray.h
...
@@ -42,10 +6,24 @@ from cpython cimport array # array.pxd / arrayarray.h
...
@@ -42,10 +6,24 @@ from cpython cimport array # array.pxd / arrayarray.h
a
=
array
.
array
(
'f'
,
[
1.0
,
2.0
,
3.0
])
a
=
array
.
array
(
'f'
,
[
1.0
,
2.0
,
3.0
])
def
test_len
(
a
):
def
test_len
(
a
):
"""
>>> a = array.array('f', [1.0, 2.0, 3.0])
>>> len(a)
3
>>> test_len(a)
3L
>>> assert len(a) == test_len(a)
"""
cdef
array
.
array
ca
=
a
# for C-fast array usage
cdef
array
.
array
ca
=
a
# for C-fast array usage
return
ca
.
length
return
ca
.
length
def
test_copy
(
a
):
def
test_copy
(
a
):
"""
>>> a = array.array('f', [1.0, 2.0, 3.0])
>>> test_copy(a)
array('f', [1.0, 2.0, 3.0])
>>> assert a == test_copy(a)
"""
cdef
array
.
array
ca
=
a
cdef
array
.
array
ca
=
a
cdef
array
.
array
b
cdef
array
.
array
b
b
=
array
.
copy
(
a
)
b
=
array
.
copy
(
a
)
...
@@ -55,6 +33,14 @@ def test_copy(a):
...
@@ -55,6 +33,14 @@ def test_copy(a):
def
test_fast_access
(
a
):
def
test_fast_access
(
a
):
"""
>>> a = array.array('f', [1.0, 2.0, 3.0])
>>> a[2]
3.5
>>> test_fast_access(a)
"""
cdef
array
.
array
ca
=
a
cdef
array
.
array
ca
=
a
assert
ca
.
_f
[
1
]
==
2.0
,
ca
.
_f
[
1
]
assert
ca
.
_f
[
1
]
==
2.0
,
ca
.
_f
[
1
]
...
@@ -65,20 +51,33 @@ def test_fast_access(a):
...
@@ -65,20 +51,33 @@ def test_fast_access(a):
def
test_new_zero
(
a
):
def
test_new_zero
(
a
):
"""
>>> a = array.array('f', [1.0, 2.0, 3.0])
>>> test_new_zero(a)
array('f', [0.0, 0.0, 0.0])
"""
cdef
array
.
array
cb
=
array
.
zeros_like
(
a
)
cdef
array
.
array
cb
=
array
.
zeros_like
(
a
)
assert
cb
.
length
==
len
(
a
)
assert
cb
.
length
==
len
(
a
)
return
cb
return
cb
def
test_set_zero
(
a
):
def
test_set_zero
(
a
):
"""
>>> a = array.array('f', [1.0, 2.0, 3.0])
>>> test_set_zero(a)
array('f', [0.0, 0.0, 0.0])
"""
cdef
array
.
array
cb
=
array
.
copy
(
a
)
cdef
array
.
array
cb
=
array
.
copy
(
a
)
array
.
zero
(
cb
)
array
.
zero
(
cb
)
assert
a
[
1
]
!=
0.0
,
a
assert
a
[
1
]
!=
0.0
,
a
assert
cb
[
1
]
==
0.0
,
cb
assert
cb
[
1
]
==
0.0
,
cb
return
cb
return
cb
def
test_resize
(
a
):
def
test_resize
(
a
):
"""
>>> a = array.array('f', [1.0, 2.0, 3.0])
>>> test_resize(a)
"""
cdef
array
.
array
cb
=
array
.
copy
(
a
)
cdef
array
.
array
cb
=
array
.
copy
(
a
)
array
.
resize
(
cb
,
10
)
array
.
resize
(
cb
,
10
)
for
i
in
range
(
10
):
for
i
in
range
(
10
):
...
@@ -86,27 +85,43 @@ def test_resize(a):
...
@@ -86,27 +85,43 @@ def test_resize(a):
assert
cb
.
length
==
10
assert
cb
.
length
==
10
assert
cb
[
9
]
==
cb
[
-
1
]
==
cb
.
_f
[
9
]
==
9
assert
cb
[
9
]
==
cb
[
-
1
]
==
cb
.
_f
[
9
]
==
9
def
test_view
():
def
test_view
():
"""
>>> a = array.array('f', [1.0, 2.0, 3.0])
>>> test_view()
"""
a
=
array
.
array
(
'i'
,
[
1
,
2
,
3
])
a
=
array
.
array
(
'i'
,
[
1
,
2
,
3
])
cdef
array
.
array
[
int
]
ca
=
a
cdef
object
[
int
]
ca
=
a
assert
ca
.
_i
[
0
]
==
1
assert
ca
[
0
]
==
1
assert
ca
.
_i
[
2
]
==
3
assert
ca
[
2
]
==
3
def
test_extend
():
def
test_extend
():
"""
>>> a = array.array('f', [1.0, 2.0, 3.0])
>>> test_extend()
"""
cdef
array
.
array
ca
=
array
.
array
(
'i'
,
[
1
,
2
,
3
])
cdef
array
.
array
ca
=
array
.
array
(
'i'
,
[
1
,
2
,
3
])
cdef
array
.
array
cb
=
array
.
array
(
'i'
,
range
(
4
,
6
))
cdef
array
.
array
cb
=
array
.
array
(
'i'
,
range
(
4
,
6
))
array
.
extend
(
ca
,
cb
)
array
.
extend
(
ca
,
cb
)
assert
list
(
ca
)
==
range
(
1
,
6
),
list
(
ca
)
assert
list
(
ca
)
==
range
(
1
,
6
),
list
(
ca
)
def
test_likes
(
a
):
def
test_likes
(
a
):
"""
>>> a = array.array('f', [1.0, 2.0, 3.0])
>>> test_likes(a)
array('f', [0.0, 0.0, 0.0])
"""
cdef
array
.
array
z
=
array
.
zeros_like
(
a
)
cdef
array
.
array
z
=
array
.
zeros_like
(
a
)
cdef
array
.
array
e
=
array
.
empty_like
(
a
)
cdef
array
.
array
e
=
array
.
empty_like
(
a
)
assert
e
.
length
==
len
(
a
)
assert
e
.
length
==
len
(
a
)
return
z
return
z
def
test_extend_buffer
():
def
test_extend_buffer
():
"""
>>> a = array.array('f', [1.0, 2.0, 3.0])
>>> test_extend_buffer()
array('c', 'abcdefghij')
"""
cdef
array
.
array
ca
=
array
.
array
(
'c'
,
"abcdef"
)
cdef
array
.
array
ca
=
array
.
array
(
'c'
,
"abcdef"
)
cdef
char
*
s
=
"ghij"
cdef
char
*
s
=
"ghij"
array
.
extend_buffer
(
ca
,
s
,
len
(
s
))
# or use stdlib.strlen
array
.
extend_buffer
(
ca
,
s
,
len
(
s
))
# or use stdlib.strlen
...
...
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