Salome HOME
Adjust test cases according to updated Arc behavior
authorazv <azv@opencascade.com>
Wed, 29 Mar 2017 15:37:32 +0000 (18:37 +0300)
committerazv <azv@opencascade.com>
Wed, 29 Mar 2017 15:37:53 +0000 (18:37 +0300)
src/PythonAPI/model/tests/tests.py
src/SketchPlugin/Test/TestArcBehavior.py
src/SketchPlugin/Test/TestCreateArcByCenterStartEnd.py

index 68b766385ff109fcd75d92ad92790da2162e8011..2cc13febd619db92e70a9ada4c5fa50429de9116 100644 (file)
@@ -1,8 +1,11 @@
 from GeomAlgoAPI import *
 from GeomAPI import *
+from GeomDataAPI import *
 from ModelAPI import ModelAPI_Feature
 import math
+from salome.shaper.model import sketcher
 
+TOLERANCE = 1.e-7
 
 aShapeTypes = {
   GeomAPI_Shape.SOLID:  "GeomAPI_Shape.SOLID",
@@ -153,3 +156,15 @@ def testNbSubFeatures(theComposite, theKindOfSub, theExpectedCount):
     if aFeature is not None and aFeature.getKind() == theKindOfSub:
        count += 1
   assert (count == theExpectedCount), "Number of sub-features of type {}: {}, expected {}".format(theKindOfSub, count, theExpectedCount)
+
+def assertSketchArc(theArcFeature):
+  """ Tests whether the arc is correctly defined
+  """
+  aCenterPnt = geomDataAPI_Point2D(theArcFeature.attribute("center_point"))
+  aStartPnt = geomDataAPI_Point2D(theArcFeature.attribute("start_point"))
+  aEndPnt = geomDataAPI_Point2D(theArcFeature.attribute("end_point"))
+  aRadius = theArcFeature.real("radius")
+  aDistCS = sketcher.tools.distancePointPoint(aCenterPnt, aStartPnt)
+  aDistCE = sketcher.tools.distancePointPoint(aCenterPnt, aEndPnt)
+  assert math.fabs(aDistCS - aDistCE) < TOLERANCE, "Wrong arc: center-start distance {}, center-end distance {}".format(aDistCS, aDistCE)
+  assert math.fabs(aRadius.value() -aDistCS) < TOLERANCE, "Wrong arc: radius is {0}, expected {1}".format(aRadius.value(), aDistCS)
index b0e31d72978fec2954acaa5b47889144424b5b62..2f8c3f4dbec2575cf10dadadff8aa07247a97122 100644 (file)
@@ -12,6 +12,7 @@
 from GeomDataAPI import *
 from ModelAPI import *
 import math
+from salome.shaper import model
 
 aSession = ModelAPI_Session.get()
 aDocument = aSession.moduleDocument()
@@ -85,8 +86,8 @@ assert shapeToEdge(aSketchArc.lastResult().shape()).length() < 32.
 aSession.startOperation()
 anArcEndPoint.setValue(10., 0.)
 aSession.finishOperation()
-assert shapeToEdge(aSketchArc.lastResult().shape()).length() > 47.
-assert shapeToEdge(aSketchArc.lastResult().shape()).length() < 48.
+assert shapeToEdge(aSketchArc.lastResult().shape()).length() > 46.5
+assert shapeToEdge(aSketchArc.lastResult().shape()).length() < 47.5
 aSession.startOperation()
 anArcEndPoint.setValue(1., 10.)
 aSession.finishOperation()
@@ -132,9 +133,8 @@ for aCenterCoords in range(-20, 20):
   aSession.finishOperation()
   assert aSketchArc.boolean("reversed").value() == anInversed
 #=========================================================================
-# Test that movement of start point of arc does not change central point
+# Test that movement of start point of arc does not break the arc
 #=========================================================================
-TOL = 1.e-5
 x = anArcCentr.x()
 y = anArcCentr.y()
 sx = anArcStartPoint.x()
@@ -143,16 +143,14 @@ for aDelta in range(0, 20):
   aSession.startOperation()
   anArcStartPoint.setValue(sx, sy+aDelta) # move start point
   aSession.finishOperation()
-  assert math.fabs(anArcCentr.x() - x) < TOL
-  assert math.fabs(anArcCentr.y() - y) < TOL
+  model.assertSketchArc(aSketchArc)
 for aDelta in range(20, -1, -1):
   aSession.startOperation()
   anArcStartPoint.setValue(sx, sy+aDelta) # move start point
   aSession.finishOperation()
-  assert math.fabs(anArcCentr.x() - x) < TOL
-  assert math.fabs(anArcCentr.y() - y) < TOL
+  model.assertSketchArc(aSketchArc)
 #=========================================================================
-# Test that movement of end point of arc does not change central point
+# Test that movement of end point of arc does not break the arc
 #=========================================================================
 x = anArcCentr.x()
 y = anArcCentr.y()
@@ -162,11 +160,9 @@ for aDelta in range(0, 20):
   aSession.startOperation()
   anArcEndPoint.setValue(sx+aDelta, sy) # move end point
   aSession.finishOperation()
-  assert math.fabs(anArcCentr.x() - x) < TOL
-  assert math.fabs(anArcCentr.y() - y) < TOL
+  model.assertSketchArc(aSketchArc)
 for aDelta in range(20, -1, -1):
   aSession.startOperation()
   anArcEndPoint.setValue(sx+aDelta, sy) # move end point
   aSession.finishOperation()
-  assert math.fabs(anArcCentr.x() - x) < TOL
-  assert math.fabs(anArcCentr.y() - y) < TOL
+  model.assertSketchArc(aSketchArc)
index 47bce50299daab7b78938bfe74422e5aac52fe23..5cbe2fafb90255cf4ac446b32f669312d3037e9f 100644 (file)
@@ -40,11 +40,7 @@ def verifyLastArc(theSketch, theCenter, theStart, theEnd):
         verifyPointCoordinates(aStartPnt, theStart[0], theStart[1])
     if len(theEnd):
         verifyPointCoordinates(aEndPnt, theEnd[0], theEnd[1])
-    aRadius = aLastArc.real("radius")
-    aDistCS = model.distancePointPoint(aCenterPnt, aStartPnt)
-    aDistCE = model.distancePointPoint(aCenterPnt, aEndPnt)
-    assert math.fabs(aDistCS - aDistCE) < TOLERANCE, "Wrong arc: center-start distance {}, center-end distance {}".format(aDistCS, aDistCE)
-    assert math.fabs(aRadius.value() -aDistCS) < TOLERANCE, "Wrong radius {0}, expected {1}".format(aRadius.value(), aDistCS)
+    model.assertSketchArc(aLastArc)
 
 def verifyPointCoordinates(thePoint, theX, theY):
     assert thePoint.x() == theX and thePoint.y() == theY, "Wrong '{0}' point ({1}, {2}), expected ({3}, {4})".format(thePoint.id(), thePoint.x(), thePoint.y(), theX, theY)