using System.Linq; using HeuristicLab.Analysis.AlgorithmBehavior.Analyzers; using HeuristicLab.Encodings.PermutationEncoding; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace AlgorithmBehaviorUnitTests { [TestClass] public class UnitTest2 { [TestMethod] public void TestPermutationSolutionDictionary() { var rand = new HeuristicLab.Random.FastRandom(); PermutationWrapperEqualityComparer comp = new PermutationWrapperEqualityComparer(); PermutationSolutionDictionary dict = new PermutationSolutionDictionary(); int realDuplicates = 0; int noDuplicates = 0; PermutationWrapper[] permutations = new PermutationWrapper[500]; for (int i = 0; i < permutations.Length; i += 2) { var p = new Permutation(PermutationTypes.RelativeUndirected, 21, rand); var pw = new PermutationWrapper(p); permutations[i] = pw; permutations[i + 1] = pw; PermutationInformation pi = new PermutationInformation(); pi.Generation = rand.Next(0, 100); pi.ProducedBy = ProducedBy.Mutation; dict.Add(pw, pi); } for (int i = 0; i < permutations.Length; i++) { for (int j = i + 1; j < permutations.Length; j++) { if (comp.Equals(permutations[i], permutations[j])) { realDuplicates++; break; } } } for (int i = 0; i < dict.SolutionDictionary.Keys.Count; i++) { for (int j = i + 1; j < dict.SolutionDictionary.Keys.Count; j++) { if (comp.Equals(dict.SolutionDictionary.Keys.ElementAt(i), dict.SolutionDictionary.Keys.ElementAt(j))) { noDuplicates++; break; } } } Assert.AreNotEqual(0, realDuplicates); Assert.AreEqual(0, noDuplicates); Assert.AreEqual(250, dict.SolutionDictionary.Keys.Count); } } }