Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project!

## pyode-commits

 [Pyode-commits] pyode/tests test_xode.py,1.1,1.2 From: Timothy Stranex - 2004-07-16 11:45:27 ```Update of /cvsroot/pyode/pyode/tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24225/tests Modified Files: test_xode.py Log Message: xode/ * Added Geom parser. * Fixed some mistakes in transform.py. * Moved exception classes from parser.py to errors.py. examples/ * Added the xml encoding attribute to the XODE document in tutorial2.py * Added an example to demonstrate XODE's transform features. tests/ * Added Geom tests to test_xode.py. Index: test_xode.py =================================================================== RCS file: /cvsroot/pyode/pyode/tests/test_xode.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** test_xode.py 7 Jul 2004 11:46:32 -0000 1.1 --- test_xode.py 16 Jul 2004 11:45:17 -0000 1.2 *************** *** 3,7 **** import unittest import ode ! from xode import node, transform, parser test_doc = ''' --- 3,8 ---- import unittest import ode ! import math ! from xode import node, transform, parser, errors test_doc = ''' *************** *** 50,53 **** --- 51,58 ---- + + + + *************** *** 72,85 **** ! ''' class Class1: pass --- 77,167 ---- ! + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ''' + def feq(n1, n2, error=0.1): + """ + Compare two floating point numbers. If the differ by less than C{error}, + return True; otherwise, return False. + """ + + n = math.fabs(n1 - n2) + if (n <= error): + return True + else: + return False + class Class1: pass *************** *** 94,97 **** --- 176,180 ---- self.node2 = node.TreeNode('node2', self.node1) self.node3 = node.TreeNode('node3', self.node2) + self.node4 = node.TreeNode('node4', self.node3) self.t2 = transform.Transform() *************** *** 103,106 **** --- 186,193 ---- self.node3.setNodeTransform(self.t3) + self.t4 = transform.Transform() + self.t4.translate(2.0, 3.0, 1.0) + self.node4.setNodeTransform(self.t4) + self.node1.setODEObject(Class2()) self.node2.setODEObject(Class2()) *************** *** 116,120 **** self.assertEqual(self.node1.getChildren(), [self.node2]) self.assertEqual(self.node2.getChildren(), [self.node3]) ! self.assertEqual(self.node3.getChildren(), []) def testNamedChildLocal(self): --- 203,208 ---- self.assertEqual(self.node1.getChildren(), [self.node2]) self.assertEqual(self.node2.getChildren(), [self.node3]) ! self.assertEqual(self.node3.getChildren(), [self.node4]) ! self.assertEqual(self.node4.getChildren(), []) def testNamedChildLocal(self): *************** *** 143,146 **** --- 231,238 ---- self.assertEqual(self.node3.getTransform().m, ref.m) + def testGetTransformUntil(self): + ref = self.t3 * self.t4 + self.assertEqual(self.node4.getTransform(self.node2).m, ref.m) + class TestParser(unittest.TestCase): def setUp(self): *************** *** 163,166 **** --- 255,259 ---- self.body1 = self.root.namedChild('body1').getODEObject() self.body3 = self.root.namedChild('body3').getODEObject() + self.body6 = self.root.namedChild('body6').getODEObject() def testInstance(self): *************** *** 168,176 **** def testRotation(self): ! # FIXME? ! #self.assertEqual(self.body3.getRotation(), [0.0, 0.0, 1.0, ! # 0.0, 1.0, 0.0, ! # 1.0, 0.0, 0.0]) ! pass def testPosition(self): --- 261,270 ---- def testRotation(self): ! ref = transform.Transform() ! ref.rotate(0.0, 0.0, 0.78) ! ! rot = self.body6.getRotation() ! for n1, n2 in zip(ref.getRotation(), rot): ! self.assert_(feq(n1, n2)) def testPosition(self): *************** *** 254,260 **** def testBallAnchor(self): ! # FIXME? ! #self.assertEqual(self.joint1.getAnchor(), (1.0, 2.0, 3.0)) ! pass class TestTransformParser(TestParser): --- 348,431 ---- def testBallAnchor(self): ! for n1, n2 in zip(self.joint1.getAnchor(), (1.0, 2.0, 3.0)): ! self.assert_(feq(n1, n2)) ! ! class TestGeomParser(TestParser): ! def setUp(self): ! TestParser.setUp(self) ! ! self.geom1 = self.root.namedChild('geom1').getODEObject() ! self.geom2 = self.root.namedChild('geom2').getODEObject() ! self.geom3 = self.root.namedChild('geom3').getODEObject() ! self.geom4 = self.root.namedChild('geom4').getODEObject() ! self.geom5 = self.root.namedChild('geom5').getODEObject() ! self.geom6 = self.root.namedChild('geom6').getODEObject() ! ! self.body1 = self.root.namedChild('body1').getODEObject() ! self.space1 = self.root.namedChild('space1').getODEObject() ! ! def testSpaceAncestor(self): ! self.assertEqual(self.geom1.getSpace(), self.space1) ! ! def testBodyAttach(self): ! self.assertEqual(self.geom1.getBody(), self.body1) ! ! def testBoxInstance(self): ! self.assert_(isinstance(self.geom1, ode.GeomBox)) ! ! def testBoxSize(self): ! self.assertEqual(self.geom1.getLengths(), (10.0, 20.0, 30.0)) ! ! def testCCylinderInstance(self): ! self.assert_(isinstance(self.geom2, ode.GeomCCylinder)) ! ! def testCCylinderParams(self): ! self.assertEqual(self.geom2.getParams(), (15.0, 3.0)) ! ! def testSphereInstance(self): ! self.assert_(isinstance(self.geom5, ode.GeomSphere)) ! ! def testSphereRadius(self): ! self.assertEqual(self.geom5.getRadius(), 23.0) ! ! def testPlaneInstance(self): ! self.assert_(isinstance(self.geom4, ode.GeomPlane)) ! ! def testPlaneParams(self): ! self.assertEqual(self.geom4.getParams(), ((0.0, 1.0, 0.0), 17.0)) ! ! def testRayInstance(self): ! self.assert_(isinstance(self.geom3, ode.GeomRay)) ! ! def testRayLength(self): ! self.assertEqual(self.geom3.getLength(), 11.0) ! ! def testIndependantRotation(self): ! ref = transform.Transform() ! ref.rotate(0.0, 0.0, 0.78) ! ! for n1, n2 in zip(self.geom5.getRotation(), ref.getRotation()): ! self.assert_(feq(n1, n2)) ! ! def testIndependantPosition(self): ! self.assertEqual(self.geom5.getPosition(), (1.0, 2.0, 3.0)) ! ! def testTransformInstance(self): ! self.assert_(isinstance(self.geom6, ode.GeomTransform)) ! ! def testTransformGeomInstance(self): ! self.assert_(isinstance(self.geom6.getGeom(), ode.GeomSphere)) ! ! def testTransformPosition(self): ! pos = self.geom6.getGeom().getPosition() ! self.assertEqual(pos, (1.0, 2.0, 3.0)) ! ! def testTransformRotation(self): ! ref = transform.Transform() ! ref.rotate(0.78, 0.0, 0.0) ! rot = self.geom6.getGeom().getRotation() ! ! for n1, n2 in zip(rot, ref.getRotation()): ! self.assert_(feq(n1, n2)) class TestTransformParser(TestParser): *************** *** 263,266 **** --- 434,439 ---- self.world1 = self.root.namedChild('world1') self.body1 = self.root.namedChild('body1') + self.body5 = self.root.namedChild('body5') + self.body7 = self.root.namedChild('body7') def testMatrixStyle(self): *************** *** 273,280 **** def testVector(self): ref = transform.Transform() - ref.translate(10.0, 11.0, 12.0) ref.rotate(45.0, 45.0, 45.0) ref.scale(2.0, 2.0, 2.0) self.assertEqual(self.body1.getNodeTransform().m, ref.m) def testMultiply(self): --- 446,470 ---- def testVector(self): ref = transform.Transform() ref.rotate(45.0, 45.0, 45.0) + ref.translate(10.0, 11.0, 12.0) ref.scale(2.0, 2.0, 2.0) self.assertEqual(self.body1.getNodeTransform().m, ref.m) + + def testAbsolute(self): + t = self.body7.getTransform() + self.assertEqual(t.m, [[1.0, 2.0, 3.0, 4.0], + [1.2, 2.2, 3.2, 4.2], + [1.4, 2.4, 3.4, 4.4], + [1.8, 2.8, 3.8, 4.8]]) + + def testRelative(self): + t1 = transform.Transform() + t1.translate(1.0, 1.0, 1.0) + t2 = transform.Transform() + t2.translate(2.0, 2.0, 2.0) + + t3 = t1 * t2 + + self.assertEqual(self.body5.getTransform().m, t3.m) def testMultiply(self): *************** *** 306,314 **** class TestInvalidTags(TestInvalid): def testRoot(self): ! self.assertRaises(parser.InvalidError, self.p.parseString, '\n') def testRootChild(self): ! self.assertRaises(parser.InvalidError, self.p.parseString, '\n') --- 496,504 ---- class TestInvalidTags(TestInvalid): def testRoot(self): ! self.assertRaises(errors.InvalidError, self.p.parseString, '\n') def testRootChild(self): ! self.assertRaises(errors.ChildError, self.p.parseString, '\n') *************** *** 319,323 **** ''' ! self.assertRaises(parser.InvalidError, self.p.parseString, doc) def testSpaceChild(self): --- 509,513 ---- ''' ! self.assertRaises(errors.ChildError, self.p.parseString, doc) def testSpaceChild(self): *************** *** 327,331 **** ''' ! self.assertRaises(parser.InvalidError, self.p.parseString, doc) def testMassChild(self): --- 517,521 ---- ''' ! self.assertRaises(errors.ChildError, self.p.parseString, doc) def testMassChild(self): *************** *** 339,348 **** ''' ! self.assertRaises(parser.InvalidError, self.p.parseString, doc) def testJointChild(self): doc = ''' ''' ! self.assertRaises(parser.InvalidError, self.p.parseString, doc) class TestInvalidBody(TestInvalid): --- 529,543 ---- ''' ! self.assertRaises(errors.ChildError, self.p.parseString, doc) def testJointChild(self): doc = ''' ''' ! self.assertRaises(errors.ChildError, self.p.parseString, doc) ! ! def testGeomChild(self): ! doc = ''' ! ''' ! self.assertRaises(errors.ChildError, self.p.parseString, doc) class TestInvalidBody(TestInvalid): *************** *** 355,359 **** ''' ! self.assertRaises(parser.InvalidError, self.p.parseString, doc) def testBodyEnable(self): --- 550,554 ---- ''' ! self.assertRaises(errors.InvalidError, self.p.parseString, doc) def testBodyEnable(self): *************** *** 364,368 **** ''' ! self.assertRaises(parser.InvalidError, self.p.parseString, doc) def testFiniteRotationMode(self): --- 559,563 ---- ''' ! self.assertRaises(errors.InvalidError, self.p.parseString, doc) def testFiniteRotationMode(self): *************** *** 374,378 **** ''' ! self.assertRaises(parser.InvalidError, self.p.parseString, doc) def testFiniteRotationAxes(self): --- 569,573 ---- ''' ! self.assertRaises(errors.InvalidError, self.p.parseString, doc) def testFiniteRotationAxes(self): *************** *** 384,388 **** ''' ! self.assertRaises(parser.InvalidError, self.p.parseString, doc) class TestInvalidJoint(TestInvalid): --- 579,583 ---- ''' ! self.assertRaises(errors.InvalidError, self.p.parseString, doc) class TestInvalidJoint(TestInvalid): *************** *** 396,400 **** # both links are ode.environment ! self.assertRaises(parser.InvalidError, self.p.parseString, doc) def testNoType(self): --- 591,595 ---- # both links are ode.environment ! self.assertRaises(errors.InvalidError, self.p.parseString, doc) def testNoType(self): *************** *** 404,408 **** ''' ! self.assertRaises(parser.InvalidError, self.p.parseString, doc) def testWrongType(self): --- 599,603 ---- ''' ! self.assertRaises(errors.InvalidError, self.p.parseString, doc) def testWrongType(self): *************** *** 417,421 **** ''' ! self.assertRaises(parser.InvalidError, self.p.parseString, doc) def testMisplacedReference(self): --- 612,616 ---- ''' ! self.assertRaises(errors.InvalidError, self.p.parseString, doc) def testMisplacedReference(self): *************** *** 432,436 **** # bodies must be defined before the joint ! self.assertRaises(parser.InvalidError, self.p.parseString, doc) if (__name__ == '__main__'): --- 627,640 ---- # bodies must be defined before the joint ! self.assertRaises(errors.InvalidError, self.p.parseString, doc) ! ! class TestInvalidGeom(TestInvalid): ! def testNoType(self): ! doc = ''' ! ! ! ''' ! ! self.assertRaises(errors.InvalidError, self.p.parseString, doc) if (__name__ == '__main__'): ```