Commit 60d110ff authored by Stefan Behnel's avatar Stefan Behnel

moved doctests from module docstring into test functions

parent f0b93467
# tag: cpp # tag: cpp
__doc__ = u"""
>>> test_new_del()
(2, 2)
>>> test_rect_area(3, 4)
12.0
>>> test_square_area(15)
(225.0, 225.0)
>>> test_overload_bint_int()
202
201
"""
cdef extern from "shapes.h" namespace "shapes": cdef extern from "shapes.h" namespace "shapes":
cdef cppclass Shape: cdef cppclass Shape:
...@@ -39,12 +27,23 @@ cdef extern from "shapes.h" namespace "shapes": ...@@ -39,12 +27,23 @@ cdef extern from "shapes.h" namespace "shapes":
int constructor_count, destructor_count int constructor_count, destructor_count
def test_new_del(): def test_new_del():
"""
>>> test_new_del()
2 0
2 2
"""
c,d = constructor_count, destructor_count
cdef Rectangle *rect = new Rectangle(10, 20) cdef Rectangle *rect = new Rectangle(10, 20)
cdef Circle *circ = new Circle(15) cdef Circle *circ = new Circle(15)
print constructor_count-c, destructor_count-d
del rect, circ del rect, circ
return constructor_count, destructor_count print constructor_count-c, destructor_count-d
def test_rect_area(w, h): def test_rect_area(w, h):
"""
>>> test_rect_area(3, 4)
12.0
"""
cdef Rectangle *rect = new Rectangle(w, h) cdef Rectangle *rect = new Rectangle(w, h)
try: try:
return rect.area() return rect.area()
...@@ -52,6 +51,11 @@ def test_rect_area(w, h): ...@@ -52,6 +51,11 @@ def test_rect_area(w, h):
del rect del rect
def test_overload_bint_int(): def test_overload_bint_int():
"""
>>> test_overload_bint_int()
202
201
"""
cdef Rectangle *rect1 = new Rectangle(10, 20) cdef Rectangle *rect1 = new Rectangle(10, 20)
cdef Rectangle *rect2 = new Rectangle(10, 20) cdef Rectangle *rect2 = new Rectangle(10, 20)
...@@ -63,6 +67,10 @@ def test_overload_bint_int(): ...@@ -63,6 +67,10 @@ def test_overload_bint_int():
del rect2 del rect2
def test_square_area(w): def test_square_area(w):
"""
>>> test_square_area(15)
(225.0, 225.0)
"""
cdef Square *sqr = new Square(w) cdef Square *sqr = new Square(w)
cdef Rectangle *rect = sqr cdef Rectangle *rect = sqr
try: try:
......
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