Free cookie consent management tool by TermsFeed Policy Generator

source: branches/Trunk/HeuristicLab.Tests/HeuristicLab.Encodings.IntegerVectorEncoding-3.3/TestRandom.cs @ 6844

Last change on this file since 6844 was 6844, checked in by mkommend, 13 years ago

#1653: Restructured unit tests.

File size: 4.7 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2011 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.IntegerVectorEncoding_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    protected TestRandom(TestRandom original, Cloner cloner) {
57    }
58
59    public TestRandom(int[] intNumbers, double[] doubleNumbers) {
60      if (intNumbers == null) intNumbers = new int[0];
61      else this.intNumbers = intNumbers;
62      if (doubleNumbers == null) doubleNumbers = new double[0];
63      else this.doubleNumbers = doubleNumbers;
64      nextIntIndex = 0;
65      nextDoubleIndex = 0;
66    }
67
68    #region IRandom Members
69
70    public void Reset() {
71      nextIntIndex = 0;
72      nextDoubleIndex = 0;
73    }
74
75    public void Reset(int seed) {
76      throw new NotImplementedException();
77    }
78
79    public int Next() {
80      if (nextIntIndex >= intNumbers.Length) throw new InvalidOperationException("Random: No more integer random numbers available");
81      return intNumbers[nextIntIndex++];
82    }
83
84    public int Next(int maxVal) {
85      if (nextIntIndex >= intNumbers.Length) throw new InvalidOperationException("Random: No more integer random numbers available");
86      if (IntNumbers[nextIntIndex] >= maxVal) throw new InvalidOperationException("Random: Next integer random number (" + IntNumbers[nextIntIndex] + ") is >= " + maxVal);
87      return intNumbers[nextIntIndex++];
88    }
89
90    public int Next(int minVal, int maxVal) {
91      if (nextIntIndex >= intNumbers.Length) throw new InvalidOperationException("Random: No more integer random numbers available");
92      if (IntNumbers[nextIntIndex] < minVal || IntNumbers[nextIntIndex] >= maxVal) throw new InvalidOperationException("Random: Next integer random number (" + IntNumbers[nextIntIndex] + ") is not in the range [" + minVal + ";" + maxVal + ")");
93      return intNumbers[nextIntIndex++];
94    }
95
96    public double NextDouble() {
97      if (nextDoubleIndex >= doubleNumbers.Length) throw new InvalidOperationException("Random: No more double random numbers available");
98      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)");
99      return doubleNumbers[nextDoubleIndex++];
100    }
101
102    #endregion
103
104    #region IItem Members
105
106    public string ItemName {
107      get { throw new NotImplementedException(); }
108    }
109
110    public string ItemDescription {
111      get { throw new NotImplementedException(); }
112    }
113
114    public Version ItemVersion {
115      get { throw new NotImplementedException(); }
116    }
117
118    public System.Drawing.Image ItemImage {
119      get { throw new NotImplementedException(); }
120    }
121
122#pragma warning disable 67
123    public event EventHandler ItemImageChanged;
124    public event EventHandler ToStringChanged;
125#pragma warning restore 67
126    #endregion
127
128    #region IDeepCloneable Members
129
130    public IDeepCloneable Clone(Cloner cloner) {
131      throw new NotImplementedException();
132    }
133
134    #endregion
135
136    #region ICloneable Members
137
138    public object Clone() {
139      throw new NotImplementedException();
140    }
141
142    #endregion
143  }
144}
Note: See TracBrowser for help on using the repository browser.