Changeset 14492 for branches/MemPRAlgorithm/HeuristicLab.Tests/HeuristicLab.Encodings.LinearLinkageEncoding-3.3/MoveTests.cs
- Timestamp:
- 12/14/16 20:45:46 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/MemPRAlgorithm/HeuristicLab.Tests/HeuristicLab.Encodings.LinearLinkageEncoding-3.3/MoveTests.cs
r14477 r14492 1 1 using System; 2 using System.Collections.Generic; 2 3 using System.Linq; 3 4 using HeuristicLab.Encodings.LinearLinkageEncoding; … … 11 12 public void TestApplyUndo() { 12 13 var random = new MersenneTwister(42); 13 var lle = MaxGroupsLinearLinkageCreator.Apply(random, 32, 8); 14 var before = (LinearLinkage)lle.Clone(); 15 var moves = 0; 16 foreach (var move in MoveGenerator.Generate(lle)) { 17 move.Apply(lle); 18 Assert.IsFalse(before.SequenceEqual(lle)); 19 move.Undo(lle); 20 Assert.IsTrue(before.SequenceEqual(lle)); 21 moves++; 14 for (var p = 0; p < 7; p++) { 15 var lle = ExactGroupsLinearLinkageCreator.Apply(random, 64, (int)Math.Pow(2, p)); 16 var before = (LinearLinkage)lle.Clone(); 17 var beforeb = before.ToBackLinks(); 18 var moves = 0; 19 foreach (var move in MoveGenerator.Generate(lle)) { 20 var lleb = lle.ToBackLinks(); 21 move.Apply(lle); 22 move.ApplyToLLEb(lleb); 23 Assert.IsFalse(before.SequenceEqual(lle)); 24 Assert.IsFalse(lleb.SequenceEqual(beforeb)); 25 Assert.IsTrue(lleb.SequenceEqual(lle.ToBackLinks())); 26 Assert.IsTrue(lle.SequenceEqual(LinearLinkage.FromBackLinks(lleb))); 27 move.Undo(lle); 28 Assert.IsTrue(before.SequenceEqual(lle)); 29 moves++; 30 } 31 Assert.IsTrue(moves > 0); 22 32 } 23 Assert.IsTrue(moves > 0); 33 } 34 35 [TestMethod] 36 public void TestApply() { 37 var random = new MersenneTwister(42); 38 for (var p = 0; p < 7; p++) { 39 var lle = ExactGroupsLinearLinkageCreator.Apply(random, 64, (int)Math.Pow(2, p)); 40 var lleb = lle.ToBackLinks(); 41 var groupItems = new List<int>() { 0 }; 42 var moves = 0; 43 for (var i = 1; i < lle.Length; i++) { 44 var move = MoveGenerator.GenerateForItem(i, groupItems, lle, lleb).SampleRandom(random); 45 move.Apply(lle); 46 move.ApplyToLLEb(lleb); 47 Assert.IsTrue(lleb.SequenceEqual(lle.ToBackLinks())); 48 Assert.IsTrue(lle.SequenceEqual(LinearLinkage.FromBackLinks(lleb))); 49 50 if (lleb[i] != i) 51 groupItems.Remove(lleb[i]); 52 groupItems.Add(i); 53 54 moves++; 55 } 56 Assert.IsTrue(moves == lle.Length - 1); 57 } 24 58 } 25 59 }
Note: See TracChangeset
for help on using the changeset viewer.