Skip to content

Commit

Permalink
#17 add tests for default args
Browse files Browse the repository at this point in the history
  • Loading branch information
kwabenantim committed Jul 29, 2024
1 parent aef7c93 commit 202d573
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 9 deletions.
16 changes: 13 additions & 3 deletions examples/shapes/src/primitives/Rectangle.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
#include <cassert>
#include <memory>

#include "Point.hpp"
#include "Rectangle.hpp"

Rectangle::Rectangle(double width, double height) :
Shape<2>()
Rectangle::Rectangle(double width, double height) : Shape<2>()
{
this->mVertices.push_back(std::make_shared<Point<2> >(0.0, 0.0));
this->mVertices.push_back(std::make_shared<Point<2> >(width, 0.0));
this->mVertices.push_back(std::make_shared<Point<2> >(width, height));
this->mVertices.push_back(std::make_shared<Point<2> >(0.0, height));
}

Rectangle::~Rectangle()
Rectangle::Rectangle(const std::vector<std::shared_ptr<Point<2> > > points) : Shape<2>()
{
assert(points.size() == 4);

for (unsigned i = 0; i < points.size(); ++i)
{
this->mVertices.push_back(points[i]);
}
}

Rectangle::~Rectangle()
{
}
10 changes: 7 additions & 3 deletions examples/shapes/src/primitives/Rectangle.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef _RECTANGLE_HPP
#define _RECTANGLE_HPP

#include "Point.hpp"
#include "Shape.hpp"

/**
Expand All @@ -10,17 +11,20 @@ class Rectangle : public Shape<2>
{

public:

/**
* Default Constructor
*/
Rectangle(double width = 2.0, double height = 1.0);

/**
* Construct from points
*/
Rectangle(const std::vector<std::shared_ptr<Point<2> > > points = {});

/**
* Destructor
*/
~Rectangle();

};

#endif // _RECTANGLE_HPP
#endif // _RECTANGLE_HPP
16 changes: 13 additions & 3 deletions examples/shapes/src/python/test/test_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,27 @@ def testGeometry(self):
p0 = pyshapes.geometry.Point2()
self.assertTrue(p0.GetLocation() == [0.0, 0.0])

p1 = pyshapes.geometry.Point2(0.0, 0.0)
p2 = pyshapes.geometry.Point2(1.0, 0.0)
p3 = pyshapes.geometry.Point2(0.0, 1.0)
p1 = pyshapes.geometry.Point2(5.0, 0.0)
self.assertTrue(p1.GetLocation() == [5.0, 0.0])

p2 = pyshapes.geometry.Point2(5.0, 5.0)
self.assertTrue(p2.GetLocation() == [5.0, 5.0])

p3 = pyshapes.geometry.Point2(0.0, 5.0)
self.assertTrue(p3.GetLocation() == [0.0, 5.0])

points = [p1, p2, p3]

triangle = pyshapes.primitives.Shape2()
triangle.SetVertices(points)
self.assertTrue(len(triangle.rGetVertices()) == 3)

rectangle = pyshapes.primitives.Rectangle(5.0, 10.0)
self.assertTrue(len(rectangle.rGetVertices()) == 4)

rectangle = pyshapes.primitives.Rectangle([p0, p1, p2, p3])
self.assertTrue(rectangle.rGetVertices() == [p0, p1, p2, p3])

cuboid = pyshapes.primitives.Cuboid(5.0, 10.0, 20.0)
self.assertTrue(len(cuboid.rGetVertices()) == 8)

Expand Down
1 change: 1 addition & 0 deletions examples/shapes/wrapper/primitives/Rectangle.cppwg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ PYBIND11_DECLARE_HOLDER_TYPE(T, std::shared_ptr<T>);
void register_Rectangle_class(py::module &m){
py::class_<Rectangle , std::shared_ptr<Rectangle > , Shape<2> >(m, "Rectangle")
.def(py::init<double, double >(), py::arg("width") = 2., py::arg("height") = 1.)
.def(py::init<::std::vector<std::shared_ptr<Point<2>>> const >(), py::arg("points") = ::std::vector<std::shared_ptr<Point<2>>> {})
;
}

0 comments on commit 202d573

Please sign in to comment.