Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PersistenceSpeedUp/HeuristicLab.Encodings.PermutationEncoding/3.3/Tests/UniformLikeCrossoverTest.cs @ 16310

Last change on this file since 16310 was 6760, checked in by epitzer, 13 years ago

#1530 integrate changes from trunk

File size: 3.4 KB
Line 
1using HeuristicLab.Core;
2using HeuristicLab.Encodings.PermutationEncoding;
3using Microsoft.VisualStudio.TestTools.UnitTesting;
4
5namespace HeuristicLab.Encodings.PermutationEncoding_33.Tests {
6
7
8  /// <summary>
9  ///This is a test class for UniformLikeCrossoverTest and is intended
10  ///to contain all UniformLikeCrossoverTest Unit Tests
11  ///</summary>
12  [TestClass()]
13  public class UniformLikeCrossoverTest {
14
15
16    private TestContext testContextInstance;
17
18    /// <summary>
19    ///Gets or sets the test context which provides
20    ///information about and functionality for the current test run.
21    ///</summary>
22    public TestContext TestContext {
23      get {
24        return testContextInstance;
25      }
26      set {
27        testContextInstance = value;
28      }
29    }
30
31    #region Additional test attributes
32    //
33    //You can use the following additional attributes as you write your tests:
34    //
35    //Use ClassInitialize to run code before running the first test in the class
36    //[ClassInitialize()]
37    //public static void MyClassInitialize(TestContext testContext)
38    //{
39    //}
40    //
41    //Use ClassCleanup to run code after all tests in a class have run
42    //[ClassCleanup()]
43    //public static void MyClassCleanup()
44    //{
45    //}
46    //
47    //Use TestInitialize to run code before running each test
48    //[TestInitialize()]
49    //public void MyTestInitialize()
50    //{
51    //}
52    //
53    //Use TestCleanup to run code after each test has run
54    //[TestCleanup()]
55    //public void MyTestCleanup()
56    //{
57    //}
58    //
59    #endregion
60
61
62    /// <summary>
63    ///A test for Apply
64    ///</summary>
65    [TestMethod()]
66    public void UniformLikeCrossoverApplyTest() {
67      // test from the paper
68      IRandom random = new TestRandom(new int[] { 0 }, new double[] { 0.2, 0.7, 0.2, 0.2 }); // TODO: Initialize to an appropriate value
69      Permutation parent1 = new Permutation(PermutationTypes.Absolute,
70        new int[] { 3, 2, 0, 7, 5, 4, 1, 6 });
71      Assert.IsTrue(parent1.Validate());
72      Permutation parent2 = new Permutation(PermutationTypes.Absolute,
73        new int[] { 5, 0, 4, 7, 1, 3, 2, 6 });
74      Assert.IsTrue(parent2.Validate());
75      Permutation expected = new Permutation(PermutationTypes.Absolute,
76        new int[] { 3, 0, 4, 7, 5, 2, 1, 6 });
77      Assert.IsTrue(expected.Validate());
78      Permutation actual;
79      actual = UniformLikeCrossover.Apply(random, parent1, parent2);
80      Assert.IsTrue(actual.Validate());
81      Assert.IsTrue(Auxiliary.PermutationIsEqualByPosition(expected, actual));
82    }
83
84    /// <summary>
85    ///A test for Cross
86    ///</summary>
87    [TestMethod()]
88    [DeploymentItem("HeuristicLab.Encodings.PermutationEncoding-3.3.dll")]
89    public void UniformLikeCrossoverCrossTest() {
90      UniformLikeCrossover_Accessor target = new UniformLikeCrossover_Accessor();
91      IRandom random = new TestRandom(new int[] { }, new double[] { 0.1, 0.2, 0.3, 0.4 });
92      random.Reset();
93      bool exceptionFired = false;
94      try {
95        target.Cross(random, new ItemArray<Permutation>(new Permutation[] {
96          new Permutation(PermutationTypes.RelativeUndirected, 4), new Permutation(PermutationTypes.RelativeUndirected, 4), new Permutation(PermutationTypes.RelativeUndirected, 4)}));
97      } catch (System.InvalidOperationException) {
98        exceptionFired = true;
99      }
100      Assert.IsTrue(exceptionFired);
101    }
102  }
103}
Note: See TracBrowser for help on using the repository browser.