Commit 3b56b868 authored by Pierre Fernbach's avatar Pierre Fernbach
Browse files

[Tests][Python] add python unittest for curve_constraints

parent 11fd64fb
......@@ -11,3 +11,4 @@ ADD_PYTHON_UNIT_TEST("python-minjerk" "python/test/test-minjerk.py" "python")
ADD_PYTHON_UNIT_TEST("python-optimization" "python/test/optimization.py" "python")
ADD_PYTHON_UNIT_TEST("python-notebook" "python/test/notebook.py" "python")
ADD_PYTHON_UNIT_TEST("python-registration" "python/test/registration.py" "python")
ADD_PYTHON_UNIT_TEST("python-curve-constraints" "python/test/test-curve-constraints.py" "python")
# Copyright (c) 2020, CNRS
# Authors: Pierre Fernbach <pfernbac@laas.fr>
import unittest
import curves
from curves import curve_constraints
import numpy as np
import pickle
from numpy import array, isclose, array_equal
class CurveConstraintsTest(unittest.TestCase):
def test_operator_equal(self):
c = curve_constraints(3)
c.init_vel = array([[0., 1., 1.]]).transpose()
c.end_vel = array([[0., -1., 1.]]).transpose()
c.init_acc = array([[0., 1., -1.]]).transpose()
c.end_acc = array([[0., 100., 1.]]).transpose()
c.init_jerk = array([[2., 4., 1.]]).transpose()
c.end_jerk = array([[-1., 2., 7.]]).transpose()
c2 = curve_constraints(3)
c2.init_vel = array([[0., 1., 1.]]).transpose()
c2.end_vel = array([[0., -1., 1.]]).transpose()
c2.init_acc = array([[0., 1., -1.]]).transpose()
c2.end_acc = array([[0., 100., 1.]]).transpose()
c2.init_jerk = array([[2., 4., 1.]]).transpose()
c2.end_jerk = array([[-1., 2., 7.]]).transpose()
self.assertTrue(c == c2)
c2.init_vel = array([[1., 1., 1.]]).transpose()
self.assertTrue(c != c2)
def test_serialization(self):
c = curve_constraints(3)
c.init_vel = array([[0., 1., 1.]]).transpose()
c.end_vel = array([[0., -1., 1.]]).transpose()
c.init_acc = array([[0., 1., -1.]]).transpose()
c.end_acc = array([[0., 100., 1.]]).transpose()
c.init_jerk = array([[2., 4., 1.]]).transpose()
c.end_jerk = array([[-1., 2., 7.]]).transpose()
c.saveAsText("curve_constraints.txt")
c.saveAsXML("curve_constraints.xml", "curve_constraints")
c.saveAsBinary("curve_constraints")
c_txt = curve_constraints()
c_txt.loadFromText("curve_constraints.txt")
self.assertEqual(c, c_txt)
c_xml = curve_constraints()
c_xml.loadFromXML("curve_constraints.xml", "curve_constraints")
self.assertEqual(c, c_xml)
c_bin = curve_constraints()
c_bin.loadFromBinary("curve_constraints")
self.assertEqual(c, c_bin)
c_pickled = pickle.dumps(c)
c_from_pickle = pickle.loads(c_pickled)
self.assertEqual(c_from_pickle, c)
if __name__ == '__main__':
unittest.main()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment