Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/19/10 12:55:18 (15 years ago)
Author:
abeham
Message:

updated the fake random number generator to throw an exception when the requested random variable doesn't fit the bounds
updated the OrderCrossoverTest to test for thrown exceptions #889

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Permutation/3.3/Tests/Random.cs

    r2836 r2840  
    6262    public int Next(int maxVal) {
    6363      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);
    6465      return intNumbers[nextIntIndex++];
    6566    }
     
    6768    public int Next(int minVal, int maxVal) {
    6869      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 + ")");
    6971      return intNumbers[nextIntIndex++];
    7072    }
     
    7274    public double NextDouble() {
    7375      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)");
    7477      return doubleNumbers[nextDoubleIndex++];
    7578    }
Note: See TracChangeset for help on using the changeset viewer.