Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/04/13 10:18:18 (11 years ago)
Author:
ascheibe
Message:

#1886 fixed RealVectorEqualityComparer and added unit tests for caches

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Analysis.AlgorithmBehavior/AlgorithmBehaviorUnitTests/PermutationCacheTest.cs

    r10060 r10104  
    3434      PermutationEqualityComparer comp = new PermutationEqualityComparer();
    3535      PermutationSolutionCache dict = new PermutationSolutionCache();
    36       int realDuplicates = 0;
    37       int noDuplicates = 0;
     36      int nrOfPermutations = 200;
    3837
    39       Permutation[] permutations = new Permutation[500];
    40       for (int i = 0; i < permutations.Length; i += 2) {
     38
     39      for (int i = 0; i < nrOfPermutations; i++) {
    4140        var p = new Permutation(PermutationTypes.RelativeUndirected, 21, rand);
    42         permutations[i] = p;
    43         permutations[i + 1] = p;
    4441
     42        //should be added
    4543        PermutationSolutionInformation pi = new PermutationSolutionInformation();
    46         pi.Generation = rand.Next(0, 100);
     44        pi.Generation = 9;
    4745        pi.ProducedBy = ProducedBy.Mutation;
     46        dict.Add(p, pi);
    4847
     48        //should be added
     49        pi = new PermutationSolutionInformation();
     50        pi.Generation = 10;
     51        pi.ProducedBy = ProducedBy.Mutation;
     52        dict.Add(p, pi);
     53
     54        //should be added
     55        pi = new PermutationSolutionInformation();
     56        pi.Generation = 10;
     57        pi.ProducedBy = ProducedBy.Crossover;
     58        dict.Add(p, pi);
     59
     60        //should not be added
     61        pi = new PermutationSolutionInformation();
     62        pi.Generation = 10;
     63        pi.ProducedBy = ProducedBy.Mutation;
    4964        dict.Add(p, pi);
    5065      }
    5166
    52       for (int i = 0; i < permutations.Length; i++) {
    53         for (int j = i + 1; j < permutations.Length; j++) {
    54           if (comp.Equals(permutations[i], permutations[j])) {
    55             realDuplicates++;
    56             break;
    57           }
    58         }
     67      foreach (var value in dict.Values()) {
     68        Assert.AreEqual(3, value.Count);
    5969      }
    6070
    61       for (int i = 0; i < dict.SolutionDictionary.Keys.Count; i++) {
    62         for (int j = i + 1; j < dict.SolutionDictionary.Keys.Count; j++) {
    63           if (comp.Equals(dict.SolutionDictionary.Keys.ElementAt(i), dict.SolutionDictionary.Keys.ElementAt(j))) {
    64             noDuplicates++;
    65             break;
    66           }
    67         }
     71      foreach (var key in dict.Keys()) {
     72        int cnt = dict.Keys().Count(x => comp.Equals(key, x));
     73        Assert.AreEqual(1, cnt);
    6874      }
    69 
    70       Assert.AreNotEqual(0, realDuplicates);
    71       Assert.AreEqual(0, noDuplicates);
    72       Assert.AreEqual(250, dict.SolutionDictionary.Keys.Count);
    7375    }
    7476  }
Note: See TracChangeset for help on using the changeset viewer.