Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Analysis.AlgorithmBehavior/AlgorithmBehaviorUnitTests/UnitTest2.cs @ 9754

Last change on this file since 9754 was 9754, checked in by ascheibe, 11 years ago

#1886 added a caching analyzer for crossover

File size: 1.9 KB
Line 
1using System.Linq;
2using HeuristicLab.Analysis.AlgorithmBehavior.Analyzers;
3using HeuristicLab.Encodings.PermutationEncoding;
4using Microsoft.VisualStudio.TestTools.UnitTesting;
5
6namespace AlgorithmBehaviorUnitTests {
7  [TestClass]
8  public class UnitTest2 {
9    [TestMethod]
10    public void TestPermutationSolutionDictionary() {
11      var rand = new HeuristicLab.Random.FastRandom();
12      PermutationWrapperEqualityComparer comp = new PermutationWrapperEqualityComparer();
13      PermutationSolutionDictionary dict = new PermutationSolutionDictionary();
14      int realDuplicates = 0;
15      int noDuplicates = 0;
16
17      PermutationWrapper[] permutations = new PermutationWrapper[500];
18      for (int i = 0; i < permutations.Length; i += 2) {
19        var p = new Permutation(PermutationTypes.RelativeUndirected, 21, rand);
20        var pw = new PermutationWrapper(p);
21        permutations[i] = pw;
22        permutations[i + 1] = pw;
23
24        PermutationInformation pi = new PermutationInformation();
25        pi.Generation = rand.Next(0, 100);
26        pi.ProducedBy = ProducedBy.Mutation;
27
28        dict.Add(pw, pi);
29      }
30
31      for (int i = 0; i < permutations.Length; i++) {
32        for (int j = i + 1; j < permutations.Length; j++) {
33          if (comp.Equals(permutations[i], permutations[j])) {
34            realDuplicates++;
35            break;
36          }
37
38        }
39      }
40
41      for (int i = 0; i < dict.SolutionDictionary.Keys.Count; i++) {
42        for (int j = i + 1; j < dict.SolutionDictionary.Keys.Count; j++) {
43          if (comp.Equals(dict.SolutionDictionary.Keys.ElementAt(i), dict.SolutionDictionary.Keys.ElementAt(j))) {
44            noDuplicates++;
45            break;
46          }
47
48        }
49      }
50
51      Assert.AreNotEqual(0, realDuplicates);
52      Assert.AreEqual(0, noDuplicates);
53      Assert.AreEqual(250, dict.SolutionDictionary.Keys.Count);
54    }
55  }
56}
Note: See TracBrowser for help on using the repository browser.