[3742] | 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 |
|
---|
[4068] | 22 | using HeuristicLab.Core;
|
---|
[3742] | 23 | using HeuristicLab.Encodings.RealVectorEncoding;
|
---|
[2936] | 24 | using Microsoft.VisualStudio.TestTools.UnitTesting;
|
---|
| 25 |
|
---|
[3053] | 26 | namespace HeuristicLab.Encodings.RealVectorEncoding_33.Tests {
|
---|
[2936] | 27 |
|
---|
| 28 |
|
---|
| 29 | /// <summary>
|
---|
| 30 | ///This is a test class for RandomConvexCrossoverTest and is intended
|
---|
| 31 | ///to contain all RandomConvexCrossoverTest Unit Tests
|
---|
| 32 | ///</summary>
|
---|
| 33 | [TestClass()]
|
---|
| 34 | public class RandomConvexCrossoverTest {
|
---|
| 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 | /// <summary>
|
---|
| 83 | ///A test for Cross
|
---|
| 84 | ///</summary>
|
---|
| 85 | [TestMethod()]
|
---|
[3053] | 86 | [DeploymentItem("HeuristicLab.Encodings.RealVectorEncoding-3.3.dll")]
|
---|
[2936] | 87 | public void RandomConvexCrossoverCrossTest() {
|
---|
| 88 | RandomConvexCrossover_Accessor target = new RandomConvexCrossover_Accessor(new PrivateObject(typeof(RandomConvexCrossover)));
|
---|
[3060] | 89 | ItemArray<RealVector> parents;
|
---|
[2936] | 90 | TestRandom random = new TestRandom();
|
---|
| 91 | bool exceptionFired;
|
---|
| 92 | // The following test checks if there is an exception when there are more than 2 parents
|
---|
| 93 | random.Reset();
|
---|
[3060] | 94 | parents = new ItemArray<RealVector>(new RealVector[] { new RealVector(5), new RealVector(6), new RealVector(4) });
|
---|
[2936] | 95 | exceptionFired = false;
|
---|
| 96 | try {
|
---|
[3060] | 97 | RealVector actual;
|
---|
[2936] | 98 | actual = target.Cross(random, parents);
|
---|
| 99 | }
|
---|
| 100 | catch (System.ArgumentException) {
|
---|
| 101 | exceptionFired = true;
|
---|
| 102 | }
|
---|
| 103 | Assert.IsTrue(exceptionFired);
|
---|
| 104 | // The following test checks if there is an exception when there are less than 2 parents
|
---|
| 105 | random.Reset();
|
---|
[3060] | 106 | parents = new ItemArray<RealVector>(new RealVector[] { new RealVector(4) });
|
---|
[2936] | 107 | exceptionFired = false;
|
---|
| 108 | try {
|
---|
[3060] | 109 | RealVector actual;
|
---|
[2936] | 110 | actual = target.Cross(random, parents);
|
---|
[4068] | 111 | }
|
---|
| 112 | catch (System.ArgumentException) {
|
---|
[2936] | 113 | exceptionFired = true;
|
---|
| 114 | }
|
---|
| 115 | Assert.IsTrue(exceptionFired);
|
---|
| 116 | }
|
---|
| 117 |
|
---|
| 118 | /// <summary>
|
---|
| 119 | ///A test for Apply
|
---|
| 120 | ///</summary>
|
---|
| 121 | [TestMethod()]
|
---|
| 122 | public void RandomConvexCrossoverApplyTest() {
|
---|
| 123 | TestRandom random = new TestRandom();
|
---|
[3060] | 124 | RealVector parent1, parent2, expected, actual;
|
---|
[2936] | 125 | bool exceptionFired;
|
---|
| 126 | // The following test is not based on published examples
|
---|
| 127 | random.Reset();
|
---|
| 128 | random.DoubleNumbers = new double[] { 0.3 };
|
---|
[3060] | 129 | parent1 = new RealVector(new double[] { 0.2, 0.2, 0.3, 0.5, 0.1 });
|
---|
| 130 | parent2 = new RealVector(new double[] { 0.4, 0.1, 0.3, 0.2, 0.8 });
|
---|
| 131 | expected = new RealVector(new double[] { 0.34, 0.13, 0.3, 0.29, 0.59 });
|
---|
[2936] | 132 | actual = RandomConvexCrossover.Apply(random, parent1, parent2);
|
---|
[3061] | 133 | Assert.IsTrue(Auxiliary.RealVectorIsAlmostEqualByPosition(actual, expected));
|
---|
[2936] | 134 | // The following test is not based on published examples
|
---|
| 135 | random.Reset();
|
---|
| 136 | random.DoubleNumbers = new double[] { 0.3 };
|
---|
[3060] | 137 | parent1 = new RealVector(new double[] { 0.2, 0.2, 0.3, 0.5, 0.1, 0.9 }); // this parent is longer
|
---|
| 138 | parent2 = new RealVector(new double[] { 0.4, 0.1, 0.3, 0.2, 0.8 });
|
---|
[2936] | 139 | exceptionFired = false;
|
---|
| 140 | try {
|
---|
| 141 | actual = RandomConvexCrossover.Apply(random, parent1, parent2);
|
---|
[4068] | 142 | }
|
---|
| 143 | catch (System.ArgumentException) {
|
---|
[2936] | 144 | exceptionFired = true;
|
---|
| 145 | }
|
---|
| 146 | Assert.IsTrue(exceptionFired);
|
---|
| 147 | }
|
---|
| 148 |
|
---|
| 149 | /// <summary>
|
---|
| 150 | ///A test for RandomConvexCrossover Constructor
|
---|
| 151 | ///</summary>
|
---|
| 152 | [TestMethod()]
|
---|
| 153 | public void RandomConvexCrossoverConstructorTest() {
|
---|
| 154 | RandomConvexCrossover target = new RandomConvexCrossover();
|
---|
| 155 | }
|
---|
| 156 | }
|
---|
| 157 | }
|
---|