#3145: refactored infix formatter to improve output (less parenthesis) and added...
[heuristiclab.git] / HeuristicLab.Tests / TestRandom.cs
blobc86cb096ecebb31f8936a9dc25a1288a93cdb6fb
1 #region License Information
2 /* HeuristicLab
3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
5 * This file is part of HeuristicLab.
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.
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.
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/>.
20 #endregion
22 using System;
23 using System.Linq;
24 using HeuristicLab.Common;
25 using HeuristicLab.Core;
27 namespace HeuristicLab.Tests {
28 public class TestRandom : IRandom {
29 #region Variables and Properties
30 private int[] intNumbers;
31 public int[] IntNumbers {
32 get { return intNumbers; }
33 set {
34 if (value == null) intNumbers = new int[0];
35 else intNumbers = value;
38 private int nextIntIndex;
39 private double[] doubleNumbers;
40 public double[] DoubleNumbers {
41 get { return doubleNumbers; }
42 set {
43 if (value == null) doubleNumbers = new double[0];
44 else doubleNumbers = value;
47 private int nextDoubleIndex;
48 #endregion
50 public TestRandom() {
51 intNumbers = new int[0];
52 doubleNumbers = new double[0];
53 nextIntIndex = 0;
54 nextDoubleIndex = 0;
57 protected TestRandom(TestRandom original, Cloner cloner) {
58 this.intNumbers = original.intNumbers.ToArray();
59 this.doubleNumbers = original.doubleNumbers.ToArray();
62 public TestRandom(int[] intNumbers, double[] doubleNumbers) {
63 if (intNumbers == null) this.intNumbers = new int[0];
64 else this.intNumbers = intNumbers;
65 if (doubleNumbers == null) this.doubleNumbers = new double[0];
66 else this.doubleNumbers = doubleNumbers;
67 nextIntIndex = 0;
68 nextDoubleIndex = 0;
71 #region IRandom Members
73 public void Reset() {
74 nextIntIndex = 0;
75 nextDoubleIndex = 0;
78 public void Reset(int seed) {
79 throw new NotImplementedException();
82 public int Next() {
83 if (nextIntIndex >= intNumbers.Length) throw new InvalidOperationException("Random: No more integer random numbers available");
84 return intNumbers[nextIntIndex++];
87 public int Next(int maxVal) {
88 if (nextIntIndex >= intNumbers.Length) throw new InvalidOperationException("Random: No more integer random numbers available");
89 if (IntNumbers[nextIntIndex] >= maxVal) throw new InvalidOperationException("Random: Next integer random number (" + IntNumbers[nextIntIndex] + ") is >= " + maxVal);
90 return intNumbers[nextIntIndex++];
93 public int Next(int minVal, int maxVal) {
94 if (nextIntIndex >= intNumbers.Length) throw new InvalidOperationException("Random: No more integer random numbers available");
95 if (IntNumbers[nextIntIndex] < minVal || IntNumbers[nextIntIndex] >= maxVal) throw new InvalidOperationException("Random: Next integer random number (" + IntNumbers[nextIntIndex] + ") is not in the range [" + minVal + ";" + maxVal + ")");
96 return intNumbers[nextIntIndex++];
99 public double NextDouble() {
100 if (nextDoubleIndex >= doubleNumbers.Length) throw new InvalidOperationException("Random: No more double random numbers available");
101 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)");
102 return doubleNumbers[nextDoubleIndex++];
105 #endregion
107 #region IItem Members
109 public string ItemName {
110 get { throw new NotImplementedException(); }
113 public string ItemDescription {
114 get { throw new NotImplementedException(); }
117 public Version ItemVersion {
118 get { throw new NotImplementedException(); }
121 public System.Drawing.Image ItemImage {
122 get { throw new NotImplementedException(); }
125 #pragma warning disable 67
126 public event EventHandler ItemImageChanged;
127 public event EventHandler ToStringChanged;
128 #pragma warning restore 67
129 #endregion
131 #region IDeepCloneable Members
133 public IDeepCloneable Clone(Cloner cloner) {
134 return new TestRandom(this, cloner);
137 #endregion
139 #region ICloneable Members
141 public object Clone() {
142 throw new NotImplementedException();
145 #endregion