Skip to content
Snippets Groups Projects
Commit 6616a103 authored by Guilhem Saurel's avatar Guilhem Saurel
Browse files

[Python][Test] use numpy.testin.assert_allclose

And also check that AssertionErrors are not silenced
parent 1e56dc47
No related branches found
No related tags found
No related merge requests found
......@@ -4,6 +4,7 @@ import unittest
from numpy import matrix
from numpy.linalg import norm
from numpy.testing import assert_allclose
from hpp_spline import bezier, bezier6, curve_constraints, exact_cubic, from_bezier, polynom, spline_deriv_constraint
......@@ -22,7 +23,7 @@ class TestSpline(unittest.TestCase):
a.min()
a.max()
a(0.4)
self.assertTrue((a.derivate(0.4, 0) == a(0.4)).all())
assert_allclose(a.derivate(0.4, 0), a(0.4))
a.derivate(0.4, 2)
a = a.compute_derivate(100)
......@@ -30,14 +31,14 @@ class TestSpline(unittest.TestCase):
for i in range(10):
t = float(i) / 10.
self.assertTrue((a(t) == prim.derivate(t, 1)).all())
self.assertTrue((prim(0) == matrix([0., 0., 0.])).all())
assert_allclose(a(t), prim.derivate(t, 1))
assert_allclose(prim(0), matrix([0., 0., 0.]).T)
prim = a.compute_primitive(2)
for i in range(10):
t = float(i) / 10.
self.assertTrue((a(t) == prim.derivate(t, 2)).all())
self.assertTrue((prim(0) == matrix([0., 0., 0.])).all())
assert_allclose(a(t), prim.derivate(t, 2))
assert_allclose(prim(0), matrix([0., 0., 0.]).T)
waypoints = matrix([[1., 2., 3.], [4., 5., 6.], [4., 5., 6.], [4., 5., 6.], [4., 5., 6.]]).T
a0 = bezier(waypoints)
......@@ -47,11 +48,13 @@ class TestSpline(unittest.TestCase):
for i in range(10):
t = float(i) / 10.
self.assertAlmostEqual(norm(a0(t) - a1(3 * t)), 0)
self.assertAlmostEqual(norm(a0.derivate(t, 1) - a1.derivate(3 * t, 1) * 3.), 0)
self.assertAlmostEqual(norm(a0.derivate(t, 2) - a1.derivate(3 * t, 2) * 9.), 0)
self.assertAlmostEqual(norm(prim0(t) - prim1(t * 3) / 3.), 0)
self.assertTrue((prim(0) == matrix([0., 0., 0.]).T).all())
assert_allclose(a0(t), a1(3 * t))
assert_allclose(a0.derivate(t, 1), a1.derivate(3 * t, 1) * 3.)
assert_allclose(a0.derivate(t, 2), a1.derivate(3 * t, 2) * 9.)
assert_allclose(prim0(t), prim1(t * 3) / 3.)
assert_allclose(prim(0), matrix([0., 0., 0.]).T)
with self.assertRaises(AssertionError):
assert_allclose(prim(0), matrix([0., 0., 0.]))
# testing bezier with constraints
c = curve_constraints()
......@@ -62,8 +65,8 @@ class TestSpline(unittest.TestCase):
waypoints = matrix([[1., 2., 3.], [4., 5., 6.]]).T
a = bezier(waypoints, c)
self.assertAlmostEqual(norm(a.derivate(0, 1) - c.init_vel), 0)
self.assertAlmostEqual(norm(a.derivate(1, 2) - c.end_acc), 0)
assert_allclose(a.derivate(0, 1), c.init_vel)
assert_allclose(a.derivate(1, 2), c.end_acc)
# testing polynom function
a = polynom(waypoints)
......@@ -71,7 +74,7 @@ class TestSpline(unittest.TestCase):
a.min()
a.max()
a(0.4)
self.assertTrue((a.derivate(0.4, 0) == a(0.4)).all())
assert_allclose(a.derivate(0.4, 0), a(0.4))
a.derivate(0.4, 2)
# testing exact_cubic function
......@@ -79,7 +82,7 @@ class TestSpline(unittest.TestCase):
a.min()
a.max()
a(0.4)
self.assertTrue((a.derivate(0.4, 0) == a(0.4)).all())
assert_allclose(a.derivate(0.4, 0), a(0.4))
a.derivate(0.4, 2)
# testing spline_deriv_constraints
......@@ -101,7 +104,7 @@ class TestSpline(unittest.TestCase):
a = bezier(waypoints)
a_pol = from_bezier(a)
self.assertAlmostEqual(norm(a(0.3) - a_pol(0.3)), 0)
assert_allclose(a(0.3), a_pol(0.3))
if __name__ == '__main__':
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment