Free cookie consent management tool by TermsFeed Policy Generator

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

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

#1886 fixed RealVectorEqualityComparer and added unit tests for caches

File size: 2.6 KB
Line 
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;
23using HeuristicLab.Analysis.SolutionCaching;
24using HeuristicLab.Analysis.SolutionCaching.PermutationEncoding;
25using HeuristicLab.Encodings.PermutationEncoding;
26using Microsoft.VisualStudio.TestTools.UnitTesting;
27
28namespace AlgorithmBehaviorUnitTests {
29  [TestClass]
30  public class PermutationCacheTest {
31    [TestMethod]
32    public void TestPermutationSolutionDictionary() {
33      var rand = new HeuristicLab.Random.FastRandom();
34      PermutationEqualityComparer comp = new PermutationEqualityComparer();
35      PermutationSolutionCache dict = new PermutationSolutionCache();
36      int nrOfPermutations = 200;
37
38
39      for (int i = 0; i < nrOfPermutations; i++) {
40        var p = new Permutation(PermutationTypes.RelativeUndirected, 21, rand);
41
42        //should be added
43        PermutationSolutionInformation pi = new PermutationSolutionInformation();
44        pi.Generation = 9;
45        pi.ProducedBy = ProducedBy.Mutation;
46        dict.Add(p, pi);
47
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;
64        dict.Add(p, pi);
65      }
66
67      foreach (var value in dict.Values()) {
68        Assert.AreEqual(3, value.Count);
69      }
70
71      foreach (var key in dict.Keys()) {
72        int cnt = dict.Keys().Count(x => comp.Equals(key, x));
73        Assert.AreEqual(1, cnt);
74      }
75    }
76  }
77}
Note: See TracBrowser for help on using the repository browser.