diff --git a/tests/test_cases_for_stubgen.cpp b/tests/test_cases_for_stubgen.cpp index 75c172ba7..7b55ce699 100644 --- a/tests/test_cases_for_stubgen.cpp +++ b/tests/test_cases_for_stubgen.cpp @@ -13,60 +13,43 @@ namespace test_cases_for_stubgen { namespace basics { -int answer() { - return 42; -} +int answer() { return 42; } -int sum(int a, int b) { - return a + b; -} +int sum(int a, int b) { return a + b; } -double midpoint(double left, double right){ - return left + (right - left)/2; -} +double midpoint(double left, double right) { return left + (right - left) / 2; } -double weighted_midpoint(double left, double right, double alpha=0.5) { - return left + (right - left) * alpha; +double weighted_midpoint(double left, double right, double alpha = 0.5) { + return left + (right - left) * alpha; } struct Point { - enum class LengthUnit { - mm=0, - pixel, - inch - }; + enum class LengthUnit { mm = 0, pixel, inch }; - enum class AngleUnit { - radian=0, - degree - }; + enum class AngleUnit { radian = 0, degree }; - Point() : Point(0, 0) {} - Point(double x, double y) : x(x), y(y) {} + Point() : Point(0, 0) {} + Point(double x, double y) : x(x), y(y) {} - static const Point origin; - static const Point x_axis; - static const Point y_axis; + static const Point origin; + static const Point x_axis; + static const Point y_axis; - static LengthUnit length_unit; - static AngleUnit angle_unit; + static LengthUnit length_unit; + static AngleUnit angle_unit; - double length() const { - return std::sqrt(x * x + y * y); - } + double length() const { return std::sqrt(x * x + y * y); } - double distance_to(double other_x, double other_y) const { - double dx = x - other_x; - double dy = y - other_y; - return std::sqrt(dx*dx + dy*dy); - } + double distance_to(double other_x, double other_y) const { + double dx = x - other_x; + double dy = y - other_y; + return std::sqrt(dx * dx + dy * dy); + } - double distance_to(const Point& other) const { - return distance_to(other.x, other.y); - } + double distance_to(const Point &other) const { return distance_to(other.x, other.y); } - double x, y; + double x, y; }; const Point Point::origin = Point(0, 0); @@ -76,56 +59,63 @@ const Point Point::y_axis = Point(0, 1); Point::LengthUnit Point::length_unit = Point::LengthUnit::mm; Point::AngleUnit Point::angle_unit = Point::AngleUnit::radian; -} // namespace: basics +} // namespace basics -void bind_basics(py::module& basics) { +void bind_basics(py::module &basics) { - using namespace basics; + using namespace basics; - // Functions - basics.def("answer", &answer, "answer docstring, with end quote\""); // tests explicit docstrings - basics.def("sum", &sum, "multiline docstring test, edge case quotes \"\"\"'''"); - basics.def("midpoint", &midpoint, py::arg("left"), py::arg("right")); - basics.def("weighted_midpoint", weighted_midpoint, py::arg("left"), py::arg("right"), py::arg("alpha")=0.5); + // Functions + basics.def( + "answer", &answer, "answer docstring, with end quote\""); // tests explicit docstrings + basics.def("sum", &sum, "multiline docstring test, edge case quotes \"\"\"'''"); + basics.def("midpoint", &midpoint, py::arg("left"), py::arg("right")); + basics.def("weighted_midpoint", + weighted_midpoint, + py::arg("left"), + py::arg("right"), + py::arg("alpha") = 0.5); - // Classes - py::class_ pyPoint(basics, "Point"); - py::enum_ pyLengthUnit(pyPoint, "LengthUnit"); - py::enum_ pyAngleUnit(pyPoint, "AngleUnit"); + // Classes + py::class_ pyPoint(basics, "Point"); + py::enum_ pyLengthUnit(pyPoint, "LengthUnit"); + py::enum_ pyAngleUnit(pyPoint, "AngleUnit"); - pyPoint - .def(py::init<>()) - .def(py::init(), py::arg("x"), py::arg("y")) - .def("distance_to", py::overload_cast(&Point::distance_to, py::const_), py::arg("x"), py::arg("y")) - .def("distance_to", py::overload_cast(&Point::distance_to, py::const_), py::arg("other")) - .def_readwrite("x", &Point::x) - .def_property("y", - [](Point& self){ return self.y; }, - [](Point& self, double value){ self.y = value; } - ) - .def_property_readonly("length", &Point::length) - .def_property_readonly_static("x_axis", [](py::object /*cls*/){return Point::x_axis;}) - .def_property_readonly_static("y_axis", [](py::object /*cls*/){return Point::y_axis;}) - .def_readwrite_static("length_unit", &Point::length_unit) - .def_property_static("angle_unit", - [](py::object& /*cls*/){ return Point::angle_unit; }, - [](py::object& /*cls*/, Point::AngleUnit value){ Point::angle_unit = value; } - ); + pyPoint.def(py::init<>()) + .def(py::init(), py::arg("x"), py::arg("y")) + .def("distance_to", + py::overload_cast(&Point::distance_to, py::const_), + py::arg("x"), + py::arg("y")) + .def("distance_to", + py::overload_cast(&Point::distance_to, py::const_), + py::arg("other")) + .def_readwrite("x", &Point::x) + .def_property( + "y", + [](Point &self) { return self.y; }, + [](Point &self, double value) { self.y = value; }) + .def_property_readonly("length", &Point::length) + .def_property_readonly_static("x_axis", [](py::object /*cls*/) { return Point::x_axis; }) + .def_property_readonly_static("y_axis", [](py::object /*cls*/) { return Point::y_axis; }) + .def_readwrite_static("length_unit", &Point::length_unit) + .def_property_static( + "angle_unit", + [](py::object & /*cls*/) { return Point::angle_unit; }, + [](py::object & /*cls*/, Point::AngleUnit value) { Point::angle_unit = value; }); - pyPoint.attr("origin") = Point::origin; + pyPoint.attr("origin") = Point::origin; - pyLengthUnit - .value("mm", Point::LengthUnit::mm) - .value("pixel", Point::LengthUnit::pixel) - .value("inch", Point::LengthUnit::inch); + pyLengthUnit.value("mm", Point::LengthUnit::mm) + .value("pixel", Point::LengthUnit::pixel) + .value("inch", Point::LengthUnit::inch); - pyAngleUnit - .value("radian", Point::AngleUnit::radian) - .value("degree", Point::AngleUnit::degree); + pyAngleUnit.value("radian", Point::AngleUnit::radian) + .value("degree", Point::AngleUnit::degree); - // Module-level attributes - basics.attr("PI") = std::acos(-1); - basics.attr("__version__") = "0.0.1"; + // Module-level attributes + basics.attr("PI") = std::acos(-1); + basics.attr("__version__") = "0.0.1"; } struct UserType {