Commit 2517ed88 authored by Gabriele Buondonno's avatar Gabriele Buondonno
Browse files

[test] Python unit tests

parent 3eeb888e
......@@ -57,3 +57,8 @@ endif(HPP_FCL_HAVE_OCTOMAP)
## Benchmark
add_executable(test-benchmark benchmark.cpp)
target_link_libraries(test-benchmark hpp-fcl ${Boost_LIBRARIES} utility)
## Python tests
IF(BUILD_PYTHON_INTERFACE)
ADD_SUBDIRECTORY(python_unit)
ENDIF(BUILD_PYTHON_INTERFACE)
SET(${PROJECT_NAME}_PYTHON_TESTS
geometric_shapes
)
FOREACH(TEST ${${PROJECT_NAME}_PYTHON_TESTS})
ADD_PYTHON_UNIT_TEST("py-${TEST}" "test/python_unit/${TEST}.py" "python")
ENDFOREACH(TEST ${${PROJECT_NAME}_PYTHON_TESTS})
import unittest
import eigenpy
eigenpy.switchToNumpyMatrix()
import hppfcl
import numpy as np
class TestGeometricShapes(unittest.TestCase):
def test_capsule(self):
capsule = hppfcl.Capsule(1.,2.)
self.assertIsInstance(capsule, hppfcl.Capsule)
self.assertIsInstance(capsule, hppfcl.ShapeBase)
self.assertIsInstance(capsule, hppfcl.CollisionGeometry)
self.assertEqual(capsule.getNodeType(), hppfcl.NODE_TYPE.GEOM_CAPSULE)
self.assertEqual(capsule.radius,1.)
self.assertEqual(capsule.lz,2.)
capsule.radius = 3.
capsule.lz = 4.
self.assertEqual(capsule.radius,3.)
self.assertEqual(capsule.lz,4.)
def test_box1(self):
box = hppfcl.Box(np.matrix([1.,2.,3.]).T)
self.assertIsInstance(box, hppfcl.Box)
self.assertIsInstance(box, hppfcl.ShapeBase)
self.assertIsInstance(box, hppfcl.CollisionGeometry)
self.assertEqual(box.getNodeType(), hppfcl.NODE_TYPE.GEOM_BOX)
self.assertTrue(np.array_equal(box.halfSide,np.matrix([.5,1.,1.5]).T))
box.halfSide = np.matrix([4.,5.,6.]).T
self.assertTrue(np.array_equal(box.halfSide,np.matrix([4.,5.,6.]).T))
def test_box2(self):
box = hppfcl.Box(1.,2.,3)
self.assertIsInstance(box, hppfcl.Box)
self.assertIsInstance(box, hppfcl.ShapeBase)
self.assertIsInstance(box, hppfcl.CollisionGeometry)
self.assertEqual(box.getNodeType(), hppfcl.NODE_TYPE.GEOM_BOX)
self.assertEqual(box.halfSide[0],0.5)
self.assertEqual(box.halfSide[1],1.0)
self.assertEqual(box.halfSide[2],1.5)
box.halfSide[0] = 4.
box.halfSide[0] = 5.
box.halfSide[0] = 6.
# self.assertEqual(box.halfSide[0],4.)
# self.assertEqual(box.halfSide[1],5.)
# self.assertEqual(box.halfSide[2],6.)
def test_sphere(self):
sphere = hppfcl.Sphere(1.)
self.assertIsInstance(sphere, hppfcl.Sphere)
self.assertIsInstance(sphere, hppfcl.ShapeBase)
self.assertIsInstance(sphere, hppfcl.CollisionGeometry)
self.assertEqual(sphere.getNodeType(), hppfcl.NODE_TYPE.GEOM_SPHERE)
self.assertEqual(sphere.radius,1.)
sphere.radius = 2.
self.assertEqual(sphere.radius,2.)
def test_cylinder(self):
cylinder = hppfcl.Cylinder(1.,2.)
self.assertIsInstance(cylinder, hppfcl.Cylinder)
self.assertIsInstance(cylinder, hppfcl.ShapeBase)
self.assertIsInstance(cylinder, hppfcl.CollisionGeometry)
self.assertEqual(cylinder.getNodeType(), hppfcl.NODE_TYPE.GEOM_CYLINDER)
self.assertEqual(cylinder.radius,1.)
self.assertEqual(cylinder.lz,2.)
def test_cone(self):
cone = hppfcl.Cone(1.,2.)
self.assertIsInstance(cone, hppfcl.Cone)
self.assertIsInstance(cone, hppfcl.ShapeBase)
self.assertIsInstance(cone, hppfcl.CollisionGeometry)
self.assertEqual(cone.getNodeType(), hppfcl.NODE_TYPE.GEOM_CONE)
self.assertEqual(cone.radius,1.)
self.assertEqual(cone.lz,2.)
cone.radius = 3.
cone.lz = 4.
self.assertEqual(cone.radius,3.)
self.assertEqual(cone.lz,4.)
if __name__ == '__main__':
unittest.main()
\ No newline at end of file
Supports Markdown
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