Changeset 2840
- Timestamp:
- 02/19/10 12:55:18 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.Permutation/3.3/Tests
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Permutation/3.3/Tests/OrderCrossoverTest.cs
r2836 r2840 124 124 // based on the previous with changed breakpoints 125 125 random.Reset(); 126 random.IntNumbers = new int[] { 4, 4};127 expected = new Permutation(new int[] { 3, 4, 0, 9, 7, 8, 2, 1, 6, 5});126 random.IntNumbers = new int[] { 6, 9 }; 127 expected = new Permutation(new int[] { 3, 4, 8, 2, 7, 1, 6, 0, 5, 9 }); 128 128 Assert.IsTrue(expected.Validate()); 129 129 actual = target.Cross(random, parents); … … 132 132 // another one based on the previous with changed breakpoints 133 133 random.Reset(); 134 random.IntNumbers = new int[] { 9, 9 }; 135 expected = new Permutation(new int[] { 5, 3, 4, 0, 8, 2, 7, 1, 6, 9 }); 136 Assert.IsTrue(expected.Validate()); 137 actual = target.Cross(random, parents); 138 Assert.IsTrue(actual.Validate()); 139 Assert.IsTrue(Auxiliary.PermutationIsEqualByPosition(expected, actual)); 134 random.IntNumbers = new int[] { 0, 9 }; 135 expected = new Permutation(new int[] { 2, 1, 4, 3, 7, 8, 6, 0, 5, 9 }); 136 Assert.IsTrue(expected.Validate()); 137 actual = target.Cross(random, parents); 138 Assert.IsTrue(actual.Validate()); 139 Assert.IsTrue(Auxiliary.PermutationIsEqualByPosition(expected, actual)); 140 // perform a test with more than two parents 141 random.Reset(); 142 bool exceptionFired = false; 143 try { 144 target.Cross(random, new ItemArray<Permutation>(new Permutation[] { new Permutation(4), new Permutation(4), new Permutation(4)})); 145 } catch (System.InvalidOperationException) { 146 exceptionFired = true; 147 } 148 Assert.IsTrue(exceptionFired); 149 // perform a test when two permutations are of unequal length 150 random.Reset(); 151 exceptionFired = false; 152 try { 153 target.Cross(random, new ItemArray<Permutation>(new Permutation[] { new Permutation(8), new Permutation(6) })); 154 } catch (System.ArgumentException) { 155 exceptionFired = true; 156 } 157 Assert.IsTrue(exceptionFired); 140 158 } 141 159 … … 196 214 // based on the previous with changed breakpoints 197 215 random.Reset(); 198 random.IntNumbers = new int[] { 4, 4};199 expected = new Permutation(new int[] { 3, 4, 0, 9, 7, 8, 2, 1, 6, 5});216 random.IntNumbers = new int[] { 6, 9 }; 217 expected = new Permutation(new int[] { 3, 4, 8, 2, 7, 1, 6, 0, 5, 9 }); 200 218 Assert.IsTrue(expected.Validate()); 201 219 actual = OrderCrossover.Apply(random, parent1, parent2); … … 204 222 // another one based on the previous with changed breakpoints 205 223 random.Reset(); 206 random.IntNumbers = new int[] { 9, 9 }; 207 expected = new Permutation(new int[] { 5, 3, 4, 0, 8, 2, 7, 1, 6, 9 }); 208 Assert.IsTrue(expected.Validate()); 209 actual = OrderCrossover.Apply(random, parent1, parent2); 210 Assert.IsTrue(actual.Validate()); 211 Assert.IsTrue(Auxiliary.PermutationIsEqualByPosition(expected, actual)); 224 random.IntNumbers = new int[] { 0, 9 }; 225 expected = new Permutation(new int[] { 2, 1, 4, 3, 7, 8, 6, 0, 5, 9 }); 226 Assert.IsTrue(expected.Validate()); 227 actual = OrderCrossover.Apply(random, parent1, parent2); 228 Assert.IsTrue(actual.Validate()); 229 Assert.IsTrue(Auxiliary.PermutationIsEqualByPosition(expected, actual)); 230 // perform a test when the two permutations are of unequal length 231 random.Reset(); 232 bool exceptionFired = false; 233 try { 234 OrderCrossover.Apply(random, new Permutation(8), new Permutation(6)); 235 } catch (System.ArgumentException) { 236 exceptionFired = true; 237 } 238 Assert.IsTrue(exceptionFired); 212 239 } 213 240 -
trunk/sources/HeuristicLab.Permutation/3.3/Tests/Random.cs
r2836 r2840 62 62 public int Next(int maxVal) { 63 63 if (nextIntIndex >= intNumbers.Length) throw new InvalidOperationException("Random: No more integer random numbers available"); 64 if (IntNumbers[nextIntIndex] >= maxVal) throw new InvalidOperationException("Random: Next integer random number (" + IntNumbers[nextIntIndex] + ") is >= " + maxVal); 64 65 return intNumbers[nextIntIndex++]; 65 66 } … … 67 68 public int Next(int minVal, int maxVal) { 68 69 if (nextIntIndex >= intNumbers.Length) throw new InvalidOperationException("Random: No more integer random numbers available"); 70 if (IntNumbers[nextIntIndex] < minVal || IntNumbers[nextIntIndex] >= maxVal) throw new InvalidOperationException("Random: Next integer random number (" + IntNumbers[nextIntIndex] + ") is not in the range [" + minVal + ";" + maxVal + ")"); 69 71 return intNumbers[nextIntIndex++]; 70 72 } … … 72 74 public double NextDouble() { 73 75 if (nextDoubleIndex >= doubleNumbers.Length) throw new InvalidOperationException("Random: No more double random numbers available"); 76 if (doubleNumbers[nextDoubleIndex] < 0.0 || doubleNumbers[nextDoubleIndex] >= 1.0) throw new InvalidOperationException("Random: Next double ranomd number (" + DoubleNumbers[nextDoubleIndex] + ") is not in the range [0;1)"); 74 77 return doubleNumbers[nextDoubleIndex++]; 75 78 }
Note: See TracChangeset
for help on using the changeset viewer.