From c4d0e20481e3c89b91bb3e054a5aa9c4f38a67a8 Mon Sep 17 00:00:00 2001 From: azv Date: Sat, 1 Apr 2017 17:34:16 +0300 Subject: [PATCH] Use tolerance 1e-7 for checking volume in the Model test cases. --- src/PythonAPI/model/tests/tests.py | 5 +++-- test.models/angle30.py | 15 ++++++++++----- test.models/wheel_rim.py | 2 +- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/PythonAPI/model/tests/tests.py b/src/PythonAPI/model/tests/tests.py index 2cc13febd..84e84c6a6 100644 --- a/src/PythonAPI/model/tests/tests.py +++ b/src/PythonAPI/model/tests/tests.py @@ -96,11 +96,12 @@ def testNbSubShapes(theFeature, theShapeType, theExpectedNbSubShapes): assert (aNbResultSubShapes == anExpectedNbSubShapes), "Number of sub-shapes of type {} for result[{}]: {}. Expected: {}.".format(aShapeTypes[theShapeType], anIndex, aNbResultSubShapes, anExpectedNbSubShapes) -def testResultsVolumes(theFeature, theExpectedResultsVolumes, theNbSignificantDigits = 10): +def testResultsVolumes(theFeature, theExpectedResultsVolumes, theNbSignificantDigits = 7): """ Tests results volumes. :param theFeature: feature to test. :param theExpectedResultsVolumes: list of results volumes. Size of list should be equal to len(theFeature.results()). """ + aTolerance = 10**(-theNbSignificantDigits) aNbResults = len(theFeature.results()) aListSize = len(theExpectedResultsVolumes) assert (aNbResults == aListSize), "Number of results: {} not equal to list size: {}.".format(aNbResults, aListSize) @@ -109,7 +110,7 @@ def testResultsVolumes(theFeature, theExpectedResultsVolumes, theNbSignificantDi aResultVolumeStr = "{:0.27f}".format(aResultVolume).lstrip("0").lstrip(".").lstrip("0") anExpectedResultVolume = theExpectedResultsVolumes[anIndex] anExpectedResultVolumeStr = "{:0.27f}".format(anExpectedResultVolume).lstrip("0").lstrip(".").lstrip("0") - assert (aResultVolumeStr[:theNbSignificantDigits] == anExpectedResultVolumeStr[:theNbSignificantDigits]), "Volume of result[{}]: {:0.27f}. Expected: {:0.27f}. The first {} significant digits not equal.".format(anIndex, aResultVolume, anExpectedResultVolume, theNbSignificantDigits) + assert math.fabs(aResultVolume - anExpectedResultVolume) < aTolerance * anExpectedResultVolume, "Volume of result[{}]: {:0.27f}. Expected: {:0.27f}. The first {} significant digits not equal.".format(anIndex, aResultVolume, anExpectedResultVolume, theNbSignificantDigits) def testHaveNamingFaces(theFeature, theModel, thePartDoc) : """ Tests if all faces of result have a name diff --git a/test.models/angle30.py b/test.models/angle30.py index 2bfbcb9f2..ffd838e9e 100644 --- a/test.models/angle30.py +++ b/test.models/angle30.py @@ -184,7 +184,6 @@ SketchLine_33.setName("SketchLine_32") SketchLine_33.result().setName("SketchLine_32") SketchConstraintDistance_10 = Sketch_4.setDistance(SketchLine_22.startPoint(), SketchLine_32.result(), 4.5) SketchConstraintDistance_10.setName("SketchConstraintDistance_13") -SketchPoint_2 = Sketch_4.addPoint(0.0367430766441097, 12.3548825983447) SketchLine_34 = Sketch_4.addLine(-8.5, 12.23281708580693, 8.5, 12.23281708580693) SketchLine_34.setName("SketchLine_33") SketchLine_34.result().setName("SketchLine_33") @@ -323,6 +322,12 @@ SketchConstraintDistance_17 = Sketch_4.setDistance(SketchLine_21.result(), Sketc SketchConstraintDistance_17.setName("SketchConstraintDistance_18") SketchConstraintDistance_18 = Sketch_4.setDistance(SketchLine_30.endPoint(), SketchLine_20.result(), 6.1) SketchConstraintDistance_18.setName("SketchConstraintDistance_19") +SketchConstraintCoincidence_67 = Sketch_4.setCoincident(SketchArc_3.center(), SketchCircle_3.center()) +SketchConstraintCoincidence_67.setName("SketchConstraintCoincidence_149") +SketchConstraintCoincidence_68 = Sketch_4.setCoincident(SketchArc_4.center(), SketchArc_3.center()) +SketchConstraintCoincidence_68.setName("SketchConstraintCoincidence_150") +SketchConstraintDistance_19 = Sketch_4.setDistance(SketchArc_4.center(), SketchLine_34.result(), 12) +SketchConstraintDistance_19.setName("SketchConstraintDistance_43") model.do() Extrusion_3 = model.addExtrusion(Part_1_doc, [model.selection("COMPOUND", "Sketch_4")], model.selection(), 50, 30) Extrusion_4 = model.addExtrusion(Part_1_doc, [model.selection("COMPOUND", "Sketch_3")], model.selection(), 22, 22) @@ -753,9 +758,9 @@ from GeomAPI import GeomAPI_Shape model.testNbResults(Boolean_7, 1) model.testNbSubResults(Boolean_7, [0]) model.testNbSubShapes(Boolean_7, GeomAPI_Shape.SOLID, [1]) -model.testNbSubShapes(Boolean_7, GeomAPI_Shape.FACE, [49]) -model.testNbSubShapes(Boolean_7, GeomAPI_Shape.EDGE, [263]) -model.testNbSubShapes(Boolean_7, GeomAPI_Shape.VERTEX, [526]) -model.testResultsVolumes(Boolean_7, [157000.328896829247241839766502380]) +model.testNbSubShapes(Boolean_7, GeomAPI_Shape.FACE, [50]) +model.testNbSubShapes(Boolean_7, GeomAPI_Shape.EDGE, [266]) +model.testNbSubShapes(Boolean_7, GeomAPI_Shape.VERTEX, [532]) +model.testResultsVolumes(Boolean_7, [156999.218330596777377650141716003]) assert(model.checkPythonDump) diff --git a/test.models/wheel_rim.py b/test.models/wheel_rim.py index bb8035203..641060991 100644 --- a/test.models/wheel_rim.py +++ b/test.models/wheel_rim.py @@ -244,6 +244,6 @@ model.testNbSubShapes(Boolean_1, GeomAPI_Shape.SOLID, [1]) model.testNbSubShapes(Boolean_1, GeomAPI_Shape.FACE, [35]) model.testNbSubShapes(Boolean_1, GeomAPI_Shape.EDGE, [162]) model.testNbSubShapes(Boolean_1, GeomAPI_Shape.VERTEX, [324]) -model.testResultsVolumes(Boolean_1, [2053931.555419394280761480331420898]) +model.testResultsVolumes(Boolean_1, [2053931.913933836854994297027587891]) assert(model.checkPythonDump()) -- 2.39.2