Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/24/11 19:04:27 (13 years ago)
Author:
gkronber
Message:

#1136 Fixed test cases for symbolic expression tree encoding operators (+ minor bug fixes in symbolic expression tree operators).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Tests/ArgumentDuplicaterTest.cs

    r4068 r5367  
    2121
    2222using System;
     23using System.Linq;
    2324using System.Collections.Generic;
    2425using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    2728using HeuristicLab.Random;
    2829using Microsoft.VisualStudio.TestTools.UnitTesting;
     30using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;
    2931
    3032namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding_3._3.Tests {
     
    5355      var trees = new List<SymbolicExpressionTree>();
    5456      var grammar = Grammars.CreateArithmeticAndAdfGrammar();
    55       var random = new MersenneTwister();
    56       int failedEvents = 0;
     57      var random = new MersenneTwister(31415);
    5758      for (int i = 0; i < POPULATION_SIZE; i++) {
    58         var tree = ProbabilisticTreeCreator.Create(random, grammar, MAX_TREE_SIZE, MAX_TREE_HEIGHT, 3, 3);
    59         if (!ArgumentDuplicater.DuplicateArgument(random, tree, grammar, MAX_TREE_SIZE, MAX_TREE_HEIGHT, 3, 3))
    60           failedEvents++;
     59        SymbolicExpressionTree tree = null;
     60        do {
     61          tree = ProbabilisticTreeCreator.Create(random, grammar, MAX_TREE_SIZE, MAX_TREE_HEIGHT, 3, 3);
     62        } while(!HasAdfWithArguments(tree));
     63        var success = ArgumentDuplicater.DuplicateArgument(random, tree, grammar, MAX_TREE_SIZE, MAX_TREE_HEIGHT, 3, 3);
     64        Assert.IsTrue(success);
    6165        Util.IsValid(tree);
    6266        trees.Add(tree);
    6367      }
    64       Assert.Inconclusive("ArgumentDuplicater: " + Environment.NewLine +
    65         "Failed events: " + failedEvents / (double)POPULATION_SIZE * 100 + " %" + Environment.NewLine +
     68      Console.WriteLine("ArgumentDuplicater: " + Environment.NewLine +
    6669        Util.GetSizeDistributionString(trees, 200, 5) + Environment.NewLine +
    6770        Util.GetFunctionDistributionString(trees) + Environment.NewLine +
     
    7073        );
    7174    }
     75
     76    private bool HasAdfWithArguments(SymbolicExpressionTree tree) {
     77      return tree.Root.SubTrees.Count == 2 &&
     78        tree.Root.SubTrees[1].GetAllowedSymbols(0).Where(x => x is Argument).Count() == 1;
     79    }
    7280  }
    7381}
Note: See TracChangeset for help on using the changeset viewer.