1 | using System.Linq;
|
---|
2 | using HeuristicLab.Analysis.AlgorithmBehavior.Analyzers;
|
---|
3 | using HeuristicLab.Encodings.PermutationEncoding;
|
---|
4 | using Microsoft.VisualStudio.TestTools.UnitTesting;
|
---|
5 |
|
---|
6 | namespace 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 | for (int i = 0; i < dict.SolutionDictionary.Keys.Count; i++) {
|
---|
41 | for (int j = i + 1; j < dict.SolutionDictionary.Keys.Count; j++) {
|
---|
42 | if (comp.Equals(dict.SolutionDictionary.Keys.ElementAt(i), dict.SolutionDictionary.Keys.ElementAt(j))) {
|
---|
43 | noDuplicates++;
|
---|
44 | break;
|
---|
45 | }
|
---|
46 | }
|
---|
47 | }
|
---|
48 |
|
---|
49 | Assert.AreNotEqual(0, realDuplicates);
|
---|
50 | Assert.AreEqual(0, noDuplicates);
|
---|
51 | Assert.AreEqual(250, dict.SolutionDictionary.Keys.Count);
|
---|
52 | }
|
---|
53 | }
|
---|
54 | }
|
---|