Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Permutation/3.3/Tests/TranslocationManipulatorTest.cs @ 2854

Last change on this file since 2854 was 2854, checked in by svonolfe, 14 years ago

Ported ported permutation operators to HL 3.3 and added test cases (#889)

File size: 3.9 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using HeuristicLab.Permutation;
23using Microsoft.VisualStudio.TestTools.UnitTesting;
24using HeuristicLab.Core;
25
26namespace HeuristicLab.Permutation.Tests {
27
28
29  /// <summary>
30  ///This is a test class for TranslocationManipulator and is intended
31  ///to contain all TranslocationManipulator Unit Tests
32  ///</summary>
33  [TestClass()]
34  public class TranslocationManipulatorTest {
35
36
37    private TestContext testContextInstance;
38
39    /// <summary>
40    ///Gets or sets the test context which provides
41    ///information about and functionality for the current test run.
42    ///</summary>
43    public TestContext TestContext {
44      get {
45        return testContextInstance;
46      }
47      set {
48        testContextInstance = value;
49      }
50    }
51
52    #region Additional test attributes
53    //
54    //You can use the following additional attributes as you write your tests:
55    //
56    //Use ClassInitialize to run code before running the first test in the class
57    //[ClassInitialize()]
58    //public static void MyClassInitialize(TestContext testContext)
59    //{
60    //}
61    //
62    //Use ClassCleanup to run code after all tests in a class have run
63    //[ClassCleanup()]
64    //public static void MyClassCleanup()
65    //{
66    //}
67    //
68    //Use TestInitialize to run code before running each test
69    //[TestInitialize()]
70    //public void MyTestInitialize()
71    //{
72    //}
73    //
74    //Use TestCleanup to run code after each test has run
75    //[TestCleanup()]
76    //public void MyTestCleanup()
77    //{
78    //}
79    //
80    #endregion
81
82
83    /// <summary>
84    ///A test for Apply
85    ///</summary>
86    [TestMethod()]
87    public void TranslocationManipulatorApplyTest() {
88      TestRandom random = new TestRandom();
89      Permutation parent, expected;
90      // The following test is based on an example from Larranaga, P. et al. 1999. Genetic Algorithms for the Travelling Salesman Problem: A Review of Representations and Operators. Artificial Intelligence Review, 13, p. 24
91      random.Reset();
92      random.IntNumbers = new int[] { 2, 4, 4 };
93      parent = new Permutation(new int[] { 0, 1, 2, 3, 4, 5, 6, 7 });
94      Assert.IsTrue(parent.Validate());
95     
96      expected = new Permutation(new int[] { 0, 1, 5, 6, 2, 3, 4, 7 });
97      Assert.IsTrue(expected.Validate());
98      TranslocationManipulator.Apply(random, parent);
99      Assert.IsTrue(parent.Validate());
100      Assert.IsTrue(Auxiliary.PermutationIsEqualByPosition(expected, parent));
101     
102      // perform a test when the two permutations are of unequal length
103      random.Reset();
104      bool exceptionFired = false;
105      try {
106        CyclicCrossover.Apply(random, new Permutation(8), new Permutation(6));
107      }
108      catch (System.ArgumentException) {
109        exceptionFired = true;
110      }
111      Assert.IsTrue(exceptionFired);
112    }
113
114    /// <summary>
115    ///A test for InversionManipulator Constructor
116    ///</summary>
117    [TestMethod()]
118    public void InversionManipulatorConstructorTest() {
119      TranslocationManipulator target = new TranslocationManipulator();
120    }
121  }
122}
Note: See TracBrowser for help on using the repository browser.