From 654b95df67b47f9f67ee754e7b1430d9a6e80091 Mon Sep 17 00:00:00 2001 From: azv Date: Thu, 10 Oct 2019 15:37:51 +0300 Subject: [PATCH] Avoid instability in unit-test for Distance constraint applied to Ellipse feature. --- .../Test/TestConstraintDistanceEllipse.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/SketchPlugin/Test/TestConstraintDistanceEllipse.py b/src/SketchPlugin/Test/TestConstraintDistanceEllipse.py index 6ec2980ca..768224aee 100644 --- a/src/SketchPlugin/Test/TestConstraintDistanceEllipse.py +++ b/src/SketchPlugin/Test/TestConstraintDistanceEllipse.py @@ -30,6 +30,7 @@ from GeomAPI import * from SketchAPI import * __updated__ = "2019-09-12" +TOLERANCE = 1.e-7 class TestDistanceEllipse(unittest.TestCase): def setUp(self): @@ -56,7 +57,7 @@ class TestDistanceEllipse(unittest.TestCase): self.myMinorStart = macroEllipse.minorAxisStart() self.myMinorEnd = macroEllipse.minorAxisEnd() self.myExpectFailure = False - self.myDistance = 20 + self.myDistance = 50 def tearDown(self): model.end() @@ -91,7 +92,8 @@ class TestDistanceEllipse(unittest.TestCase): self.myDOF -= 1 model.do() if not self.myExpectFailure: - self.assertAlmostEqual(model.distancePointPoint(thePoint1, thePoint2), self.myDistance) + NB_DIGITS = math.floor(-math.log10(TOLERANCE) - math.log10(self.myDistance)) + self.assertAlmostEqual(model.distancePointPoint(thePoint1, thePoint2), self.myDistance, NB_DIGITS) self.assertGreater(self.myEllipse.majorRadius().value(), 0.0) self.assertGreater(self.myEllipse.minorRadius().value(), 0.0) @@ -99,13 +101,15 @@ class TestDistanceEllipse(unittest.TestCase): self.mySketch.setDistance(thePoint, theLine.result(), self.myDistance) self.myDOF -= 1 model.do() - self.assertAlmostEqual(model.distancePointLine(thePoint, theLine), self.myDistance) + NB_DIGITS = math.floor(-math.log10(TOLERANCE) - math.log10(self.myDistance)) + self.assertAlmostEqual(model.distancePointLine(thePoint, theLine), self.myDistance, NB_DIGITS) self.assertGreater(self.myEllipse.majorRadius().value(), 0.0) self.assertGreater(self.myEllipse.minorRadius().value(), 0.0) def assertPoints(self, thePoint1, thePoint2): - self.assertAlmostEqual(thePoint1.x(), thePoint2.x()) - self.assertAlmostEqual(thePoint1.y(), thePoint2.y()) + NB_DIGITS = math.floor(-math.log10(TOLERANCE) - math.log10(self.myDistance)) + self.assertAlmostEqual(thePoint1.x(), thePoint2.x(), NB_DIGITS) + self.assertAlmostEqual(thePoint1.y(), thePoint2.y(), NB_DIGITS) def test_distance_center(self): -- 2.39.2