# Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D
"Verification d'un exemple de la documentation"
+from utExtend import assertAlmostEqualArrays
+
# ==============================================================================
def test1():
- """Exemple"""
+ """Test"""
from numpy import array, matrix
import adaoBuilder
case = adaoBuilder.New()
case.set( 'Observer', Variable="Analysis", Template="ValuePrinter" )
case.execute()
#
- return 0
+ return case.get("Analysis")[-1]
# ==============================================================================
if __name__ == "__main__":
Un exemple simple de creation d'un cas de calcul TUI ADAO
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
"""
- test1()
+ xa = test1()
+ assertAlmostEqualArrays(xa, [0.25, 0.80, 0.95], places = 5)
--- /dev/null
+#-*-coding:iso-8859-1-*-
+#
+# Copyright (C) 2008-2017 EDF R&D
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
+# Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D
+
+"""
+ Unittest extensions for Numpy objects
+"""
+__author__ = "Jean-Philippe ARGAUD"
+__all__ = ["assertAlmostEqualVector"]
+
+import numpy
+
+# ==============================================================================
+def assertAlmostEqualArrays(first, second, places=7, msg=None, delta=None):
+ "Compare two vectors, like unittest.assertAlmostEqual"
+ if msg is not None:
+ print msg
+ if delta is not None:
+ if ( (numpy.asarray(first) - numpy.asarray(second)) > float(delta) ).any():
+ raise AssertionError("%s != %s within %s places"%(first,second,delta))
+ else:
+ if ( (numpy.asarray(first) - numpy.asarray(second)) > 10**(-int(places)) ).any():
+ raise AssertionError("%s != %s within %i places"%(first,second,places))
+ return max(abs(numpy.asarray(first) - numpy.asarray(second)))
# Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D
"Verification d'un exemple de la documentation"
+from utExtend import assertAlmostEqualArrays
+
# ==============================================================================
def test1():
- """Exemple"""
+ """Test"""
from numpy import array, matrix
import adaoBuilder
case = adaoBuilder.New()
return case.get("Analysis")[-1]
def test2():
- """Exemple"""
+ """Test"""
from numpy import array, matrix
import adaoBuilder
case = adaoBuilder.New()
#
return case.get("Analysis")[-1]
-def almost_equal_vectors(v1, v2, precision = 1.e-15, msg = ""):
- """Comparaison de deux vecteurs"""
- print " Difference maximale %s: %.2e"%(msg, max(abs(v2 - v1)))
- return max(abs(v2 - v1)) < precision
-
# ==============================================================================
if __name__ == "__main__":
print '\n AUTODIAGNOSTIC \n'
"""
xa1 = test1()
xa2 = test2()
- assert almost_equal_vectors( xa1, xa2, msg = "entre les deux" )
+ ecart = assertAlmostEqualArrays(xa1, xa2, places = 15)
+ print " Difference maximale entre les deux : %.2e"%ecart
--- /dev/null
+#-*-coding:iso-8859-1-*-
+#
+# Copyright (C) 2008-2017 EDF R&D
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
+# Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D
+
+"""
+ Unittest extensions for Numpy objects
+"""
+__author__ = "Jean-Philippe ARGAUD"
+__all__ = ["assertAlmostEqualVector"]
+
+import numpy
+
+# ==============================================================================
+def assertAlmostEqualArrays(first, second, places=7, msg=None, delta=None):
+ "Compare two vectors, like unittest.assertAlmostEqual"
+ if msg is not None:
+ print msg
+ if delta is not None:
+ if ( (numpy.asarray(first) - numpy.asarray(second)) > float(delta) ).any():
+ raise AssertionError("%s != %s within %s places"%(first,second,delta))
+ else:
+ if ( (numpy.asarray(first) - numpy.asarray(second)) > 10**(-int(places)) ).any():
+ raise AssertionError("%s != %s within %i places"%(first,second,places))
+ return max(abs(numpy.asarray(first) - numpy.asarray(second)))
# Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D
"Verification d'un exemple de la documentation"
+from utExtend import assertAlmostEqualArrays
+
# ==============================================================================
#
# Construction artificielle d'un exemple de donnees utilisateur
# ==============================================================================
def test1():
- "Exemple"
+ "Test"
import numpy
import adaoBuilder
#
print "Simulation at optimal state.....:",numpy.ravel(FX_at_optimum)
print
#
- return 0
+ return case.get("Analysis")[-1]
# ==============================================================================
if __name__ == "__main__":
Exploitation independante des resultats d'un cas de calcul
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
"""
- test1()
+ xa = test1()
+ assertAlmostEqualArrays(xa, [ 2., 3., 4.])
--- /dev/null
+#-*-coding:iso-8859-1-*-
+#
+# Copyright (C) 2008-2017 EDF R&D
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
+# Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D
+
+"""
+ Unittest extensions for Numpy objects
+"""
+__author__ = "Jean-Philippe ARGAUD"
+__all__ = ["assertAlmostEqualVector"]
+
+import numpy
+
+# ==============================================================================
+def assertAlmostEqualArrays(first, second, places=7, msg=None, delta=None):
+ "Compare two vectors, like unittest.assertAlmostEqual"
+ if msg is not None:
+ print msg
+ if delta is not None:
+ if ( (numpy.asarray(first) - numpy.asarray(second)) > float(delta) ).any():
+ raise AssertionError("%s != %s within %s places"%(first,second,delta))
+ else:
+ if ( (numpy.asarray(first) - numpy.asarray(second)) > 10**(-int(places)) ).any():
+ raise AssertionError("%s != %s within %i places"%(first,second,places))
+ return max(abs(numpy.asarray(first) - numpy.asarray(second)))