Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3.2/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Tests/TestRandom.cs @ 3580

Last change on this file since 3580 was 3483, checked in by swagner, 15 years ago

Worked on the refactoring of saving and loading items (#990)

File size: 4.9 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.Common;
24using HeuristicLab.Core;
25
26namespace HeuristicLab.Encodings.RealVectorEncoding_33.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 System.Drawing.Image ItemImage {
112      get { throw new NotImplementedException(); }
113    }
114
115#pragma warning disable 67
116    public event EventHandler ItemImageChanged;
117    public event EventHandler ToStringChanged;
118#pragma warning restore 67
119    #endregion
120
121    #region IDeepCloneable Members
122
123    public IDeepCloneable Clone(Cloner cloner) {
124      throw new NotImplementedException();
125    }
126
127    #endregion
128
129    #region ICloneable Members
130
131    public object Clone() {
132      throw new NotImplementedException();
133    }
134
135    #endregion
136
137    #region IStorableContent Members
138
139    public string Filename {
140      get { throw new NotImplementedException(); }
141      set { throw new NotImplementedException(); }
142    }
143
144#pragma warning disable 67
145    public event EventHandler FilenameChanged;
146#pragma warning restore 67
147
148    #endregion
149  }
150}
Note: See TracBrowser for help on using the repository browser.