Skip to content

Commit

Permalink
Add a function to compare 2 double allowing approximation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
plgarcia committed Dec 8, 2017
1 parent 9d4cddf commit 361d099
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/Mod/Test/Document.py
Expand Up @@ -23,6 +23,7 @@
#***************************************************************************/

import FreeCAD, os, unittest, tempfile
import math


#---------------------------------------------------------------------------
Expand Down Expand Up @@ -1262,18 +1263,24 @@ def setUp(self):
self.Obj1 = self.Doc.addObject("App::FeatureTest","Test")
self.Obj2 = self.Doc.addObject("App::FeatureTest","Test")

def assertAlmostEqual (self, v1, v2) :
if (math.fabs(v2-v1) > 1E-12) :
self.assertEqual(v1,v2)


def testExpression(self):
# set the object twice to test that the backlinks are removed when overwriting the expression
self.Obj2.setExpression('Placement.Rotation.Angle', u'%s.Placement.Rotation.Angle' % self.Obj1.Name)
self.Obj2.setExpression('Placement.Rotation.Angle', u'%s.Placement.Rotation.Angle' % self.Obj1.Name)
self.Obj1.Placement = FreeCAD.Placement(FreeCAD.Vector(0,0,0),FreeCAD.Rotation(FreeCAD.Vector(0,0,1),10))
self.Doc.recompute()
self.assertEqual(self.Obj1.Placement.Rotation.Angle, self.Obj2.Placement.Rotation.Angle)
self.assertAlmostEqual(self.Obj1.Placement.Rotation.Angle, self.Obj2.Placement.Rotation.Angle)

# clear the expression
self.Obj2.setExpression('Placement.Rotation.Angle', None)
self.assertEqual(self.Obj1.Placement.Rotation.Angle, self.Obj2.Placement.Rotation.Angle)
self.assertAlmostEqual(self.Obj1.Placement.Rotation.Angle, self.Obj2.Placement.Rotation.Angle)
self.Doc.recompute()
self.assertEqual(self.Obj1.Placement.Rotation.Angle, self.Obj2.Placement.Rotation.Angle)
self.assertAlmostEqual(self.Obj1.Placement.Rotation.Angle, self.Obj2.Placement.Rotation.Angle)
# touch the objects to perform a recompute
self.Obj1.Placement = self.Obj1.Placement
self.Obj2.Placement = self.Obj2.Placement
Expand Down

0 comments on commit 361d099

Please sign in to comment.