Changeset 3060 for trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Tests/BlendAlphaCrossoverTest.cs
- Timestamp:
- 03/16/10 10:46:59 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Tests/BlendAlphaCrossoverTest.cs
r3053 r3060 68 68 public void BlendAlphaCrossoverCrossTest() { 69 69 BlendAlphaCrossover_Accessor target = new BlendAlphaCrossover_Accessor(new PrivateObject(typeof(BlendAlphaCrossover))); 70 ItemArray< DoubleArray> parents;70 ItemArray<RealVector> parents; 71 71 TestRandom random = new TestRandom(); 72 72 bool exceptionFired; 73 73 // The following test checks if there is an exception when there are more than 2 parents 74 74 random.Reset(); 75 parents = new ItemArray< DoubleArray>(new DoubleArray[] { new DoubleArray(5), new DoubleArray(6), new DoubleArray(4) });75 parents = new ItemArray<RealVector>(new RealVector[] { new RealVector(5), new RealVector(6), new RealVector(4) }); 76 76 exceptionFired = false; 77 77 try { 78 DoubleArrayactual;78 RealVector actual; 79 79 actual = target.Cross(random, parents); 80 80 } catch (System.ArgumentException) { … … 84 84 // The following test checks if there is an exception when there are less than 2 parents 85 85 random.Reset(); 86 parents = new ItemArray< DoubleArray>(new DoubleArray[] { new DoubleArray(4) });86 parents = new ItemArray<RealVector>(new RealVector[] { new RealVector(4) }); 87 87 exceptionFired = false; 88 88 try { 89 DoubleArrayactual;89 RealVector actual; 90 90 actual = target.Cross(random, parents); 91 91 } catch (System.ArgumentException) { … … 101 101 public void BlendAlphaCrossoverApplyTest() { 102 102 TestRandom random = new TestRandom(); 103 DoubleArrayparent1, parent2, expected, actual;103 RealVector parent1, parent2, expected, actual; 104 104 DoubleValue alpha; 105 105 bool exceptionFired; … … 108 108 random.DoubleNumbers = new double[] { 0.5, 0.5, 0.5, 0.5, 0.5 }; 109 109 alpha = new DoubleValue(0.5); 110 parent1 = new DoubleArray(new double[] { 0.2, 0.2, 0.3, 0.5, 0.1 });111 parent2 = new DoubleArray(new double[] { 0.4, 0.1, 0.3, 0.2, 0.8 });112 expected = new DoubleArray(new double[] { 0.3, 0.15, 0.3, 0.35, 0.45 });110 parent1 = new RealVector(new double[] { 0.2, 0.2, 0.3, 0.5, 0.1 }); 111 parent2 = new RealVector(new double[] { 0.4, 0.1, 0.3, 0.2, 0.8 }); 112 expected = new RealVector(new double[] { 0.3, 0.15, 0.3, 0.35, 0.45 }); 113 113 actual = BlendAlphaCrossover.Apply(random, parent1, parent2, alpha); 114 Assert.IsTrue(Auxiliary. RealVectorIsAlmostEqualByPosition(actual, expected));114 Assert.IsTrue(Auxiliary.DoubleArrayIsAlmostEqualByPosition(actual, expected)); 115 115 // The following test is not based on published examples 116 116 random.Reset(); 117 117 random.DoubleNumbers = new double[] { 0.25, 0.75, 0.25, 0.75, 0.25 }; 118 118 alpha = new DoubleValue(0.25); 119 parent1 = new DoubleArray(new double[] { 0.2, 0.2, 0.3, 0.5, 0.1 });120 parent2 = new DoubleArray(new double[] { 0.4, 0.1, 0.3, 0.2, 0.8 });121 expected = new DoubleArray(new double[] { 0.225, 0.1875, 0.3, 0.4625, 0.1875 });119 parent1 = new RealVector(new double[] { 0.2, 0.2, 0.3, 0.5, 0.1 }); 120 parent2 = new RealVector(new double[] { 0.4, 0.1, 0.3, 0.2, 0.8 }); 121 expected = new RealVector(new double[] { 0.225, 0.1875, 0.3, 0.4625, 0.1875 }); 122 122 actual = BlendAlphaCrossover.Apply(random, parent1, parent2, alpha); 123 Assert.IsTrue(Auxiliary. RealVectorIsAlmostEqualByPosition(actual, expected));123 Assert.IsTrue(Auxiliary.DoubleArrayIsAlmostEqualByPosition(actual, expected)); 124 124 // The following test is not based on published examples 125 125 random.Reset(); 126 126 random.DoubleNumbers = new double[] { 0.25, 0.75, 0.25, 0.75, 0.25 }; 127 127 alpha = new DoubleValue(-0.25); // negative values for alpha are not allowed 128 parent1 = new DoubleArray(new double[] { 0.2, 0.2, 0.3, 0.5, 0.1 });129 parent2 = new DoubleArray(new double[] { 0.4, 0.1, 0.3, 0.2, 0.8 });130 expected = new DoubleArray(new double[] { 0.225, 0.1875, 0.3, 0.4625, 0.1875 });128 parent1 = new RealVector(new double[] { 0.2, 0.2, 0.3, 0.5, 0.1 }); 129 parent2 = new RealVector(new double[] { 0.4, 0.1, 0.3, 0.2, 0.8 }); 130 expected = new RealVector(new double[] { 0.225, 0.1875, 0.3, 0.4625, 0.1875 }); 131 131 exceptionFired = false; 132 132 try { … … 140 140 random.DoubleNumbers = new double[] { 0.25, 0.75, 0.25, 0.75, 0.25, .75 }; 141 141 alpha = new DoubleValue(0.25); 142 parent1 = new DoubleArray(new double[] { 0.2, 0.2, 0.3, 0.5, 0.1, 0.9 }); // this parent is longer143 parent2 = new DoubleArray(new double[] { 0.4, 0.1, 0.3, 0.2, 0.8 });144 expected = new DoubleArray(new double[] { 0.225, 0.1875, 0.3, 0.4625, 0.1875 });142 parent1 = new RealVector(new double[] { 0.2, 0.2, 0.3, 0.5, 0.1, 0.9 }); // this parent is longer 143 parent2 = new RealVector(new double[] { 0.4, 0.1, 0.3, 0.2, 0.8 }); 144 expected = new RealVector(new double[] { 0.225, 0.1875, 0.3, 0.4625, 0.1875 }); 145 145 exceptionFired = false; 146 146 try {
Note: See TracChangeset
for help on using the changeset viewer.