diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 80a174031222fd1bde12d5deb9687899c1d32f8a..2db77cc854e5afe7f8d759de2a459e4149a9338e 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -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) diff --git a/test/python_unit/CMakeLists.txt b/test/python_unit/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..6d62837aee6187fd6b7e0d3665b3090cc6e0efb2 --- /dev/null +++ b/test/python_unit/CMakeLists.txt @@ -0,0 +1,7 @@ +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}) diff --git a/test/python_unit/geometric_shapes.py b/test/python_unit/geometric_shapes.py new file mode 100644 index 0000000000000000000000000000000000000000..5a005b0e22949eeebeda4d3d87ba2b4beac518fa --- /dev/null +++ b/test/python_unit/geometric_shapes.py @@ -0,0 +1,81 @@ +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