Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/15/11 10:34:38 (13 years ago)
Author:
gkronber
Message:

#1227 implemented transformations in simplifier to successfully run current set of test cases.

File:
1 edited

Legend:

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

    r5460 r5461  
    140140      }
    141141      #endregion
     142      #region constant and variable folding
     143      {
     144        var actualTree = simplifier.Simplify(importer.Import("(+ 1.0 2.0)"));
     145        var expectedTree = importer.Import("3.0");
     146        Assert.AreEqual(formatter.Format(expectedTree), formatter.Format(actualTree));
     147      }
     148      {
     149        var actualTree = simplifier.Simplify(importer.Import("(+ (variable 2.0 a) (variable 2.0 a))"));
     150        var expectedTree = importer.Import("(variable 4.0 a)");
     151        Assert.AreEqual(formatter.Format(expectedTree), formatter.Format(actualTree));
     152      }
     153      {
     154        var actualTree = simplifier.Simplify(importer.Import("(- (variable 2.0 a) (variable 1.0 a))"));
     155        var expectedTree = importer.Import("(variable 1.0 a)");
     156        Assert.AreEqual(formatter.Format(expectedTree), formatter.Format(actualTree));
     157      }
     158      {
     159        var actualTree = simplifier.Simplify(importer.Import("(* (variable 2.0 a) (variable 2.0 a))"));
     160        var expectedTree = importer.Import("(* (* (variable 1.0 a) (variable 1.0 a)) 4.0)");
     161        Assert.AreEqual(formatter.Format(expectedTree), formatter.Format(actualTree));
     162      }
     163      {
     164        var actualTree = simplifier.Simplify(importer.Import("(/ (variable 1.0 a) (variable 2.0 a))"));
     165        var expectedTree = importer.Import("0.5");
     166        Assert.AreEqual(formatter.Format(expectedTree), formatter.Format(actualTree));
     167      }
     168      #endregion
    142169      #region logarithm rules
    143170      {
     
    155182      {
    156183        // log transformation
    157         var actualTree = simplifier.Simplify(importer.Import("(log (* (variable 2.0 a) (variable 3.0 b))"));
    158         var expectedTree = importer.Import("(+ (log (variable 2.0 a)) (log (variable 3.0 b)))");
     184        var actualTree = simplifier.Simplify(importer.Import("(log (* (variable 2.0 a) (variable 3.0 b)))"));
     185        var expectedTree = importer.Import("(+ (log (variable 1.0 a)) (log (variable 1.0 b)) 1.7918)");
    159186        Assert.AreEqual(formatter.Format(expectedTree), formatter.Format(actualTree));
    160187      }
    161188      {
    162189        // log transformation
    163         var actualTree = simplifier.Simplify(importer.Import("(log (/ (variable 2.0 a) (variable 3.0 b))"));
     190        var actualTree = simplifier.Simplify(importer.Import("(log (/ (variable 2.0 a) (variable 3.0 b)))"));
    164191        var expectedTree = importer.Import("(- (log (variable 2.0 a)) (log (variable 3.0 b)))");
    165192        Assert.AreEqual(formatter.Format(expectedTree), formatter.Format(actualTree));
     
    194221        // constant not
    195222        var actualTree = simplifier.Simplify(importer.Import("(not -2.0)"));
    196         var expectedTree = importer.Import("1.0");
     223        var expectedTree = importer.Import("2.0");
    197224        Assert.AreEqual(formatter.Format(expectedTree), formatter.Format(actualTree));
    198225      }
     
    200227        // constant not
    201228        var actualTree = simplifier.Simplify(importer.Import("(not 2.0)"));
    202         var expectedTree = importer.Import("-1.0");
     229        var expectedTree = importer.Import("-2.0");
    203230        Assert.AreEqual(formatter.Format(expectedTree), formatter.Format(actualTree));
    204231      }
     
    206233        // constant not
    207234        var actualTree = simplifier.Simplify(importer.Import("(not 0.0)"));
    208         var expectedTree = importer.Import("1.0");
     235        var expectedTree = importer.Import("0.0");
    209236        Assert.AreEqual(formatter.Format(expectedTree), formatter.Format(actualTree));
    210237      }
     
    245272        var actualTree = simplifier.Simplify(importer.Import("(if (variable 1.0 a) (variable 2.0 a) (variable 3.0 a))"));
    246273        var expectedTree = importer.Import("(if (> (variable 1.0 a) 0.0) (variable 2.0 a) (variable 3.0 a))");
    247         Assert.AreEqual(formatter.Format(expectedTree), formatter.Format(actualTree));
    248       }
    249       #endregion
    250       #region constant and variable folding
    251       {
    252         var actualTree = simplifier.Simplify(importer.Import("(+ 1.0 2.0)"));
    253         var expectedTree = importer.Import("3.0");
    254         Assert.AreEqual(formatter.Format(expectedTree), formatter.Format(actualTree));
    255       }
    256       {
    257         var actualTree = simplifier.Simplify(importer.Import("(+ (variable 2.0 a) (variable 2.0 a))"));
    258         var expectedTree = importer.Import("(variable 4.0 a)");
    259         Assert.AreEqual(formatter.Format(expectedTree), formatter.Format(actualTree));
    260       }
    261       {
    262         var actualTree = simplifier.Simplify(importer.Import("(- (variable 2.0 a) (variable 1.0 a))"));
    263         var expectedTree = importer.Import("(variable 1.0 a)");
    264         Assert.AreEqual(formatter.Format(expectedTree), formatter.Format(actualTree));
    265       }
    266       {
    267         var actualTree = simplifier.Simplify(importer.Import("(* (variable 2.0 a) (variable 2.0 a))"));
    268         var expectedTree = importer.Import("(* (* (variable 1.0 a) (variable 1.0 a)) 4.0)");
    269         Assert.AreEqual(formatter.Format(expectedTree), formatter.Format(actualTree));
    270       }
    271       {
    272         var actualTree = simplifier.Simplify(importer.Import("(/ (variable 1.0 a) (variable 2.0 a))"));
    273         var expectedTree = importer.Import("0.5");
    274274        Assert.AreEqual(formatter.Format(expectedTree), formatter.Format(actualTree));
    275275      }
Note: See TracChangeset for help on using the changeset viewer.