From 62e421475a91e80bc0608ebc78d45fedc3f065ed Mon Sep 17 00:00:00 2001 From: azv Date: Wed, 29 Mar 2017 18:37:32 +0300 Subject: [PATCH] Adjust test cases according to updated Arc behavior --- src/PythonAPI/model/tests/tests.py | 15 +++++++++++++ src/SketchPlugin/Test/TestArcBehavior.py | 22 ++++++++----------- .../Test/TestCreateArcByCenterStartEnd.py | 6 +---- 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/src/PythonAPI/model/tests/tests.py b/src/PythonAPI/model/tests/tests.py index 68b766385..2cc13febd 100644 --- a/src/PythonAPI/model/tests/tests.py +++ b/src/PythonAPI/model/tests/tests.py @@ -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) diff --git a/src/SketchPlugin/Test/TestArcBehavior.py b/src/SketchPlugin/Test/TestArcBehavior.py index b0e31d729..2f8c3f4db 100644 --- a/src/SketchPlugin/Test/TestArcBehavior.py +++ b/src/SketchPlugin/Test/TestArcBehavior.py @@ -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) diff --git a/src/SketchPlugin/Test/TestCreateArcByCenterStartEnd.py b/src/SketchPlugin/Test/TestCreateArcByCenterStartEnd.py index 47bce5029..5cbe2fafb 100644 --- a/src/SketchPlugin/Test/TestCreateArcByCenterStartEnd.py +++ b/src/SketchPlugin/Test/TestCreateArcByCenterStartEnd.py @@ -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) -- 2.39.2