Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HiveHiveEngine/HeuristicLab.Tests/HeuristicLab.Encodings.PermutationEncoding-3.3/UniformLikeCrossoverTest.cs @ 10207

Last change on this file since 10207 was 6891, checked in by abeham, 13 years ago

#1619, #1628

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