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
e8a12c46
Commit
e8a12c46
authored
May 12, 2013
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
extend SwitchTransform tests
parent
e8b4275a
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
63 additions
and
0 deletions
+63
-0
tests/run/switch.pyx
tests/run/switch.pyx
+63
-0
No files found.
tests/run/switch.pyx
View file @
e8a12c46
...
...
@@ -4,6 +4,7 @@ cimport cython
@
cython
.
test_fail_if_path_exists
(
'//SwitchStatNode'
)
@
cython
.
test_assert_path_exists
(
'//IfStatNode'
)
def
switch_simple_py
(
x
):
"""
>>> switch_simple_py(1)
...
...
@@ -31,6 +32,7 @@ def switch_simple_py(x):
@
cython
.
test_fail_if_path_exists
(
'//SwitchStatNode'
)
@
cython
.
test_assert_path_exists
(
'//IfStatNode'
)
def
switch_py
(
x
):
"""
>>> switch_py(1)
...
...
@@ -72,6 +74,7 @@ def switch_py(x):
@
cython
.
test_assert_path_exists
(
'//SwitchStatNode'
)
@
cython
.
test_fail_if_path_exists
(
'//IfStatNode'
)
def
switch_simple_c
(
int
x
):
"""
>>> switch_simple_c(1)
...
...
@@ -99,6 +102,7 @@ def switch_simple_c(int x):
@
cython
.
test_assert_path_exists
(
'//SwitchStatNode'
)
@
cython
.
test_fail_if_path_exists
(
'//IfStatNode'
)
def
switch_c
(
int
x
):
"""
>>> switch_c(1)
...
...
@@ -140,6 +144,7 @@ def switch_c(int x):
@
cython
.
test_assert_path_exists
(
'//SwitchStatNode'
)
@
cython
.
test_fail_if_path_exists
(
'//IfStatNode'
)
def
switch_or
(
int
x
):
"""
>>> switch_or(0)
...
...
@@ -161,6 +166,7 @@ def switch_or(int x):
@
cython
.
test_assert_path_exists
(
'//SwitchStatNode'
)
@
cython
.
test_fail_if_path_exists
(
'//IfStatNode'
)
def
switch_in
(
int
X
):
"""
>>> switch_in(0)
...
...
@@ -180,6 +186,7 @@ def switch_in(int X):
@
cython
.
test_assert_path_exists
(
'//SwitchStatNode'
)
@
cython
.
test_fail_if_path_exists
(
'//IfStatNode'
)
def
switch_short
(
int
x
):
"""
>>> switch_short(0)
...
...
@@ -201,6 +208,7 @@ def switch_short(int x):
@
cython
.
test_fail_if_path_exists
(
'//SwitchStatNode'
)
@
cython
.
test_assert_path_exists
(
'//IfStatNode'
)
def
switch_off
(
int
x
):
"""
>>> switch_off(0)
...
...
@@ -217,7 +225,9 @@ def switch_off(int x):
return
-
1
@
cython
.
test_assert_path_exists
(
'//SwitchStatNode'
)
@
cython
.
test_fail_if_path_exists
(
'//IfStatNode'
)
def
switch_pass
(
int
x
):
"""
>>> switch_pass(1)
...
...
@@ -235,6 +245,7 @@ def switch_pass(int x):
DEF
t
=
(
1
,
2
,
3
,
4
,
5
,
6
)
@
cython
.
test_assert_path_exists
(
'//SwitchStatNode'
)
@
cython
.
test_fail_if_path_exists
(
'//IfStatNode'
)
def
compile_time_tuple_constant
(
int
x
):
"""
>>> compile_time_tuple_constant(1)
...
...
@@ -249,6 +260,7 @@ def compile_time_tuple_constant(int x):
else
:
return
False
cdef
enum
X
:
a
=
1
b
...
...
@@ -258,6 +270,7 @@ cdef enum X:
f
=
100
@
cython
.
test_assert_path_exists
(
'//SwitchStatNode'
)
@
cython
.
test_fail_if_path_exists
(
'//IfStatNode'
)
def
enum_switch
(
X
x
):
"""
>>> enum_switch(1)
...
...
@@ -273,3 +286,53 @@ def enum_switch(X x):
return
1
else
:
return
2
@
cython
.
test_assert_path_exists
(
'//IfStatNode'
)
@
cython
.
test_assert_path_exists
(
'//IfStatNode//SwitchStatNode'
)
def
enum_duplicates
(
X
x
):
"""
>>> enum_duplicates(1)
0
>>> enum_duplicates(2) # b
0
>>> enum_duplicates(10)
1
>>> enum_duplicates(100)
3
"""
if
x
in
[
a
,
b
,
c
,
d
]:
# switch is ok here!
return
0
elif
x
==
e
:
return
1
elif
x
==
b
:
# duplicate => no switch here!
return
2
else
:
return
3
@
cython
.
test_assert_path_exists
(
'//SwitchStatNode'
)
@
cython
.
test_fail_if_path_exists
(
'//IfStatNode'
)
def
int_enum_switch_mix
(
int
x
):
"""
>>> int_enum_switch_mix(1)
0
>>> int_enum_switch_mix(10)
1
>>> int_enum_switch_mix(ord('X'))
2
>>> int_enum_switch_mix(99)
3
>>> int_enum_switch_mix(100)
4
"""
if
x
in
[
a
,
b
,
c
,
d
]:
return
0
elif
x
==
e
:
return
1
elif
x
==
'X'
:
# ASCII(88)
return
2
elif
x
==
99
:
return
3
else
:
return
4
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