Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Tests/TestRandom.cs @ 3051

Last change on this file since 3051 was 2932, checked in by swagner, 15 years ago

Operator architecture refactoring (#95)

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