opensim-development – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | eva | 1 | /* |
2 | * Copyright (c) Contributors, http://opensimulator.org/ |
||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. |
||
4 | * |
||
5 | * Redistribution and use in source and binary forms, with or without |
||
6 | * modification, are permitted provided that the following conditions are met: |
||
7 | * * Redistributions of source code must retain the above copyright |
||
8 | * notice, this list of conditions and the following disclaimer. |
||
9 | * * Redistributions in binary form must reproduce the above copyright |
||
10 | * notice, this list of conditions and the following disclaimer in the |
||
11 | * documentation and/or other materials provided with the distribution. |
||
12 | * * Neither the name of the OpenSimulator Project nor the |
||
13 | * names of its contributors may be used to endorse or promote products |
||
14 | * derived from this software without specific prior written permission. |
||
15 | * |
||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY |
||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY |
||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
26 | */ |
||
27 | |||
28 | using System.Collections.Generic; |
||
29 | using NUnit.Framework; |
||
30 | using OpenSim.Tests.Common; |
||
31 | using OpenSim.Region.ScriptEngine.Shared; |
||
32 | |||
33 | namespace OpenSim.Region.ScriptEngine.Shared.Tests |
||
34 | { |
||
35 | [TestFixture] |
||
36 | public class LSL_TypesTestLSLFloat : OpenSimTestCase |
||
37 | { |
||
38 | // Used for testing equality of two floats. |
||
39 | private double _lowPrecisionTolerance = 0.000001; |
||
40 | |||
41 | private Dictionary<int, double> m_intDoubleSet; |
||
42 | private Dictionary<double, double> m_doubleDoubleSet; |
||
43 | private Dictionary<double, int> m_doubleIntSet; |
||
44 | private Dictionary<double, int> m_doubleUintSet; |
||
45 | private Dictionary<string, double> m_stringDoubleSet; |
||
46 | private Dictionary<double, string> m_doubleStringSet; |
||
47 | private List<int> m_intList; |
||
48 | private List<double> m_doubleList; |
||
49 | |||
50 | /// <summary> |
||
51 | /// Sets up dictionaries and arrays used in the tests. |
||
52 | /// </summary> |
||
53 | [TestFixtureSetUp] |
||
54 | public void SetUpDataSets() |
||
55 | { |
||
56 | m_intDoubleSet = new Dictionary<int, double>(); |
||
57 | m_intDoubleSet.Add(2, 2.0); |
||
58 | m_intDoubleSet.Add(-2, -2.0); |
||
59 | m_intDoubleSet.Add(0, 0.0); |
||
60 | m_intDoubleSet.Add(1, 1.0); |
||
61 | m_intDoubleSet.Add(-1, -1.0); |
||
62 | m_intDoubleSet.Add(999999999, 999999999.0); |
||
63 | m_intDoubleSet.Add(-99999999, -99999999.0); |
||
64 | |||
65 | m_doubleDoubleSet = new Dictionary<double, double>(); |
||
66 | m_doubleDoubleSet.Add(2.0, 2.0); |
||
67 | m_doubleDoubleSet.Add(-2.0, -2.0); |
||
68 | m_doubleDoubleSet.Add(0.0, 0.0); |
||
69 | m_doubleDoubleSet.Add(1.0, 1.0); |
||
70 | m_doubleDoubleSet.Add(-1.0, -1.0); |
||
71 | m_doubleDoubleSet.Add(999999999.0, 999999999.0); |
||
72 | m_doubleDoubleSet.Add(-99999999.0, -99999999.0); |
||
73 | m_doubleDoubleSet.Add(0.5, 0.5); |
||
74 | m_doubleDoubleSet.Add(0.0005, 0.0005); |
||
75 | m_doubleDoubleSet.Add(0.6805, 0.6805); |
||
76 | m_doubleDoubleSet.Add(-0.5, -0.5); |
||
77 | m_doubleDoubleSet.Add(-0.0005, -0.0005); |
||
78 | m_doubleDoubleSet.Add(-0.6805, -0.6805); |
||
79 | m_doubleDoubleSet.Add(548.5, 548.5); |
||
80 | m_doubleDoubleSet.Add(2.0005, 2.0005); |
||
81 | m_doubleDoubleSet.Add(349485435.6805, 349485435.6805); |
||
82 | m_doubleDoubleSet.Add(-548.5, -548.5); |
||
83 | m_doubleDoubleSet.Add(-2.0005, -2.0005); |
||
84 | m_doubleDoubleSet.Add(-349485435.6805, -349485435.6805); |
||
85 | |||
86 | m_doubleIntSet = new Dictionary<double, int>(); |
||
87 | m_doubleIntSet.Add(2.0, 2); |
||
88 | m_doubleIntSet.Add(-2.0, -2); |
||
89 | m_doubleIntSet.Add(0.0, 0); |
||
90 | m_doubleIntSet.Add(1.0, 1); |
||
91 | m_doubleIntSet.Add(-1.0, -1); |
||
92 | m_doubleIntSet.Add(999999999.0, 999999999); |
||
93 | m_doubleIntSet.Add(-99999999.0, -99999999); |
||
94 | m_doubleIntSet.Add(0.5, 0); |
||
95 | m_doubleIntSet.Add(0.0005, 0); |
||
96 | m_doubleIntSet.Add(0.6805, 0); |
||
97 | m_doubleIntSet.Add(-0.5, 0); |
||
98 | m_doubleIntSet.Add(-0.0005, 0); |
||
99 | m_doubleIntSet.Add(-0.6805, 0); |
||
100 | m_doubleIntSet.Add(548.5, 548); |
||
101 | m_doubleIntSet.Add(2.0005, 2); |
||
102 | m_doubleIntSet.Add(349485435.6805, 349485435); |
||
103 | m_doubleIntSet.Add(-548.5, -548); |
||
104 | m_doubleIntSet.Add(-2.0005, -2); |
||
105 | m_doubleIntSet.Add(-349485435.6805, -349485435); |
||
106 | |||
107 | m_doubleUintSet = new Dictionary<double, int>(); |
||
108 | m_doubleUintSet.Add(2.0, 2); |
||
109 | m_doubleUintSet.Add(-2.0, 2); |
||
110 | m_doubleUintSet.Add(0.0, 0); |
||
111 | m_doubleUintSet.Add(1.0, 1); |
||
112 | m_doubleUintSet.Add(-1.0, 1); |
||
113 | m_doubleUintSet.Add(999999999.0, 999999999); |
||
114 | m_doubleUintSet.Add(-99999999.0, 99999999); |
||
115 | m_doubleUintSet.Add(0.5, 0); |
||
116 | m_doubleUintSet.Add(0.0005, 0); |
||
117 | m_doubleUintSet.Add(0.6805, 0); |
||
118 | m_doubleUintSet.Add(-0.5, 0); |
||
119 | m_doubleUintSet.Add(-0.0005, 0); |
||
120 | m_doubleUintSet.Add(-0.6805, 0); |
||
121 | m_doubleUintSet.Add(548.5, 548); |
||
122 | m_doubleUintSet.Add(2.0005, 2); |
||
123 | m_doubleUintSet.Add(349485435.6805, 349485435); |
||
124 | m_doubleUintSet.Add(-548.5, 548); |
||
125 | m_doubleUintSet.Add(-2.0005, 2); |
||
126 | m_doubleUintSet.Add(-349485435.6805, 349485435); |
||
127 | |||
128 | m_stringDoubleSet = new Dictionary<string, double>(); |
||
129 | m_stringDoubleSet.Add("2", 2.0); |
||
130 | m_stringDoubleSet.Add("-2", -2.0); |
||
131 | m_stringDoubleSet.Add("1", 1.0); |
||
132 | m_stringDoubleSet.Add("-1", -1.0); |
||
133 | m_stringDoubleSet.Add("0", 0.0); |
||
134 | m_stringDoubleSet.Add("999999999.0", 999999999.0); |
||
135 | m_stringDoubleSet.Add("-99999999.0", -99999999.0); |
||
136 | m_stringDoubleSet.Add("0.5", 0.5); |
||
137 | m_stringDoubleSet.Add("0.0005", 0.0005); |
||
138 | m_stringDoubleSet.Add("0.6805", 0.6805); |
||
139 | m_stringDoubleSet.Add("-0.5", -0.5); |
||
140 | m_stringDoubleSet.Add("-0.0005", -0.0005); |
||
141 | m_stringDoubleSet.Add("-0.6805", -0.6805); |
||
142 | m_stringDoubleSet.Add("548.5", 548.5); |
||
143 | m_stringDoubleSet.Add("2.0005", 2.0005); |
||
144 | m_stringDoubleSet.Add("349485435.6805", 349485435.6805); |
||
145 | m_stringDoubleSet.Add("-548.5", -548.5); |
||
146 | m_stringDoubleSet.Add("-2.0005", -2.0005); |
||
147 | m_stringDoubleSet.Add("-349485435.6805", -349485435.6805); |
||
148 | // some oddball combinations and exponents |
||
149 | m_stringDoubleSet.Add("", 0.0); |
||
150 | m_stringDoubleSet.Add("1.0E+5", 100000.0); |
||
151 | m_stringDoubleSet.Add("-1.0E+5", -100000.0); |
||
152 | m_stringDoubleSet.Add("-1E+5", -100000.0); |
||
153 | m_stringDoubleSet.Add("-1.E+5", -100000.0); |
||
154 | m_stringDoubleSet.Add("-1.E+5.0", -100000.0); |
||
155 | m_stringDoubleSet.Add("1ef", 1.0); |
||
156 | m_stringDoubleSet.Add("e10", 0.0); |
||
157 | m_stringDoubleSet.Add("1.e0.0", 1.0); |
||
158 | |||
159 | m_doubleStringSet = new Dictionary<double, string>(); |
||
160 | m_doubleStringSet.Add(2.0, "2.000000"); |
||
161 | m_doubleStringSet.Add(-2.0, "-2.000000"); |
||
162 | m_doubleStringSet.Add(1.0, "1.000000"); |
||
163 | m_doubleStringSet.Add(-1.0, "-1.000000"); |
||
164 | m_doubleStringSet.Add(0.0, "0.000000"); |
||
165 | m_doubleStringSet.Add(999999999.0, "999999999.000000"); |
||
166 | m_doubleStringSet.Add(-99999999.0, "-99999999.000000"); |
||
167 | m_doubleStringSet.Add(0.5, "0.500000"); |
||
168 | m_doubleStringSet.Add(0.0005, "0.000500"); |
||
169 | m_doubleStringSet.Add(0.6805, "0.680500"); |
||
170 | m_doubleStringSet.Add(-0.5, "-0.500000"); |
||
171 | m_doubleStringSet.Add(-0.0005, "-0.000500"); |
||
172 | m_doubleStringSet.Add(-0.6805, "-0.680500"); |
||
173 | m_doubleStringSet.Add(548.5, "548.500000"); |
||
174 | m_doubleStringSet.Add(2.0005, "2.000500"); |
||
175 | m_doubleStringSet.Add(349485435.6805, "349485435.680500"); |
||
176 | m_doubleStringSet.Add(-548.5, "-548.500000"); |
||
177 | m_doubleStringSet.Add(-2.0005, "-2.000500"); |
||
178 | m_doubleStringSet.Add(-349485435.6805, "-349485435.680500"); |
||
179 | |||
180 | m_doubleList = new List<double>(); |
||
181 | m_doubleList.Add(2.0); |
||
182 | m_doubleList.Add(-2.0); |
||
183 | m_doubleList.Add(1.0); |
||
184 | m_doubleList.Add(-1.0); |
||
185 | m_doubleList.Add(999999999.0); |
||
186 | m_doubleList.Add(-99999999.0); |
||
187 | m_doubleList.Add(0.5); |
||
188 | m_doubleList.Add(0.0005); |
||
189 | m_doubleList.Add(0.6805); |
||
190 | m_doubleList.Add(-0.5); |
||
191 | m_doubleList.Add(-0.0005); |
||
192 | m_doubleList.Add(-0.6805); |
||
193 | m_doubleList.Add(548.5); |
||
194 | m_doubleList.Add(2.0005); |
||
195 | m_doubleList.Add(349485435.6805); |
||
196 | m_doubleList.Add(-548.5); |
||
197 | m_doubleList.Add(-2.0005); |
||
198 | m_doubleList.Add(-349485435.6805); |
||
199 | |||
200 | m_intList = new List<int>(); |
||
201 | m_intList.Add(2); |
||
202 | m_intList.Add(-2); |
||
203 | m_intList.Add(0); |
||
204 | m_intList.Add(1); |
||
205 | m_intList.Add(-1); |
||
206 | m_intList.Add(999999999); |
||
207 | m_intList.Add(-99999999); |
||
208 | } |
||
209 | |||
210 | /// <summary> |
||
211 | /// Tests constructing a LSLFloat from an integer. |
||
212 | /// </summary> |
||
213 | [Test] |
||
214 | public void TestConstructFromInt() |
||
215 | { |
||
216 | TestHelpers.InMethod(); |
||
217 | |||
218 | LSL_Types.LSLFloat testFloat; |
||
219 | |||
220 | foreach (KeyValuePair<int, double> number in m_intDoubleSet) |
||
221 | { |
||
222 | testFloat = new LSL_Types.LSLFloat(number.Key); |
||
223 | Assert.That(testFloat.value, new DoubleToleranceConstraint(number.Value, _lowPrecisionTolerance)); |
||
224 | } |
||
225 | } |
||
226 | |||
227 | /// <summary> |
||
228 | /// Tests constructing a LSLFloat from a double. |
||
229 | /// </summary> |
||
230 | [Test] |
||
231 | public void TestConstructFromDouble() |
||
232 | { |
||
233 | TestHelpers.InMethod(); |
||
234 | |||
235 | LSL_Types.LSLFloat testFloat; |
||
236 | |||
237 | foreach (KeyValuePair<double, double> number in m_doubleDoubleSet) |
||
238 | { |
||
239 | testFloat = new LSL_Types.LSLFloat(number.Key); |
||
240 | Assert.That(testFloat.value, new DoubleToleranceConstraint(number.Value, _lowPrecisionTolerance)); |
||
241 | } |
||
242 | } |
||
243 | |||
244 | /// <summary> |
||
245 | /// Tests LSLFloat is correctly cast explicitly to integer. |
||
246 | /// </summary> |
||
247 | [Test] |
||
248 | public void TestExplicitCastLSLFloatToInt() |
||
249 | { |
||
250 | TestHelpers.InMethod(); |
||
251 | |||
252 | int testNumber; |
||
253 | |||
254 | foreach (KeyValuePair<double, int> number in m_doubleIntSet) |
||
255 | { |
||
256 | testNumber = (int) new LSL_Types.LSLFloat(number.Key); |
||
257 | Assert.AreEqual(number.Value, testNumber, "Converting double " + number.Key + ", expecting int " + number.Value); |
||
258 | } |
||
259 | } |
||
260 | |||
261 | /// <summary> |
||
262 | /// Tests LSLFloat is correctly cast explicitly to unsigned integer. |
||
263 | /// </summary> |
||
264 | [Test] |
||
265 | public void TestExplicitCastLSLFloatToUint() |
||
266 | { |
||
267 | TestHelpers.InMethod(); |
||
268 | |||
269 | uint testNumber; |
||
270 | |||
271 | foreach (KeyValuePair<double, int> number in m_doubleUintSet) |
||
272 | { |
||
273 | testNumber = (uint) new LSL_Types.LSLFloat(number.Key); |
||
274 | Assert.AreEqual(number.Value, testNumber, "Converting double " + number.Key + ", expecting uint " + number.Value); |
||
275 | } |
||
276 | } |
||
277 | |||
278 | /// <summary> |
||
279 | /// Tests LSLFloat is correctly cast implicitly to Boolean if non-zero. |
||
280 | /// </summary> |
||
281 | [Test] |
||
282 | public void TestImplicitCastLSLFloatToBooleanTrue() |
||
283 | { |
||
284 | TestHelpers.InMethod(); |
||
285 | |||
286 | LSL_Types.LSLFloat testFloat; |
||
287 | bool testBool; |
||
288 | |||
289 | foreach (double number in m_doubleList) |
||
290 | { |
||
291 | testFloat = new LSL_Types.LSLFloat(number); |
||
292 | testBool = testFloat; |
||
293 | |||
294 | Assert.IsTrue(testBool); |
||
295 | } |
||
296 | } |
||
297 | |||
298 | /// <summary> |
||
299 | /// Tests LSLFloat is correctly cast implicitly to Boolean if zero. |
||
300 | /// </summary> |
||
301 | [Test] |
||
302 | public void TestImplicitCastLSLFloatToBooleanFalse() |
||
303 | { |
||
304 | TestHelpers.InMethod(); |
||
305 | |||
306 | LSL_Types.LSLFloat testFloat = new LSL_Types.LSLFloat(0.0); |
||
307 | bool testBool = testFloat; |
||
308 | |||
309 | Assert.IsFalse(testBool); |
||
310 | } |
||
311 | |||
312 | /// <summary> |
||
313 | /// Tests integer is correctly cast implicitly to LSLFloat. |
||
314 | /// </summary> |
||
315 | [Test] |
||
316 | public void TestImplicitCastIntToLSLFloat() |
||
317 | { |
||
318 | TestHelpers.InMethod(); |
||
319 | |||
320 | LSL_Types.LSLFloat testFloat; |
||
321 | |||
322 | foreach (int number in m_intList) |
||
323 | { |
||
324 | testFloat = number; |
||
325 | Assert.That(testFloat.value, new DoubleToleranceConstraint(number, _lowPrecisionTolerance)); |
||
326 | } |
||
327 | } |
||
328 | |||
329 | /// <summary> |
||
330 | /// Tests LSLInteger is correctly cast implicitly to LSLFloat. |
||
331 | /// </summary> |
||
332 | [Test] |
||
333 | public void TestImplicitCastLSLIntegerToLSLFloat() |
||
334 | { |
||
335 | TestHelpers.InMethod(); |
||
336 | |||
337 | LSL_Types.LSLFloat testFloat; |
||
338 | |||
339 | foreach (int number in m_intList) |
||
340 | { |
||
341 | testFloat = new LSL_Types.LSLInteger(number); |
||
342 | Assert.That(testFloat.value, new DoubleToleranceConstraint(number, _lowPrecisionTolerance)); |
||
343 | } |
||
344 | } |
||
345 | |||
346 | /// <summary> |
||
347 | /// Tests LSLInteger is correctly cast explicitly to LSLFloat. |
||
348 | /// </summary> |
||
349 | [Test] |
||
350 | public void TestExplicitCastLSLIntegerToLSLFloat() |
||
351 | { |
||
352 | TestHelpers.InMethod(); |
||
353 | |||
354 | LSL_Types.LSLFloat testFloat; |
||
355 | |||
356 | foreach (int number in m_intList) |
||
357 | { |
||
358 | testFloat = (LSL_Types.LSLFloat) new LSL_Types.LSLInteger(number); |
||
359 | Assert.That(testFloat.value, new DoubleToleranceConstraint(number, _lowPrecisionTolerance)); |
||
360 | } |
||
361 | } |
||
362 | |||
363 | /// <summary> |
||
364 | /// Tests string is correctly cast explicitly to LSLFloat. |
||
365 | /// </summary> |
||
366 | [Test] |
||
367 | public void TestExplicitCastStringToLSLFloat() |
||
368 | { |
||
369 | TestHelpers.InMethod(); |
||
370 | |||
371 | LSL_Types.LSLFloat testFloat; |
||
372 | |||
373 | foreach (KeyValuePair<string, double> number in m_stringDoubleSet) |
||
374 | { |
||
375 | testFloat = (LSL_Types.LSLFloat) number.Key; |
||
376 | Assert.That(testFloat.value, new DoubleToleranceConstraint(number.Value, _lowPrecisionTolerance)); |
||
377 | } |
||
378 | } |
||
379 | |||
380 | /// <summary> |
||
381 | /// Tests LSLString is correctly cast implicitly to LSLFloat. |
||
382 | /// </summary> |
||
383 | [Test] |
||
384 | public void TestExplicitCastLSLStringToLSLFloat() |
||
385 | { |
||
386 | TestHelpers.InMethod(); |
||
387 | |||
388 | LSL_Types.LSLFloat testFloat; |
||
389 | |||
390 | foreach (KeyValuePair<string, double> number in m_stringDoubleSet) |
||
391 | { |
||
392 | testFloat = (LSL_Types.LSLFloat) new LSL_Types.LSLString(number.Key); |
||
393 | Assert.That(testFloat.value, new DoubleToleranceConstraint(number.Value, _lowPrecisionTolerance)); |
||
394 | } |
||
395 | } |
||
396 | |||
397 | /// <summary> |
||
398 | /// Tests double is correctly cast implicitly to LSLFloat. |
||
399 | /// </summary> |
||
400 | [Test] |
||
401 | public void TestImplicitCastDoubleToLSLFloat() |
||
402 | { |
||
403 | TestHelpers.InMethod(); |
||
404 | |||
405 | LSL_Types.LSLFloat testFloat; |
||
406 | |||
407 | foreach (double number in m_doubleList) |
||
408 | { |
||
409 | testFloat = number; |
||
410 | Assert.That(testFloat.value, new DoubleToleranceConstraint(number, _lowPrecisionTolerance)); |
||
411 | } |
||
412 | } |
||
413 | |||
414 | /// <summary> |
||
415 | /// Tests LSLFloat is correctly cast implicitly to double. |
||
416 | /// </summary> |
||
417 | [Test] |
||
418 | public void TestImplicitCastLSLFloatToDouble() |
||
419 | { |
||
420 | TestHelpers.InMethod(); |
||
421 | |||
422 | double testNumber; |
||
423 | LSL_Types.LSLFloat testFloat; |
||
424 | |||
425 | foreach (double number in m_doubleList) |
||
426 | { |
||
427 | testFloat = new LSL_Types.LSLFloat(number); |
||
428 | testNumber = testFloat; |
||
429 | |||
430 | Assert.That(testNumber, new DoubleToleranceConstraint(number, _lowPrecisionTolerance)); |
||
431 | } |
||
432 | } |
||
433 | |||
434 | /// <summary> |
||
435 | /// Tests LSLFloat is correctly cast explicitly to float |
||
436 | /// </summary> |
||
437 | [Test] |
||
438 | public void TestExplicitCastLSLFloatToFloat() |
||
439 | { |
||
440 | TestHelpers.InMethod(); |
||
441 | |||
442 | float testFloat; |
||
443 | float numberAsFloat; |
||
444 | LSL_Types.LSLFloat testLSLFloat; |
||
445 | |||
446 | foreach (double number in m_doubleList) |
||
447 | { |
||
448 | testLSLFloat = new LSL_Types.LSLFloat(number); |
||
449 | numberAsFloat = (float)number; |
||
450 | testFloat = (float)testLSLFloat; |
||
451 | |||
452 | Assert.That((double)testFloat, new DoubleToleranceConstraint((double)numberAsFloat, _lowPrecisionTolerance)); |
||
453 | } |
||
454 | } |
||
455 | |||
456 | /// <summary> |
||
457 | /// Tests the equality (==) operator. |
||
458 | /// </summary> |
||
459 | [Test] |
||
460 | public void TestEqualsOperator() |
||
461 | { |
||
462 | TestHelpers.InMethod(); |
||
463 | |||
464 | LSL_Types.LSLFloat testFloatA, testFloatB; |
||
465 | |||
466 | foreach (double number in m_doubleList) |
||
467 | { |
||
468 | testFloatA = new LSL_Types.LSLFloat(number); |
||
469 | testFloatB = new LSL_Types.LSLFloat(number); |
||
470 | Assert.IsTrue(testFloatA == testFloatB); |
||
471 | |||
472 | testFloatB = new LSL_Types.LSLFloat(number + 1.0); |
||
473 | Assert.IsFalse(testFloatA == testFloatB); |
||
474 | } |
||
475 | } |
||
476 | |||
477 | /// <summary> |
||
478 | /// Tests the inequality (!=) operator. |
||
479 | /// </summary> |
||
480 | [Test] |
||
481 | public void TestNotEqualOperator() |
||
482 | { |
||
483 | TestHelpers.InMethod(); |
||
484 | |||
485 | LSL_Types.LSLFloat testFloatA, testFloatB; |
||
486 | |||
487 | foreach (double number in m_doubleList) |
||
488 | { |
||
489 | testFloatA = new LSL_Types.LSLFloat(number); |
||
490 | testFloatB = new LSL_Types.LSLFloat(number + 1.0); |
||
491 | Assert.IsTrue(testFloatA != testFloatB); |
||
492 | |||
493 | testFloatB = new LSL_Types.LSLFloat(number); |
||
494 | Assert.IsFalse(testFloatA != testFloatB); |
||
495 | } |
||
496 | } |
||
497 | |||
498 | /// <summary> |
||
499 | /// Tests the increment operator. |
||
500 | /// </summary> |
||
501 | [Test] |
||
502 | public void TestIncrementOperator() |
||
503 | { |
||
504 | TestHelpers.InMethod(); |
||
505 | |||
506 | LSL_Types.LSLFloat testFloat; |
||
507 | double testNumber; |
||
508 | |||
509 | foreach (double number in m_doubleList) |
||
510 | { |
||
511 | testFloat = new LSL_Types.LSLFloat(number); |
||
512 | |||
513 | testNumber = testFloat++; |
||
514 | Assert.That(testNumber, new DoubleToleranceConstraint(number, _lowPrecisionTolerance)); |
||
515 | |||
516 | testNumber = testFloat; |
||
517 | Assert.That(testNumber, new DoubleToleranceConstraint(number + 1.0, _lowPrecisionTolerance)); |
||
518 | |||
519 | testNumber = ++testFloat; |
||
520 | Assert.That(testNumber, new DoubleToleranceConstraint(number + 2.0, _lowPrecisionTolerance)); |
||
521 | } |
||
522 | } |
||
523 | |||
524 | /// <summary> |
||
525 | /// Tests the decrement operator. |
||
526 | /// </summary> |
||
527 | [Test] |
||
528 | public void TestDecrementOperator() |
||
529 | { |
||
530 | TestHelpers.InMethod(); |
||
531 | |||
532 | LSL_Types.LSLFloat testFloat; |
||
533 | double testNumber; |
||
534 | |||
535 | foreach (double number in m_doubleList) |
||
536 | { |
||
537 | testFloat = new LSL_Types.LSLFloat(number); |
||
538 | |||
539 | testNumber = testFloat--; |
||
540 | Assert.That(testNumber, new DoubleToleranceConstraint(number, _lowPrecisionTolerance)); |
||
541 | |||
542 | testNumber = testFloat; |
||
543 | Assert.That(testNumber, new DoubleToleranceConstraint(number - 1.0, _lowPrecisionTolerance)); |
||
544 | |||
545 | testNumber = --testFloat; |
||
546 | Assert.That(testNumber, new DoubleToleranceConstraint(number - 2.0, _lowPrecisionTolerance)); |
||
547 | } |
||
548 | } |
||
549 | |||
550 | /// <summary> |
||
551 | /// Tests LSLFloat.ToString(). |
||
552 | /// </summary> |
||
553 | [Test] |
||
554 | public void TestToString() |
||
555 | { |
||
556 | TestHelpers.InMethod(); |
||
557 | |||
558 | LSL_Types.LSLFloat testFloat; |
||
559 | |||
560 | foreach (KeyValuePair<double, string> number in m_doubleStringSet) |
||
561 | { |
||
562 | testFloat = new LSL_Types.LSLFloat(number.Key); |
||
563 | Assert.AreEqual(number.Value, testFloat.ToString()); |
||
564 | } |
||
565 | } |
||
566 | |||
567 | /// <summary> |
||
568 | /// Tests addition of two LSLFloats. |
||
569 | /// </summary> |
||
570 | [Test] |
||
571 | public void TestAddTwoLSLFloats() |
||
572 | { |
||
573 | TestHelpers.InMethod(); |
||
574 | |||
575 | LSL_Types.LSLFloat testResult; |
||
576 | |||
577 | foreach (KeyValuePair<double, double> number in m_doubleDoubleSet) |
||
578 | { |
||
579 | testResult = new LSL_Types.LSLFloat(number.Key) + new LSL_Types.LSLFloat(number.Value); |
||
580 | Assert.That(testResult.value, new DoubleToleranceConstraint(number.Key + number.Value, _lowPrecisionTolerance)); |
||
581 | } |
||
582 | } |
||
583 | |||
584 | /// <summary> |
||
585 | /// Tests subtraction of two LSLFloats. |
||
586 | /// </summary> |
||
587 | [Test] |
||
588 | public void TestSubtractTwoLSLFloats() |
||
589 | { |
||
590 | TestHelpers.InMethod(); |
||
591 | |||
592 | LSL_Types.LSLFloat testResult; |
||
593 | |||
594 | foreach (KeyValuePair<double, double> number in m_doubleDoubleSet) |
||
595 | { |
||
596 | testResult = new LSL_Types.LSLFloat(number.Key) - new LSL_Types.LSLFloat(number.Value); |
||
597 | Assert.That(testResult.value, new DoubleToleranceConstraint(number.Key - number.Value, _lowPrecisionTolerance)); |
||
598 | } |
||
599 | } |
||
600 | |||
601 | /// <summary> |
||
602 | /// Tests multiplication of two LSLFloats. |
||
603 | /// </summary> |
||
604 | [Test] |
||
605 | public void TestMultiplyTwoLSLFloats() |
||
606 | { |
||
607 | TestHelpers.InMethod(); |
||
608 | |||
609 | LSL_Types.LSLFloat testResult; |
||
610 | |||
611 | foreach (KeyValuePair<double, double> number in m_doubleDoubleSet) |
||
612 | { |
||
613 | testResult = new LSL_Types.LSLFloat(number.Key) * new LSL_Types.LSLFloat(number.Value); |
||
614 | Assert.That(testResult.value, new DoubleToleranceConstraint(number.Key * number.Value, _lowPrecisionTolerance)); |
||
615 | } |
||
616 | } |
||
617 | |||
618 | /// <summary> |
||
619 | /// Tests division of two LSLFloats. |
||
620 | /// </summary> |
||
621 | [Test] |
||
622 | public void TestDivideTwoLSLFloats() |
||
623 | { |
||
624 | TestHelpers.InMethod(); |
||
625 | |||
626 | LSL_Types.LSLFloat testResult; |
||
627 | |||
628 | foreach (KeyValuePair<double, double> number in m_doubleDoubleSet) |
||
629 | { |
||
630 | if (number.Value != 0.0) // Let's avoid divide by zero. |
||
631 | { |
||
632 | testResult = new LSL_Types.LSLFloat(number.Key) / new LSL_Types.LSLFloat(number.Value); |
||
633 | Assert.That(testResult.value, new DoubleToleranceConstraint(number.Key / number.Value, _lowPrecisionTolerance)); |
||
634 | } |
||
635 | } |
||
636 | } |
||
637 | |||
638 | /// <summary> |
||
639 | /// Tests boolean correctly cast implicitly to LSLFloat. |
||
640 | /// </summary> |
||
641 | [Test] |
||
642 | public void TestImplicitCastBooleanToLSLFloat() |
||
643 | { |
||
644 | TestHelpers.InMethod(); |
||
645 | |||
646 | LSL_Types.LSLFloat testFloat; |
||
647 | |||
648 | testFloat = (1 == 0); |
||
649 | Assert.That(testFloat.value, new DoubleToleranceConstraint(0.0, _lowPrecisionTolerance)); |
||
650 | |||
651 | testFloat = (1 == 1); |
||
652 | Assert.That(testFloat.value, new DoubleToleranceConstraint(1.0, _lowPrecisionTolerance)); |
||
653 | |||
654 | testFloat = false; |
||
655 | Assert.That(testFloat.value, new DoubleToleranceConstraint(0.0, _lowPrecisionTolerance)); |
||
656 | |||
657 | testFloat = true; |
||
658 | Assert.That(testFloat.value, new DoubleToleranceConstraint(1.0, _lowPrecisionTolerance)); |
||
659 | } |
||
660 | } |
||
661 | } |