Browse Source

python: oops, forgot to adapt Vector::minmax().

Because it wasn't tested, at all. So test it.
next
Vladimír Vondruš 3 years ago
parent
commit
1e0559bc0b
  1. 5
      src/python/magnum/math.vector.h
  2. 17
      src/python/magnum/test/test_math.py

5
src/python/magnum/math.vector.h

@ -358,7 +358,10 @@ template<class T> void vector(py::module_& m, py::class_<T>& c) {
.def("product", &T::product, "Product of values in the vector") .def("product", &T::product, "Product of values in the vector")
.def("min", &T::min, "Minimal value in the vector") .def("min", &T::min, "Minimal value in the vector")
.def("max", &T::max, "Maximal value in the vector") .def("max", &T::max, "Maximal value in the vector")
.def("minmax", &T::minmax, "Minimal and maximal value in the vector") .def("minmax", [](const T& self) {
/** @todo bind Containers::Pair directly */
return std::pair<typename T::Type, typename T::Type>{self.minmax()};
}, "Minimal and maximal value in the vector")
.def("__repr__", repr<T>, "Object representation"); .def("__repr__", repr<T>, "Object representation");

17
src/python/magnum/test/test_math.py

@ -260,7 +260,7 @@ class Vector(unittest.TestCase):
#self.assertEqual(len(Vector3), 3) TODO: Y not? #self.assertEqual(len(Vector3), 3) TODO: Y not?
self.assertEqual(len(Vector4i()), 4) self.assertEqual(len(Vector4i()), 4)
def test_properties(self): def test_components(self):
a = Vector2i() a = Vector2i()
a.x = 1 a.x = 1
a.y = 2 a.y = 2
@ -320,7 +320,7 @@ class Vector(unittest.TestCase):
self.assertEqual(a.xyz, Vector3d(0.5, 0.25, 0.125)) self.assertEqual(a.xyz, Vector3d(0.5, 0.25, 0.125))
self.assertEqual(a, Vector4d(0.5, 0.25, 0.125, 4.0)) self.assertEqual(a, Vector4d(0.5, 0.25, 0.125, 4.0))
def test_properties_rgb(self): def test_components_rgb(self):
a = Vector3() a = Vector3()
a.r = 1.0 a.r = 1.0
a.g = 2.0 a.g = 2.0
@ -369,6 +369,19 @@ class Vector(unittest.TestCase):
# representable as floats to avoid the need for delta comparison # representable as floats to avoid the need for delta comparison
self.assertEqual(a, [1.0, 3.25, 3.5, -1.125]) self.assertEqual(a, [1.0, 3.25, 3.5, -1.125])
def test_properties(self):
a = Vector3(1.0, 3.5, -13.5)
b = Vector3i()
self.assertFalse(a.is_zero())
self.assertTrue(b.is_zero())
self.assertAlmostEqual(a.dot(), 195.5)
self.assertEqual(a.flipped(), (-13.5, 3.5, 1.0))
self.assertAlmostEqual(a.sum(), -9.0)
self.assertEqual(a.product(), -47.25)
self.assertEqual(a.min(), -13.5)
self.assertEqual(a.max(), 3.5)
self.assertEqual(a.minmax(), (-13.5, 3.5))
def test_ops(self): def test_ops(self):
self.assertEqual(math.dot(Vector2(0.5, 3.0), Vector2(2.0, 0.5)), 2.5) self.assertEqual(math.dot(Vector2(0.5, 3.0), Vector2(2.0, 0.5)), 2.5)
self.assertEqual(Deg(math.angle( self.assertEqual(Deg(math.angle(

Loading…
Cancel
Save