Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Analysis.AlgorithmBehavior/AlgorithmBehaviorUnitTests/PermutationCacheTest.cs @ 10129

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

#1886 renamed some properties in SolutionInformation as suggested by swagner

File size: 2.6 KB
RevLine 
[10060]1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System.Linq;
[10026]23using HeuristicLab.Analysis.SolutionCaching;
24using HeuristicLab.Analysis.SolutionCaching.PermutationEncoding;
[9754]25using HeuristicLab.Encodings.PermutationEncoding;
26using Microsoft.VisualStudio.TestTools.UnitTesting;
27
28namespace AlgorithmBehaviorUnitTests {
29  [TestClass]
[10060]30  public class PermutationCacheTest {
[9754]31    [TestMethod]
32    public void TestPermutationSolutionDictionary() {
33      var rand = new HeuristicLab.Random.FastRandom();
[10026]34      PermutationEqualityComparer comp = new PermutationEqualityComparer();
35      PermutationSolutionCache dict = new PermutationSolutionCache();
[10104]36      int nrOfPermutations = 200;
[9754]37
[10104]38
39      for (int i = 0; i < nrOfPermutations; i++) {
[9754]40        var p = new Permutation(PermutationTypes.RelativeUndirected, 21, rand);
41
[10104]42        //should be added
[10026]43        PermutationSolutionInformation pi = new PermutationSolutionInformation();
[10105]44        pi.Iteration = 9;
[9754]45        pi.ProducedBy = ProducedBy.Mutation;
[10104]46        dict.Add(p, pi);
[9754]47
[10104]48        //should be added
49        pi = new PermutationSolutionInformation();
[10105]50        pi.Iteration = 10;
[10104]51        pi.ProducedBy = ProducedBy.Mutation;
[10026]52        dict.Add(p, pi);
[10104]53
54        //should be added
55        pi = new PermutationSolutionInformation();
[10105]56        pi.Iteration = 10;
[10104]57        pi.ProducedBy = ProducedBy.Crossover;
58        dict.Add(p, pi);
59
60        //should not be added
61        pi = new PermutationSolutionInformation();
[10105]62        pi.Iteration = 10;
[10104]63        pi.ProducedBy = ProducedBy.Mutation;
64        dict.Add(p, pi);
[9754]65      }
66
[10104]67      foreach (var value in dict.Values()) {
68        Assert.AreEqual(3, value.Count);
[9754]69      }
70
[10104]71      foreach (var key in dict.Keys()) {
72        int cnt = dict.Keys().Count(x => comp.Equals(key, x));
73        Assert.AreEqual(1, cnt);
[9754]74      }
75    }
76  }
77}
Note: See TracBrowser for help on using the repository browser.