Free cookie consent management tool by TermsFeed Policy Generator

source: branches/Scheduling/HeuristicLab.Encodings.ScheduleEncoding.Tests/TestRandom.cs @ 9133

Last change on this file since 9133 was 8603, checked in by gkronber, 12 years ago

#1329:

  • updated copy-right year
  • trimmed assembly and plugin references
  • removed x86 and x64 build configurations
File size: 4.6 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 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
22using System;
23using HeuristicLab.Common;
24using HeuristicLab.Core;
25
26namespace HeuristicLab.Encodings.ScheduleEncoding.Tests {
27  public class TestRandom : IRandom {
28    #region Variables and Properties
29    private int[] intNumbers;
30    public int[] IntNumbers {
31      get { return intNumbers; }
32      set {
33        if (value == null) intNumbers = new int[0];
34        else intNumbers = value;
35      }
36    }
37    private int nextIntIndex;
38    private double[] doubleNumbers;
39    public double[] DoubleNumbers {
40      get { return doubleNumbers; }
41      set {
42        if (value == null) doubleNumbers = new double[0];
43        else doubleNumbers = value;
44      }
45    }
46    private int nextDoubleIndex;
47    #endregion
48
49    public TestRandom() {
50      intNumbers = new int[0];
51      doubleNumbers = new double[0];
52      nextIntIndex = 0;
53      nextDoubleIndex = 0;
54    }
55
56    public TestRandom(int[] intNumbers, double[] doubleNumbers) {
57      if (intNumbers == null) intNumbers = new int[0];
58      else this.intNumbers = intNumbers;
59      if (doubleNumbers == null) doubleNumbers = new double[0];
60      else this.doubleNumbers = doubleNumbers;
61      nextIntIndex = 0;
62      nextDoubleIndex = 0;
63    }
64
65    #region IRandom Members
66
67    public void Reset() {
68      nextIntIndex = 0;
69      nextDoubleIndex = 0;
70    }
71
72    public void Reset(int seed) {
73      throw new NotImplementedException();
74    }
75
76    public int Next() {
77      if (nextIntIndex >= intNumbers.Length) throw new InvalidOperationException("Random: No more integer random numbers available");
78      return intNumbers[nextIntIndex++];
79    }
80
81    public int Next(int maxVal) {
82      if (nextIntIndex >= intNumbers.Length) throw new InvalidOperationException("Random: No more integer random numbers available");
83      if (IntNumbers[nextIntIndex] >= maxVal) throw new InvalidOperationException("Random: Next integer random number (" + IntNumbers[nextIntIndex] + ") is >= " + maxVal);
84      return intNumbers[nextIntIndex++];
85    }
86
87    public int Next(int minVal, int maxVal) {
88      if (nextIntIndex >= intNumbers.Length) throw new InvalidOperationException("Random: No more integer random numbers available");
89      if (IntNumbers[nextIntIndex] < minVal || IntNumbers[nextIntIndex] >= maxVal) throw new InvalidOperationException("Random: Next integer random number (" + IntNumbers[nextIntIndex] + ") is not in the range [" + minVal + ";" + maxVal + ")");
90      return intNumbers[nextIntIndex++];
91    }
92
93    public double NextDouble() {
94      if (nextDoubleIndex >= doubleNumbers.Length) throw new InvalidOperationException("Random: No more double random numbers available");
95      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)");
96      return doubleNumbers[nextDoubleIndex++];
97    }
98
99    #endregion
100
101    #region IItem Members
102
103    public string ItemName {
104      get { throw new NotImplementedException(); }
105    }
106
107    public string ItemDescription {
108      get { throw new NotImplementedException(); }
109    }
110
111    public Version ItemVersion {
112      get { throw new NotImplementedException(); }
113    }
114
115    public System.Drawing.Image ItemImage {
116      get { throw new NotImplementedException(); }
117    }
118
119#pragma warning disable 67
120    public event EventHandler ItemImageChanged;
121    public event EventHandler ToStringChanged;
122#pragma warning restore 67
123    #endregion
124
125    #region IDeepCloneable Members
126
127    public IDeepCloneable Clone(Cloner cloner) {
128      throw new NotImplementedException();
129    }
130
131    #endregion
132
133    #region ICloneable Members
134
135    public object Clone() {
136      throw new NotImplementedException();
137    }
138
139    #endregion
140  }
141}
Note: See TracBrowser for help on using the repository browser.