From: Robert Bradshaw Date: Tue, 7 Jul 2009 09:13:38 +0000 (-0700) Subject: More cpp test, don't need cpp file. X-Git-Tag: 0.13.beta0~353^2~67 X-Git-Url: http://git.tremily.us/gitweb.cgi?a=commitdiff_plain;h=67164f050d3f432e54958f42111950688ff7b26f;p=cython.git More cpp test, don't need cpp file. --- diff --git a/tests/run/cpp_classes.pyx b/tests/run/cpp_classes.pyx index e0d7e1b2..d56be4e4 100644 --- a/tests/run/cpp_classes.pyx +++ b/tests/run/cpp_classes.pyx @@ -1,29 +1,33 @@ __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(Shape): + cdef cppclass Square(Rectangle): int side - __init__(int) + # __init__(int) # need function overloading def test_new_del(): cdef Rectangle *rect = new Rectangle(10, 20) - cdef Square *sqr = new Square(15) - del rect, sqr + cdef Circle *circ = new Circle(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() diff --git a/tests/run/shapes.cpp b/tests/run/shapes.cpp deleted file mode 100644 index 11f6e2f2..00000000 --- a/tests/run/shapes.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#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; -} - diff --git a/tests/run/shapes.h b/tests/run/shapes.h index 54c31f08..19dd2fce 100644 --- a/tests/run/shapes.h +++ b/tests/run/shapes.h @@ -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 Shape + + class Square : public Rectangle { 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.1415926535897931f * radius; } + int radius; + }; + } + #endif