Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Permutation/3.3/Tests/Random.cs @ 2900

Last change on this file since 2900 was 2854, checked in by svonolfe, 15 years ago

Ported ported permutation operators to HL 3.3 and added test cases (#889)

File size: 4.5 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 System.Collections.Generic;
24using System.Linq;
25using System.Text;
26using HeuristicLab.Core;
27
28namespace HeuristicLab.Permutation.Tests {
29  public class TestRandom : IRandom {
30    #region Variables and Properties
31    private int[] intNumbers;
32    public int[] IntNumbers {
33      get { return intNumbers; }
34      set {
35        if (value == null) intNumbers = new int[0];
36        else intNumbers = value;
37      }
38    }
39    private int nextIntIndex;
40    private double[] doubleNumbers;
41    public double[] DoubleNumbers {
42      get { return doubleNumbers; }
43      set {
44        if (value == null) doubleNumbers = new double[0];
45        else doubleNumbers = value;
46      }
47    }
48    private int nextDoubleIndex;
49    #endregion
50
51    public TestRandom() {
52      intNumbers = new int[0];
53      doubleNumbers = new double[0];
54      nextIntIndex = 0;
55      nextDoubleIndex = 0;
56    }
57
58    public TestRandom(int[] intNumbers, double[] doubleNumbers) {
59      if (intNumbers == null) intNumbers = new int[0];
60      else this.intNumbers = intNumbers;
61      if (doubleNumbers == null) doubleNumbers = new double[0];
62      else this.doubleNumbers = doubleNumbers;
63      nextIntIndex = 0;
64      nextDoubleIndex = 0;
65    }
66
67    #region IRandom Members
68
69    public void Reset() {
70      nextIntIndex = 0;
71      nextDoubleIndex = 0;
72    }
73
74    public void Reset(int seed) {
75      throw new NotImplementedException();
76    }
77
78    public int Next() {
79      if (nextIntIndex >= intNumbers.Length) throw new InvalidOperationException("Random: No more integer random numbers available");
80      return intNumbers[nextIntIndex++];
81    }
82
83    public int Next(int maxVal) {
84      if (nextIntIndex >= intNumbers.Length) throw new InvalidOperationException("Random: No more integer random numbers available");
85      if (IntNumbers[nextIntIndex] >= maxVal) throw new InvalidOperationException("Random: Next integer random number (" + IntNumbers[nextIntIndex] + ") is >= " + maxVal);
86      return intNumbers[nextIntIndex++];
87    }
88
89    public int Next(int minVal, int maxVal) {
90      if (nextIntIndex >= intNumbers.Length) throw new InvalidOperationException("Random: No more integer random numbers available");
91      if (IntNumbers[nextIntIndex] < minVal || IntNumbers[nextIntIndex] >= maxVal) throw new InvalidOperationException("Random: Next integer random number (" + IntNumbers[nextIntIndex] + ") is not in the range [" + minVal + ";" + maxVal + ")");
92      return intNumbers[nextIntIndex++];
93    }
94
95    public double NextDouble() {
96      if (nextDoubleIndex >= doubleNumbers.Length) throw new InvalidOperationException("Random: No more double random numbers available");
97      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)");
98      return doubleNumbers[nextDoubleIndex++];
99    }
100
101    #endregion
102
103    #region IItem Members
104
105    public string ItemName {
106      get { throw new NotImplementedException(); }
107    }
108
109    public string ItemDescription {
110      get { throw new NotImplementedException(); }
111    }
112
113    public System.Drawing.Image ItemImage {
114      get { throw new NotImplementedException(); }
115    }
116
117    public event ChangedEventHandler Changed;
118
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}
Note: See TracBrowser for help on using the repository browser.