Commit f21013a5 authored by Robert Bradshaw's avatar Robert Bradshaw

Expand and fix cpp tests

parent 1ca9c605
cdef extern from "shapes.h" namespace shapes: __doc__ = u"""
>>> test_new_del()
>>> test_rect_area(3, 4)
12
>>> test_square_area(15)
225
"""
cdef extern from "shapes.cpp" namespace shapes:
cdef cppclass Shape: cdef cppclass Shape:
area() float area()
cdef cppclass Rectangle(Shape): cdef cppclass Rectangle(Shape):
int width int width
...@@ -12,7 +20,23 @@ cdef extern from "shapes.h" namespace shapes: ...@@ -12,7 +20,23 @@ cdef extern from "shapes.h" namespace shapes:
int side int side
__init__(int) __init__(int)
cdef Rectangle *rect = new Rectangle(10, 20) def test_new_del():
cdef Square *sqr = new Square(15) cdef Rectangle *rect = new Rectangle(10, 20)
cdef Square *sqr = new Square(15)
del rect, sqr
def test_rect_area(w, h):
cdef Rectangle *rect = new Rectangle(w, h)
try:
return rect.area()
finally:
del rect
def test_square_area(w):
cdef Square *sqr = new Square(w)
cdef Rectangle *rect = sqr
try:
return rect.area(), sqr.area()
finally:
del sqr
del rect, sqr
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment