Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/15/11 13:36:45 (13 years ago)
Author:
gkronber
Message:

#1227 implemented test cases and transformation rules for root and power symbols.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Tests/SymbolicSimplifierTest.cs

    r5461 r5465  
    170170      {
    171171        // cancellation
    172         var actualTree = simplifier.Simplify(importer.Import("(exp (log (variable 2.0 a)))"));
    173         var expectedTree = importer.Import("(variable 2.0 a)");
    174         Assert.AreEqual(formatter.Format(expectedTree), formatter.Format(actualTree));
    175       }
    176       {
    177         // cancellation
    178172        var actualTree = simplifier.Simplify(importer.Import("(log (exp (variable 2.0 a)))"));
    179173        var expectedTree = importer.Import("(variable 2.0 a)");
     
    190184        var actualTree = simplifier.Simplify(importer.Import("(log (/ (variable 2.0 a) (variable 3.0 b)))"));
    191185        var expectedTree = importer.Import("(- (log (variable 2.0 a)) (log (variable 3.0 b)))");
     186        Assert.AreEqual(formatter.Format(expectedTree), formatter.Format(actualTree));
     187      }
     188      #endregion
     189      #region exponentiation rules
     190      {
     191        // cancellation
     192        var actualTree = simplifier.Simplify(importer.Import("(exp (log (variable 2.0 a)))"));
     193        var expectedTree = importer.Import("(variable 2.0 a)");
     194        Assert.AreEqual(formatter.Format(expectedTree), formatter.Format(actualTree));
     195      }
     196      {
     197        // exp transformation
     198        var actualTree = simplifier.Simplify(importer.Import("(exp (+ (variable 2.0 a) (variable 3.0 b)))"));
     199        var expectedTree = importer.Import("(* (exp (variable 2.0 a)) (exp (variable 3.0 b)))");
     200        Assert.AreEqual(formatter.Format(expectedTree), formatter.Format(actualTree));
     201      }
     202      {
     203        // exp transformation
     204        var actualTree = simplifier.Simplify(importer.Import("(exp (- (variable 2.0 a) (variable 3.0 b)))"));
     205        var expectedTree = importer.Import("(* (exp (variable 2.0 a)) (exp (variable -3.0 b)))");
     206        Assert.AreEqual(formatter.Format(expectedTree), formatter.Format(actualTree));
     207      }
     208      #endregion
     209      #region power rules
     210      {
     211        // cancellation
     212        var actualTree = simplifier.Simplify(importer.Import("(pow (variable 2.0 a) 0.0)"));
     213        var expectedTree = importer.Import("1.0");
     214        Assert.AreEqual(formatter.Format(expectedTree), formatter.Format(actualTree));
     215      }
     216      {
     217        // fixed point
     218        var actualTree = simplifier.Simplify(importer.Import("(pow (variable 2.0 a) 1.0)"));
     219        var expectedTree = importer.Import("(variable 2.0 a)");
     220        Assert.AreEqual(formatter.Format(expectedTree), formatter.Format(actualTree));
     221      }
     222      {
     223        // inversion fixed point
     224        var actualTree = simplifier.Simplify(importer.Import("(pow (variable 2.0 a) -1.0)"));
     225        var expectedTree = importer.Import("(/ 1.0 (variable 2.0 a))");
     226        Assert.AreEqual(formatter.Format(expectedTree), formatter.Format(actualTree));
     227      }
     228      {
     229        // inversion
     230        var actualTree = simplifier.Simplify(importer.Import("(pow (variable 2.0 a) -2.0)"));
     231        var expectedTree = importer.Import("(/ 1.0 (pow (variable 2.0 a) 2.0))");
     232        Assert.AreEqual(formatter.Format(expectedTree), formatter.Format(actualTree));
     233      }
     234      {
     235        // constant folding
     236        var actualTree = simplifier.Simplify(importer.Import("(pow 3.0 2.0)"));
     237        var expectedTree = importer.Import("9.0");
     238        Assert.AreEqual(formatter.Format(expectedTree), formatter.Format(actualTree));
     239      }
     240      #endregion
     241      #region root rules
     242      {
     243        // cancellation
     244        var actualTree = simplifier.Simplify(importer.Import("(root (variable 2.0 a) 0.0)"));
     245        var expectedTree = importer.Import("1.0");
     246        Assert.AreEqual(formatter.Format(expectedTree), formatter.Format(actualTree));
     247      }
     248      {
     249        // fixed point
     250        var actualTree = simplifier.Simplify(importer.Import("(root (variable 2.0 a) 1.0)"));
     251        var expectedTree = importer.Import("(variable 2.0 a)");
     252        Assert.AreEqual(formatter.Format(expectedTree), formatter.Format(actualTree));
     253      }
     254      {
     255        // inversion fixed point
     256        var actualTree = simplifier.Simplify(importer.Import("(root (variable 2.0 a) -1.0)"));
     257        var expectedTree = importer.Import("(/ 1.0 (variable 2.0 a))");
     258        Assert.AreEqual(formatter.Format(expectedTree), formatter.Format(actualTree));
     259      }
     260      {
     261        // inversion
     262        var actualTree = simplifier.Simplify(importer.Import("(root (variable 2.0 a) -2.0)"));
     263        var expectedTree = importer.Import("(/ 1.0 (root (variable 2.0 a) 2.0))");
     264        Assert.AreEqual(formatter.Format(expectedTree), formatter.Format(actualTree));
     265      }
     266      {
     267        // constant folding
     268        var actualTree = simplifier.Simplify(importer.Import("(root 9.0 2.0)"));
     269        var expectedTree = importer.Import("3.0");
    192270        Assert.AreEqual(formatter.Format(expectedTree), formatter.Format(actualTree));
    193271      }
Note: See TracChangeset for help on using the changeset viewer.