Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Analysis.AlgorithmBehavior/AlgorithmBehaviorUnitTests/RealVectorSolutionCacheTest.cs @ 10105

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

#1886 renamed some properties in SolutionInformation as suggested by swagner

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.RealVectorEncoding;
25using HeuristicLab.Encodings.RealVectorEncoding;
26using Microsoft.VisualStudio.TestTools.UnitTesting;
27
28namespace AlgorithmBehaviorUnitTests {
29  [TestClass]
30  public class RealVectorSolutionCacheTest {
31    [TestMethod]
32    public void TestCache() {
33      var rand = new HeuristicLab.Random.FastRandom();
34      int nrOfVectors = 200;
35      int vectorLength = 50;
36
37      RealVectorSolutionCache solutionCache = new RealVectorSolutionCache();
38      RealVectorEqualityComparer comp = new RealVectorEqualityComparer();
39
40      for (int i = 0; i < nrOfVectors; i++) {
41        RealVector vector = new RealVector(vectorLength, rand, -20, 30);
42        RealVectorSolutionInformation info = new RealVectorSolutionInformation();
43
44        //should be added
45        info.ProducedBy = ProducedBy.Crossover;
46        solutionCache.Add(vector, info);
47
48        //should be added
49        info = new RealVectorSolutionInformation();
50        info.ProducedBy = ProducedBy.Move;
51        solutionCache.Add(vector, info);
52
53        //should be added
54        info = new RealVectorSolutionInformation();
55        info.ProducedBy = ProducedBy.Move;
56        info.Iteration = 20;
57        solutionCache.Add(vector, info);
58
59        //should not be added
60        info = new RealVectorSolutionInformation();
61        info.ProducedBy = ProducedBy.Crossover;
62        solutionCache.Add(vector, info);
63      }
64
65      foreach (var value in solutionCache.Values()) {
66        Assert.AreEqual(3, value.Count);
67      }
68
69      foreach (var key in solutionCache.Keys()) {
70        int cnt = solutionCache.Keys().Count(x => comp.Equals(key, x));
71        Assert.AreEqual(1, cnt);
72      }
73    }
74  }
75}
Note: See TracBrowser for help on using the repository browser.