[NUI] Rebase develnui (DevelNUI only patches --> master) (#3910)
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Devel.Tests.Ubuntu / nunit.framework / Attributes / RangeAttribute.cs
1 // ***********************************************************************
2 // Copyright (c) 2008-2015 Charlie Poole
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining
5 // a copy of this software and associated documentation files (the
6 // "Software"), to deal in the Software without restriction, including
7 // without limitation the rights to use, copy, modify, merge, publish,
8 // distribute, sublicense, and/or sell copies of the Software, and to
9 // permit persons to whom the Software is furnished to do so, subject to
10 // the following conditions:
11 // 
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
14 // 
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 // ***********************************************************************
23 #define PORTABLE
24 #define TIZEN
25 #define NUNIT_FRAMEWORK
26 #define NUNITLITE
27 #define NET_4_5
28 #define PARALLEL
29 using System;
30 using System.Collections;
31
32 namespace NUnit.Framework
33 {
34     /// <summary>
35     /// RangeAttribute is used to supply a range of _values to an
36     /// individual parameter of a parameterized test.
37     /// </summary>
38     public class RangeAttribute : ValuesAttribute
39     {
40         #region Ints
41
42         /// <summary>
43         /// Construct a range of ints using default step of 1
44         /// </summary>
45         /// <param name="from"></param>
46         /// <param name="to"></param>
47         public RangeAttribute(int from, int to) : this(from, to, from > to ? -1 : 1) { }
48
49         /// <summary>
50         /// Construct a range of ints specifying the step size 
51         /// </summary>
52         /// <param name="from"></param>
53         /// <param name="to"></param>
54         /// <param name="step"></param>
55         public RangeAttribute(int from, int to, int step)
56         {
57             Guard.ArgumentValid(step > 0 && to >= from || step < 0 && to <= from,
58                 "Step must be positive with to >= from or negative with to <= from", "step");
59
60             int count = (to - from) / step + 1;
61             this.data = new object[count];
62             int index = 0;
63             for (int val = from; index < count; val += step)
64                 this.data[index++] = val;
65         }
66
67         #endregion
68
69         #region Unsigned Ints
70
71         /// <summary>
72         /// Construct a range of unsigned ints using default step of 1
73         /// </summary>
74         /// <param name="from"></param>
75         /// <param name="to"></param>
76         //[CLSCompliant(false)]
77         public RangeAttribute(uint from, uint to) : this(from, to, 1u) { }
78
79         /// <summary>
80         /// Construct a range of unsigned ints specifying the step size 
81         /// </summary>
82         /// <param name="from"></param>
83         /// <param name="to"></param>
84         /// <param name="step"></param>
85         //[CLSCompliant(false)]
86         public RangeAttribute(uint from, uint to, uint step)
87         {
88             Guard.ArgumentValid(step > 0, "Step must be greater than zero", "step");
89             Guard.ArgumentValid(to >= from, "Value of to must be greater than or equal to from", "to");
90
91             uint count = (to - from) / step + 1;
92             this.data = new object[count];
93             uint index = 0;
94             for (uint val = from; index < count; val += step)
95                 this.data[index++] = val;
96         }
97
98         #endregion
99
100         #region Longs
101
102         /// <summary>
103         /// Construct a range of longs using a default step of 1
104         /// </summary>
105         /// <param name="from"></param>
106         /// <param name="to"></param>
107         public RangeAttribute(long from, long to) : this(from, to, from > to ? -1L : 1L) { }
108
109         /// <summary>
110         /// Construct a range of longs
111         /// </summary>
112         /// <param name="from"></param>
113         /// <param name="to"></param>
114         /// <param name="step"></param>
115         public RangeAttribute(long from, long to, long step)
116         {
117             Guard.ArgumentValid(step > 0L && to >= from || step < 0L && to <= from,
118                 "Step must be positive with to >= from or negative with to <= from", "step");
119
120             long count = (to - from) / step + 1;
121             this.data = new object[count];
122             int index = 0;
123             for (long val = from; index < count; val += step)
124                 this.data[index++] = val;
125         }
126
127         #endregion
128
129         #region Unsigned Longs
130
131         /// <summary>
132         /// Construct a range of unsigned longs using default step of 1
133         /// </summary>
134         /// <param name="from"></param>
135         /// <param name="to"></param>
136         //[CLSCompliant(false)]
137         public RangeAttribute(ulong from, ulong to) : this(from, to, 1ul) { }
138
139         /// <summary>
140         /// Construct a range of unsigned longs specifying the step size 
141         /// </summary>
142         /// <param name="from"></param>
143         /// <param name="to"></param>
144         /// <param name="step"></param>
145         //[CLSCompliant(false)]
146         public RangeAttribute(ulong from, ulong to, ulong step)
147         {
148             Guard.ArgumentValid(step > 0, "Step must be greater than zero", "step");
149             Guard.ArgumentValid(to >= from, "Value of to must be greater than or equal to from", "to");
150
151             ulong count = (to - from) / step + 1;
152             this.data = new object[count];
153             ulong index = 0;
154             for (ulong val = from; index < count; val += step)
155                 this.data[index++] = val;
156         }
157
158         #endregion
159
160         #region Doubles
161
162         /// <summary>
163         /// Construct a range of doubles
164         /// </summary>
165         /// <param name="from"></param>
166         /// <param name="to"></param>
167         /// <param name="step"></param>
168         public RangeAttribute(double from, double to, double step)
169         {
170             Guard.ArgumentValid(step > 0.0D && to >= from || step < 0.0D && to <= from,
171                 "Step must be positive with to >= from or negative with to <= from", "step");
172
173             double aStep = Math.Abs(step);
174             double tol = aStep / 1000;
175             int count = (int)(Math.Abs(to - from) / aStep + tol + 1);
176             this.data = new object[count];
177             int index = 0;
178             for (double val = from; index < count; val += step)
179                 this.data[index++] = val;
180         }
181
182         #endregion
183
184         #region Floats
185
186         /// <summary>
187         /// Construct a range of floats
188         /// </summary>
189         /// <param name="from"></param>
190         /// <param name="to"></param>
191         /// <param name="step"></param>
192         public RangeAttribute(float from, float to, float step)
193         {
194             Guard.ArgumentValid(step > 0.0F && to >= from || step < 0.0F && to <= from,
195                 "Step must be positive with to >= from or negative with to <= from", "step");
196
197             float aStep = Math.Abs(step);
198             float tol = aStep / 1000;
199             int count = (int)(Math.Abs(to - from) / aStep + tol + 1);
200             this.data = new object[count];
201             int index = 0;
202             for (float val = from; index < count; val += step)
203                 this.data[index++] = val;
204         }
205
206         #endregion
207     }
208 }