mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-04-10 18:51:21 +03:00
0031697: Foundation Classes - Expr_GeneralExpression::Derivative does not seem to work (691 & 720)
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
This commit is contained in:
parent
e0b2443737
commit
1bf23e5bb6
@ -130,7 +130,7 @@ Standard_Boolean Expr_NamedUnknown::IsLinear () const
|
|||||||
Handle(Expr_GeneralExpression) Expr_NamedUnknown::Derivative (const Handle(Expr_NamedUnknown)& X) const
|
Handle(Expr_GeneralExpression) Expr_NamedUnknown::Derivative (const Handle(Expr_NamedUnknown)& X) const
|
||||||
{
|
{
|
||||||
Handle(Expr_NamedUnknown) me = this;
|
Handle(Expr_NamedUnknown) me = this;
|
||||||
if (me != X) {
|
if (!me->IsIdentical(X)) {
|
||||||
if (IsAssigned()) {
|
if (IsAssigned()) {
|
||||||
return myExpression->Derivative(X);
|
return myExpression->Derivative(X);
|
||||||
}
|
}
|
||||||
|
@ -1673,6 +1673,7 @@ static Standard_Integer OCC921 (Draw_Interpretor& di, Standard_Integer argc, con
|
|||||||
#include <Expr_NamedUnknown.hxx>
|
#include <Expr_NamedUnknown.hxx>
|
||||||
#include <Expr_GeneralExpression.hxx>
|
#include <Expr_GeneralExpression.hxx>
|
||||||
#include <Expr_Exponential.hxx>
|
#include <Expr_Exponential.hxx>
|
||||||
|
#include <ExprIntrp_GenExp.hxx>
|
||||||
//=======================================================================
|
//=======================================================================
|
||||||
//function : OCC902
|
//function : OCC902
|
||||||
//purpose :
|
//purpose :
|
||||||
@ -1685,16 +1686,32 @@ static Standard_Integer OCC902(Draw_Interpretor& di, Standard_Integer argc, cons
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
TCollection_AsciiString myStr(argv[1]);
|
TCollection_AsciiString anExpStr(argv[1]);
|
||||||
|
anExpStr.AssignCat("*x");
|
||||||
|
anExpStr.Prepend("Exp(");
|
||||||
|
anExpStr.AssignCat(")");
|
||||||
|
|
||||||
Handle (Expr_NamedUnknown) myNamed = new Expr_NamedUnknown(myStr);
|
Handle(ExprIntrp_GenExp) exprIntrp = ExprIntrp_GenExp::Create();
|
||||||
Handle (Expr_Exponential) oldExpr = new Expr_Exponential(myNamed);
|
|
||||||
Handle (Expr_GeneralExpression) newExpr = oldExpr->Derivative(myNamed);
|
//
|
||||||
|
// 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("x");
|
||||||
|
Handle (Expr_GeneralExpression) newExpr = anExpr->Derivative(aVar);
|
||||||
|
|
||||||
|
|
||||||
TCollection_AsciiString res = newExpr->String();
|
TCollection_AsciiString res = newExpr->String();
|
||||||
Standard_CString resStr = res.ToCString();
|
Standard_CString resStr = res.ToCString();
|
||||||
TCollection_AsciiString res_old = oldExpr->String();
|
TCollection_AsciiString res_old = anExpr->String();
|
||||||
Standard_CString res_oldStr = res_old.ToCString();
|
Standard_CString res_oldStr = res_old.ToCString();
|
||||||
|
|
||||||
|
|
||||||
|
@ -3471,6 +3471,54 @@ static Standard_Integer OCC31294(Draw_Interpretor& di, Standard_Integer, const c
|
|||||||
return 0;
|
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) {
|
void QABugs::Commands_20(Draw_Interpretor& theCommands) {
|
||||||
const char *group = "QABugs";
|
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("OCC30704_1", "OCC30704_1", __FILE__, OCC30704_1, group);
|
||||||
theCommands.Add("OCC31294", "OCC31294", __FILE__, OCC31294, group);
|
theCommands.Add("OCC31294", "OCC31294", __FILE__, OCC31294, group);
|
||||||
|
|
||||||
|
theCommands.Add("OCC31697", "OCC31697 expression variable", __FILE__, OCC31697, group);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
25
tests/bugs/fclasses/bug31697
Normal file
25
tests/bugs/fclasses/bug31697
Normal file
@ -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"
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,3 @@
|
|||||||
puts "TODO OCC12345 ALL: OCC902 Faulty"
|
|
||||||
|
|
||||||
puts "======="
|
puts "======="
|
||||||
puts "OCC902"
|
puts "OCC902"
|
||||||
puts "======="
|
puts "======="
|
||||||
@ -16,9 +14,9 @@ set list [OCC902 $arg]
|
|||||||
set we_have [lindex $list 8]
|
set we_have [lindex $list 8]
|
||||||
puts "we_have = $we_have"
|
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"
|
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"
|
puts "must_be_2 = $must_be_2"
|
||||||
|
|
||||||
if {[string compare $we_have $must_be_1] == 0} {
|
if {[string compare $we_have $must_be_1] == 0} {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user