[3053] | 1 | using HeuristicLab.Encodings.IntegerVectorEncoding;
|
---|
[3032] | 2 | using Microsoft.VisualStudio.TestTools.UnitTesting;
|
---|
| 3 | using HeuristicLab.Core;
|
---|
| 4 | using HeuristicLab.Data;
|
---|
| 5 | using HeuristicLab.Parameters;
|
---|
| 6 |
|
---|
[3053] | 7 | namespace HeuristicLab.Encodings.IntegerVectorEncoding_33.Tests {
|
---|
[3032] | 8 |
|
---|
| 9 |
|
---|
| 10 | /// <summary>
|
---|
| 11 | ///This is a test class for DiscreteCrossoverTest and is intended
|
---|
| 12 | ///to contain all DiscreteCrossoverTest Unit Tests
|
---|
| 13 | ///</summary>
|
---|
| 14 | [TestClass()]
|
---|
| 15 | public class DiscreteCrossoverTest {
|
---|
| 16 |
|
---|
| 17 |
|
---|
| 18 | private TestContext testContextInstance;
|
---|
| 19 |
|
---|
| 20 | /// <summary>
|
---|
| 21 | ///Gets or sets the test context which provides
|
---|
| 22 | ///information about and functionality for the current test run.
|
---|
| 23 | ///</summary>
|
---|
| 24 | public TestContext TestContext {
|
---|
| 25 | get {
|
---|
| 26 | return testContextInstance;
|
---|
| 27 | }
|
---|
| 28 | set {
|
---|
| 29 | testContextInstance = value;
|
---|
| 30 | }
|
---|
| 31 | }
|
---|
| 32 |
|
---|
| 33 | #region Additional test attributes
|
---|
| 34 | //
|
---|
| 35 | //You can use the following additional attributes as you write your tests:
|
---|
| 36 | //
|
---|
| 37 | //Use ClassInitialize to run code before running the first test in the class
|
---|
| 38 | //[ClassInitialize()]
|
---|
| 39 | //public static void MyClassInitialize(TestContext testContext)
|
---|
| 40 | //{
|
---|
| 41 | //}
|
---|
| 42 | //
|
---|
| 43 | //Use ClassCleanup to run code after all tests in a class have run
|
---|
| 44 | //[ClassCleanup()]
|
---|
| 45 | //public static void MyClassCleanup()
|
---|
| 46 | //{
|
---|
| 47 | //}
|
---|
| 48 | //
|
---|
| 49 | //Use TestInitialize to run code before running each test
|
---|
| 50 | //[TestInitialize()]
|
---|
| 51 | //public void MyTestInitialize()
|
---|
| 52 | //{
|
---|
| 53 | //}
|
---|
| 54 | //
|
---|
| 55 | //Use TestCleanup to run code after each test has run
|
---|
| 56 | //[TestCleanup()]
|
---|
| 57 | //public void MyTestCleanup()
|
---|
| 58 | //{
|
---|
| 59 | //}
|
---|
| 60 | //
|
---|
| 61 | #endregion
|
---|
| 62 |
|
---|
| 63 | /// <summary>
|
---|
| 64 | ///A test for Cross
|
---|
| 65 | ///</summary>
|
---|
| 66 | [TestMethod()]
|
---|
[3053] | 67 | [DeploymentItem("HeuristicLab.Encodings.IntegerVectorEncoding-3.3.dll")]
|
---|
[3032] | 68 | public void DiscreteCrossoverCrossTest() {
|
---|
| 69 | DiscreteCrossover_Accessor target = new DiscreteCrossover_Accessor(new PrivateObject(typeof(DiscreteCrossover)));
|
---|
[3059] | 70 | ItemArray<IntegerVector> parents;
|
---|
[3032] | 71 | TestRandom random = new TestRandom();
|
---|
| 72 | bool exceptionFired;
|
---|
| 73 | // The following test checks if there is an exception when there are less than 2 parents
|
---|
| 74 | random.Reset();
|
---|
[3059] | 75 | parents = new ItemArray<IntegerVector>(new IntegerVector[] { new IntegerVector(4) });
|
---|
[3032] | 76 | exceptionFired = false;
|
---|
| 77 | try {
|
---|
[3061] | 78 | IntegerVector actual;
|
---|
[3032] | 79 | actual = target.Cross(random, parents);
|
---|
| 80 | } catch (System.ArgumentException) {
|
---|
| 81 | exceptionFired = true;
|
---|
| 82 | }
|
---|
| 83 | Assert.IsTrue(exceptionFired);
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | /// <summary>
|
---|
| 87 | ///A test for Apply
|
---|
| 88 | ///</summary>
|
---|
| 89 | [TestMethod()]
|
---|
| 90 | public void DiscreteCrossoverApplyTest() {
|
---|
| 91 | TestRandom random = new TestRandom();
|
---|
[3059] | 92 | IntegerVector parent1, parent2, expected, actual;
|
---|
[3032] | 93 | bool exceptionFired;
|
---|
| 94 | // The following test is not based on published examples
|
---|
| 95 | random.Reset();
|
---|
| 96 | random.DoubleNumbers = new double[] { 0, 0, 0.9, 0, 0.9 };
|
---|
[3059] | 97 | parent1 = new IntegerVector(new int[] { 2, 2, 3, 5, 1 });
|
---|
| 98 | parent2 = new IntegerVector(new int[] { 4, 1, 3, 2, 8 });
|
---|
| 99 | expected = new IntegerVector(new int[] { 2, 2, 3, 5, 8 });
|
---|
[3032] | 100 | actual = DiscreteCrossover.Apply(random, parent1, parent2);
|
---|
[3061] | 101 | Assert.IsTrue(Auxiliary.IntegerVectorIsEqualByPosition(actual, expected));
|
---|
[3032] | 102 |
|
---|
| 103 | // The following test is not based on published examples
|
---|
| 104 | random.Reset();
|
---|
| 105 | random.DoubleNumbers = new double[] { 0, 0, 0.9, 0, 0.9 };
|
---|
[3059] | 106 | parent1 = new IntegerVector(new int[] { 2, 2, 3, 5, 1, 9 }); // this parent is longer
|
---|
| 107 | parent2 = new IntegerVector(new int[] { 4, 1, 3, 2, 8 });
|
---|
[3032] | 108 | exceptionFired = false;
|
---|
| 109 | try {
|
---|
| 110 | actual = DiscreteCrossover.Apply(random, parent1, parent2);
|
---|
| 111 | } catch (System.ArgumentException) {
|
---|
| 112 | exceptionFired = true;
|
---|
| 113 | }
|
---|
| 114 | Assert.IsTrue(exceptionFired);
|
---|
| 115 | }
|
---|
| 116 |
|
---|
| 117 | /// <summary>
|
---|
| 118 | ///A test for DiscreteCrossover Constructor
|
---|
| 119 | ///</summary>
|
---|
| 120 | [TestMethod()]
|
---|
| 121 | public void DiscreteCrossoverConstructorTest() {
|
---|
| 122 | DiscreteCrossover target = new DiscreteCrossover();
|
---|
| 123 | }
|
---|
| 124 | }
|
---|
| 125 | }
|
---|