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
67164f05
Commit
67164f05
authored
Jul 07, 2009
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More cpp test, don't need cpp file.
parent
f21013a5
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
30 deletions
+32
-30
tests/run/cpp_classes.pyx
tests/run/cpp_classes.pyx
+12
-8
tests/run/shapes.cpp
tests/run/shapes.cpp
+0
-15
tests/run/shapes.h
tests/run/shapes.h
+20
-7
No files found.
tests/run/cpp_classes.pyx
View file @
67164f05
__doc__
=
u"""
>>> test_new_del()
>>> test_rect_area(3, 4)
12
12
.0
>>> test_square_area(15)
225
(225.0, 225.0)
"""
cdef
extern
from
"shapes.
cpp
"
namespace
shapes
:
cdef
extern
from
"shapes.
h
"
namespace
shapes
:
cdef
cppclass
Shape
:
float
area
()
cdef
cppclass
Circle
(
Shape
):
int
radius
__init__
(
int
)
cdef
cppclass
Rectangle
(
Shape
):
int
width
int
height
__init__
(
int
,
int
)
cdef
cppclass
Square
(
Shap
e
):
cdef
cppclass
Square
(
Rectangl
e
):
int
side
__init__
(
int
)
# __init__(int) # need function overloading
def
test_new_del
():
cdef
Rectangle
*
rect
=
new
Rectangle
(
10
,
20
)
cdef
Square
*
sqr
=
new
Squar
e
(
15
)
del
rect
,
sqr
cdef
Circle
*
circ
=
new
Circl
e
(
15
)
del
rect
,
circ
def
test_rect_area
(
w
,
h
):
cdef
Rectangle
*
rect
=
new
Rectangle
(
w
,
h
)
...
...
@@ -33,7 +37,7 @@ def test_rect_area(w, h):
del
rect
def
test_square_area
(
w
):
cdef
Square
*
sqr
=
new
Square
(
w
)
cdef
Square
*
sqr
=
new
Square
(
w
,
w
)
cdef
Rectangle
*
rect
=
sqr
try
:
return
rect
.
area
(),
sqr
.
area
()
...
...
tests/run/shapes.cpp
deleted
100644 → 0
View file @
f21013a5
#include "shapes.h"
using
namespace
shapes
;
Rectangle
::
Rectangle
(
int
width
,
int
height
)
{
this
->
width
=
width
;
this
->
height
=
height
;
}
Square
::
Square
(
int
side
)
{
this
->
side
=
side
;
}
tests/run/shapes.h
View file @
67164f05
...
...
@@ -2,30 +2,43 @@
#define SHAPES_H
namespace
shapes
{
class
Shape
{
public:
virtual
float
area
()
=
0
;
virtual
~
Shape
()
{
}
};
class
Rectangle
:
public
Shape
{
public:
Rectangle
(
int
width
,
int
height
);
Rectangle
(
int
width
,
int
height
)
{
this
->
width
=
width
;
this
->
height
=
height
;
}
float
area
()
{
return
width
*
height
;
}
int
width
;
int
height
;
};
class
Square
:
public
Shap
e
class
Square
:
public
Rectangl
e
{
public:
Square
(
int
side
);
float
area
()
{
return
side
*
side
;
}
Square
(
int
side
)
:
Rectangle
(
side
,
side
)
{
this
->
side
=
side
;
}
/* need until function overloading in Cython */
Square
(
int
side
,
int
ignored
)
:
Rectangle
(
side
,
side
)
{
this
->
side
=
side
;
}
int
side
;
};
class
Circle
:
public
Shape
{
public:
Circle
(
int
radius
)
{
this
->
radius
=
radius
;
}
float
area
()
{
return
3.1415926535897931
f
*
radius
;
}
int
radius
;
};
}
#endif
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