Free cookie consent management tool by TermsFeed Policy Generator

Changeset 18120


Ignore:
Timestamp:
12/15/21 09:53:31 (3 years ago)
Author:
gkronber
Message:

#3140: fix unit test for symbolic derivative

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3140_NumberSymbol/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4/DeriveTest.cs

    r17180 r18120  
    3535      var formatter = new InfixExpressionFormatter();
    3636      var parser = new InfixExpressionParser();
    37       Assert.AreEqual("0", Derive("3", "x"));
     37      Assert.AreEqual("0", Derive("<num=3>", "x"));
    3838      Assert.AreEqual("1", Derive("x", "x"));
    39       Assert.AreEqual("10", Derive("10*x", "x"));
    40       Assert.AreEqual("10", Derive("x*10", "x"));
     39      Assert.AreEqual("10", Derive("<num=10>*x", "x"));
     40      Assert.AreEqual("10", Derive("x*<num=10>", "x"));
    4141      Assert.AreEqual("(2*'x')", Derive("x*x", "x"));
    4242      Assert.AreEqual("((('x' * 'x') * 2) + ('x' * 'x'))", Derive("x*x*x", "x")); // simplifier does not merge (x*x)*2 + x*x  to 3*x*x
    43       Assert.AreEqual("0", Derive("10*x", "y"));
    44       Assert.AreEqual("20", Derive("10*x+20*y", "y"));
    45       Assert.AreEqual("6", Derive("2*3*x", "x"));
    46       Assert.AreEqual("(10*'y')", Derive("10*x*y+20*y", "x"));
     43      Assert.AreEqual("0", Derive("<num=10>*x", "y"));
     44      Assert.AreEqual("20", Derive("<num=10>*x+<num=20>*y", "y"));
     45      Assert.AreEqual("6", Derive("<num=2>*<num=3>*x", "x"));
     46      Assert.AreEqual("(10*'y')", Derive("<num=10>*x*y+<num=20>*y", "x"));
    4747      Assert.AreEqual("(1 / (SQR('x') * (-1)))", Derive("1/x", "x"));
    4848      Assert.AreEqual("('y' / (SQR('x') * (-1)))", Derive("y/x", "x"));
     
    5151      Assert.AreEqual("((((-2*'x') + (-1)) * ('a' + 'b')) / SQR(('x' + SQR('x'))))", Derive("(a+b)/(x+SQR(x))", "x"));
    5252      Assert.AreEqual("EXP('x')", Derive("exp(x)", "x"));
    53       Assert.AreEqual("(EXP((3*'x')) * 3)", Derive("exp(3*x)", "x"));
     53      Assert.AreEqual("(EXP((3*'x')) * 3)", Derive("exp(<num=3>*x)", "x"));
    5454      Assert.AreEqual("(1 / 'x')", Derive("log(x)", "x"));
    55       Assert.AreEqual("(1 / 'x')", Derive("log(3*x)", "x"));   // 3 * 1/(3*x)
    56       Assert.AreEqual("(1 / ('x' + (0.333333333333333*'y')))", Derive("log(3*x+y)", "x"));  // simplifier does not try to keep fractions
    57       Assert.AreEqual("(1 / (SQRT(((3*'x') + 'y')) * 0.666666666666667))", Derive("sqrt(3*x+y)", "x"));   // 3 / (2 * sqrt(3*x+y)) = 1 / ((2/3) * sqrt(3*x+y))
    58       Assert.AreEqual("(COS((3*'x')) * 3)", Derive("sin(3*x)", "x"));
    59       Assert.AreEqual("(SIN((3*'x')) * (-3))", Derive("cos(3*x)", "x"));
    60       Assert.AreEqual("(1 / (SQR(COS((3*'x'))) * 0.333333333333333))", Derive("tan(3*x)", "x")); // diff(tan(f(x)), x) = 1.0 / cos²(f(x)), simplifier puts constant factor into the denominator
     55      Assert.AreEqual("(1 / 'x')", Derive("log(<num=3>*x)", "x"));   // 3 * 1/(3*x)
     56      Assert.AreEqual("(1 / ('x' + (0.333333333333333*'y')))", Derive("log(<num=3>*x+y)", "x"));  // simplifier does not try to keep fractions
     57      Assert.AreEqual("(1 / (SQRT(((3*'x') + 'y')) * 0.666666666666667))", Derive("sqrt(<num=3>*x+y)", "x"));   // 3 / (2 * sqrt(3*x+y)) = 1 / ((2/3) * sqrt(3*x+y))
     58      Assert.AreEqual("(COS((3*'x')) * 3)", Derive("sin(<num=3>*x)", "x"));
     59      Assert.AreEqual("(SIN((3*'x')) * (-3))", Derive("cos(<num=3>*x)", "x"));
     60      Assert.AreEqual("(1 / (SQR(COS((3*'x'))) * 0.333333333333333))", Derive("tan(<num=3>*x)", "x")); // diff(tan(f(x)), x) = 1.0 / cos²(f(x)), simplifier puts constant factor into the denominator
    6161
    62       Assert.AreEqual("((9*'x') / ABS((3*'x')))", Derive("abs(3*x)", "x"));
     62      Assert.AreEqual("((9*'x') / ABS((3*'x')))", Derive("abs(<num=3>*x)", "x"));
    6363      Assert.AreEqual("(SQR('x') * 3)", Derive("cube(x)", "x"));
    6464      Assert.AreEqual("(1 / (SQR(CUBEROOT('x')) * 3))", Derive("cuberoot(x)", "x"));
Note: See TracChangeset for help on using the changeset viewer.