]> OCCT Git - occt.git/commitdiff
0031697: Foundation Classes - Expr_GeneralExpression::Derivative does not seem to... IR-2020-08-07
authorifv <ifv@opencascade.com>
Thu, 6 Aug 2020 10:07:52 +0000 (13:07 +0300)
committerbugmaster <bugmaster@opencascade.com>
Fri, 7 Aug 2020 15:49:38 +0000 (18:49 +0300)
Expr_NamedUnknown.cxx - wrong comparing of named unknown is fixed

QABugs_20.cxx - new QAcommand is created
QABugs_11.cxx - wrong command is corrected
bug902 - wrong test is corrected
bug31697 - new test is added

src/Expr/Expr_NamedUnknown.cxx
src/QABugs/QABugs_11.cxx
src/QABugs/QABugs_20.cxx
tests/bugs/fclasses/bug31697 [new file with mode: 0644]
tests/bugs/fclasses/bug902

index 41385a13a37cb67b3d2c7532a339a7df49a43099..3aef079ef63fc6f806c5c7b19d6b86a2a90c9ebb 100644 (file)
@@ -130,7 +130,7 @@ Standard_Boolean Expr_NamedUnknown::IsLinear () const
 Handle(Expr_GeneralExpression) Expr_NamedUnknown::Derivative (const Handle(Expr_NamedUnknown)& X) const
 {
   Handle(Expr_NamedUnknown) me = this;
-  if (me != X) {
+  if (!me->IsIdentical(X)) {
     if (IsAssigned()) {
       return myExpression->Derivative(X);
     }
index 7c0be73307376078d33e610b1203abd176319543..2daac23630dcd7e06f397a06d94d1d0382fca2d8 100644 (file)
@@ -1673,6 +1673,7 @@ static Standard_Integer OCC921 (Draw_Interpretor& di, Standard_Integer argc, con
 #include <Expr_NamedUnknown.hxx>
 #include <Expr_GeneralExpression.hxx>
 #include <Expr_Exponential.hxx>
+#include <ExprIntrp_GenExp.hxx>
 //=======================================================================
 //function :  OCC902
 //purpose  : 
@@ -1685,16 +1686,32 @@ static Standard_Integer OCC902(Draw_Interpretor& di, Standard_Integer argc, cons
     return 1;
   }
 
- TCollection_AsciiString  myStr(argv[1]);
+  TCollection_AsciiString  anExpStr(argv[1]);
+  anExpStr.AssignCat("*x");
+  anExpStr.Prepend("Exp(");
+  anExpStr.AssignCat(")");
+
+  Handle(ExprIntrp_GenExp) exprIntrp = ExprIntrp_GenExp::Create();
+
+  //
+  // Create the expression
+  exprIntrp->Process(anExpStr);
+
+  if (!exprIntrp->IsDone())
+  {
+    di << "Interpretation of expression " << argv[1] << " failed\n";
+    return 1;
+  }
+
 
Handle (Expr_NamedUnknown)      myNamed = new Expr_NamedUnknown(myStr);
- Handle (Expr_Exponential)       oldExpr = new Expr_Exponential(myNamed); 
Handle (Expr_GeneralExpression) newExpr = oldExpr->Derivative(myNamed);
 Handle(Expr_GeneralExpression) anExpr = exprIntrp->Expression();
+  Handle(Expr_NamedUnknown) aVar = new Expr_NamedUnknown("x");
 Handle (Expr_GeneralExpression) newExpr = anExpr->Derivative(aVar);
 
  
  TCollection_AsciiString  res        = newExpr->String();
  Standard_CString         resStr     = res.ToCString();
- TCollection_AsciiString  res_old    = oldExpr->String();
+ TCollection_AsciiString  res_old    = anExpr->String();
  Standard_CString         res_oldStr = res_old.ToCString();
  
 
index 9f841bb787862061434e6b3d6c6126942d126e5d..6c8a9962a7f17cdf07a35187755de90a716f05c5 100644 (file)
@@ -3471,6 +3471,54 @@ static Standard_Integer OCC31294(Draw_Interpretor& di, Standard_Integer, const c
   return 0;
 }
 
+#include <ExprIntrp_GenExp.hxx>
+#include <Expr_GeneralExpression.hxx>
+#include <Expr_NamedUnknown.hxx>
+//=======================================================================
+//function :  OCC31697
+//purpose  : 
+//=======================================================================
+static Standard_Integer OCC31697(Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
+{
+  if (argc < 3)
+  {
+    di << "Usage : " << argv[0] << " expression  variable\n";
+    return 1;
+  }
+
+  TCollection_AsciiString  anExpStr(argv[1]);
+  TCollection_AsciiString  aVarStr(argv[2]);
+
+  Handle(ExprIntrp_GenExp) exprIntrp = ExprIntrp_GenExp::Create();
+
+  //
+  // Create the expression
+  exprIntrp->Process(anExpStr);
+
+  if (!exprIntrp->IsDone())
+  {
+    di << "Interpretation of expression " << argv[1] << " failed\n";
+    return 1;
+  }
+
+  Handle(Expr_GeneralExpression) anExpr = exprIntrp->Expression();
+  Handle(Expr_NamedUnknown) aVar = new Expr_NamedUnknown(aVarStr);
+
+  if (!anExpr->Contains(aVar))
+  {
+    di << "Expression " << argv[1] << " does not contain variable " << argv[2] << "\n";
+    return 1;
+  }
+
+  Handle(Expr_GeneralExpression) aDer = anExpr->Derivative(aVar);
+
+  TCollection_AsciiString  aDerStr = aDer->String();
+
+  di << "The derivative of the " << argv[1] << " by " << argv[2] << " is equal to " << aDerStr << "\n";
+
+  return 0;
+}
+
 void QABugs::Commands_20(Draw_Interpretor& theCommands) {
   const char *group = "QABugs";
 
@@ -3537,5 +3585,7 @@ void QABugs::Commands_20(Draw_Interpretor& theCommands) {
   theCommands.Add("OCC30704_1", "OCC30704_1", __FILE__, OCC30704_1, group);
   theCommands.Add("OCC31294", "OCC31294", __FILE__, OCC31294, group);
 
+  theCommands.Add("OCC31697", "OCC31697 expression variable", __FILE__, OCC31697, group);
+
   return;
 }
diff --git a/tests/bugs/fclasses/bug31697 b/tests/bugs/fclasses/bug31697
new file mode 100644 (file)
index 0000000..a5a8462
--- /dev/null
@@ -0,0 +1,25 @@
+puts "======="
+puts "OCC31697 - Expr_GeneralExpression::Derivative does not seem to work"
+puts "======="
+puts ""
+
+
+pload QAcommands
+
+set exp Exp(2*Sin(x^2))
+set var x
+set list [OCC31697 $exp $var]
+
+set we_have [lindex $list 10]
+puts "we_have = $we_have"
+
+set must_be "Exp(2*Sin(x^2))*Cos(x^2)*x*4"
+puts "must_be = $must_be"
+
+
+if  {[string compare $we_have $must_be] == 0} {
+  puts "OCC31697 OK"
+} else {      
+   puts "OCC31697 Faulty"       
+}
+
index d12d79f48e491b47e89d605d479514149d44f430..9e068d07aff00b8412e908f1c0c54a7ade8d3364 100755 (executable)
@@ -1,5 +1,3 @@
-puts "TODO OCC12345 ALL: OCC902 Faulty"
-
 puts "======="
 puts "OCC902"
 puts "======="
@@ -16,9 +14,9 @@ set list [OCC902 $arg]
 set we_have [lindex $list 8]
 puts "we_have = $we_have"
 
-set must_be_1 "Exp($arg)*$arg"
+set must_be_1 "Exp($arg*x)*$arg"
 puts "must_be_1 = $must_be_1"
-set must_be_2 "$arg*Exp($arg)"
+set must_be_2 "$arg*Exp($arg*x)"
 puts "must_be_2 = $must_be_2"
 
 if  {[string compare $we_have $must_be_1] == 0} {