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 |
|
---|
22 | using Microsoft.VisualStudio.TestTools.UnitTesting;
|
---|
23 |
|
---|
24 | namespace HeuristicLab.Encodings.Permutation_33.Tests {
|
---|
25 | /// <summary>
|
---|
26 | ///This is a test class for InsertionManipulator and is intended
|
---|
27 | ///to contain all InsertionManipulator Unit Tests
|
---|
28 | ///</summary>
|
---|
29 | [TestClass()]
|
---|
30 | public class InsertionManipulatorTest {
|
---|
31 |
|
---|
32 |
|
---|
33 | private TestContext testContextInstance;
|
---|
34 |
|
---|
35 | /// <summary>
|
---|
36 | ///Gets or sets the test context which provides
|
---|
37 | ///information about and functionality for the current test run.
|
---|
38 | ///</summary>
|
---|
39 | public TestContext TestContext {
|
---|
40 | get {
|
---|
41 | return testContextInstance;
|
---|
42 | }
|
---|
43 | set {
|
---|
44 | testContextInstance = value;
|
---|
45 | }
|
---|
46 | }
|
---|
47 |
|
---|
48 | #region Additional test attributes
|
---|
49 | //
|
---|
50 | //You can use the following additional attributes as you write your tests:
|
---|
51 | //
|
---|
52 | //Use ClassInitialize to run code before running the first test in the class
|
---|
53 | //[ClassInitialize()]
|
---|
54 | //public static void MyClassInitialize(TestContext testContext)
|
---|
55 | //{
|
---|
56 | //}
|
---|
57 | //
|
---|
58 | //Use ClassCleanup to run code after all tests in a class have run
|
---|
59 | //[ClassCleanup()]
|
---|
60 | //public static void MyClassCleanup()
|
---|
61 | //{
|
---|
62 | //}
|
---|
63 | //
|
---|
64 | //Use TestInitialize to run code before running each test
|
---|
65 | //[TestInitialize()]
|
---|
66 | //public void MyTestInitialize()
|
---|
67 | //{
|
---|
68 | //}
|
---|
69 | //
|
---|
70 | //Use TestCleanup to run code after each test has run
|
---|
71 | //[TestCleanup()]
|
---|
72 | //public void MyTestCleanup()
|
---|
73 | //{
|
---|
74 | //}
|
---|
75 | //
|
---|
76 | #endregion
|
---|
77 |
|
---|
78 |
|
---|
79 | /// <summary>
|
---|
80 | ///A test for Apply
|
---|
81 | ///</summary>
|
---|
82 | [TestMethod()]
|
---|
83 | public void InsertionManipulatorApplyTest() {
|
---|
84 | TestRandom random = new TestRandom();
|
---|
85 | Permutation parent, expected;
|
---|
86 | // 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
|
---|
87 | random.Reset();
|
---|
88 | random.IntNumbers = new int[] { 3, 6 };
|
---|
89 | parent = new Permutation(new int[] { 0, 1, 2, 3, 4, 5, 6, 7 });
|
---|
90 | Assert.IsTrue(parent.Validate());
|
---|
91 |
|
---|
92 | expected = new Permutation(new int[] { 0, 1, 2, 4, 5, 6, 3, 7 });
|
---|
93 | Assert.IsTrue(expected.Validate());
|
---|
94 | InsertionManipulator.Apply(random, parent);
|
---|
95 | Assert.IsTrue(parent.Validate());
|
---|
96 | Assert.IsTrue(Auxiliary.PermutationIsEqualByPosition(expected, parent));
|
---|
97 |
|
---|
98 | // perform a test when the two permutations are of unequal length
|
---|
99 | random.Reset();
|
---|
100 | bool exceptionFired = false;
|
---|
101 | try {
|
---|
102 | CyclicCrossover.Apply(random, new Permutation(8), new Permutation(6));
|
---|
103 | }
|
---|
104 | catch (System.ArgumentException) {
|
---|
105 | exceptionFired = true;
|
---|
106 | }
|
---|
107 | Assert.IsTrue(exceptionFired);
|
---|
108 | }
|
---|
109 |
|
---|
110 | /// <summary>
|
---|
111 | ///A test for InsertionManipulator Constructor
|
---|
112 | ///</summary>
|
---|
113 | [TestMethod()]
|
---|
114 | public void InsertionManipulatorConstructorTest() {
|
---|
115 | InsertionManipulator target = new InsertionManipulator();
|
---|
116 | }
|
---|
117 | }
|
---|
118 | }
|
---|