diff options
Diffstat (limited to 'OpenSim/Tests/Region/ScriptEngine/Shared/LSL_TypesTestLSLFloat.cs')
-rw-r--r-- | OpenSim/Tests/Region/ScriptEngine/Shared/LSL_TypesTestLSLFloat.cs | 603 |
1 files changed, 603 insertions, 0 deletions
diff --git a/OpenSim/Tests/Region/ScriptEngine/Shared/LSL_TypesTestLSLFloat.cs b/OpenSim/Tests/Region/ScriptEngine/Shared/LSL_TypesTestLSLFloat.cs new file mode 100644 index 0000000..272d06c --- /dev/null +++ b/OpenSim/Tests/Region/ScriptEngine/Shared/LSL_TypesTestLSLFloat.cs | |||
@@ -0,0 +1,603 @@ | |||
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 OpenSim 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 | ||
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 | |||
149 | m_doubleStringSet = new Dictionary<double, string>(); | ||
150 | m_doubleStringSet.Add(2.0, "2.000000"); | ||
151 | m_doubleStringSet.Add(-2.0, "-2.000000"); | ||
152 | m_doubleStringSet.Add(1.0, "1.000000"); | ||
153 | m_doubleStringSet.Add(-1.0, "-1.000000"); | ||
154 | m_doubleStringSet.Add(0.0, "0.000000"); | ||
155 | m_doubleStringSet.Add(999999999.0, "999999999.000000"); | ||
156 | m_doubleStringSet.Add(-99999999.0, "-99999999.000000"); | ||
157 | m_doubleStringSet.Add(0.5, "0.500000"); | ||
158 | m_doubleStringSet.Add(0.0005, "0.000500"); | ||
159 | m_doubleStringSet.Add(0.6805, "0.680500"); | ||
160 | m_doubleStringSet.Add(-0.5, "-0.500000"); | ||
161 | m_doubleStringSet.Add(-0.0005, "-0.000500"); | ||
162 | m_doubleStringSet.Add(-0.6805, "-0.680500"); | ||
163 | m_doubleStringSet.Add(548.5, "548.500000"); | ||
164 | m_doubleStringSet.Add(2.0005, "2.000500"); | ||
165 | m_doubleStringSet.Add(349485435.6805, "349485435.680500"); | ||
166 | m_doubleStringSet.Add(-548.5, "-548.500000"); | ||
167 | m_doubleStringSet.Add(-2.0005, "-2.000500"); | ||
168 | m_doubleStringSet.Add(-349485435.6805, "-349485435.680500"); | ||
169 | |||
170 | m_doubleList = new List<double>(); | ||
171 | m_doubleList.Add(2.0); | ||
172 | m_doubleList.Add(-2.0); | ||
173 | m_doubleList.Add(1.0); | ||
174 | m_doubleList.Add(-1.0); | ||
175 | m_doubleList.Add(999999999.0); | ||
176 | m_doubleList.Add(-99999999.0); | ||
177 | m_doubleList.Add(0.5); | ||
178 | m_doubleList.Add(0.0005); | ||
179 | m_doubleList.Add(0.6805); | ||
180 | m_doubleList.Add(-0.5); | ||
181 | m_doubleList.Add(-0.0005); | ||
182 | m_doubleList.Add(-0.6805); | ||
183 | m_doubleList.Add(548.5); | ||
184 | m_doubleList.Add(2.0005); | ||
185 | m_doubleList.Add(349485435.6805); | ||
186 | m_doubleList.Add(-548.5); | ||
187 | m_doubleList.Add(-2.0005); | ||
188 | m_doubleList.Add(-349485435.6805); | ||
189 | |||
190 | m_intList = new List<int>(); | ||
191 | m_intList.Add(2); | ||
192 | m_intList.Add(-2); | ||
193 | m_intList.Add(0); | ||
194 | m_intList.Add(1); | ||
195 | m_intList.Add(-1); | ||
196 | m_intList.Add(999999999); | ||
197 | m_intList.Add(-99999999); | ||
198 | } | ||
199 | |||
200 | /// <summary> | ||
201 | /// Tests constructing a LSLFloat from an integer. | ||
202 | /// </summary> | ||
203 | [Test] | ||
204 | public void TestConstructFromInt() | ||
205 | { | ||
206 | LSL_Types.LSLFloat testFloat; | ||
207 | |||
208 | foreach (KeyValuePair<int, double> number in m_intDoubleSet) | ||
209 | { | ||
210 | testFloat = new LSL_Types.LSLFloat(number.Key); | ||
211 | Assert.That(testFloat.value, new DoubleToleranceConstraint(number.Value, _lowPrecisionTolerance)); | ||
212 | } | ||
213 | } | ||
214 | |||
215 | /// <summary> | ||
216 | /// Tests constructing a LSLFloat from a double. | ||
217 | /// </summary> | ||
218 | [Test] | ||
219 | public void TestConstructFromDouble() | ||
220 | { | ||
221 | LSL_Types.LSLFloat testFloat; | ||
222 | |||
223 | foreach (KeyValuePair<double, double> number in m_doubleDoubleSet) | ||
224 | { | ||
225 | testFloat = new LSL_Types.LSLFloat(number.Key); | ||
226 | Assert.That(testFloat.value, new DoubleToleranceConstraint(number.Value, _lowPrecisionTolerance)); | ||
227 | } | ||
228 | } | ||
229 | |||
230 | /// <summary> | ||
231 | /// Tests LSLFloat is correctly cast explicitly to integer. | ||
232 | /// </summary> | ||
233 | [Test] | ||
234 | public void TestExplicitCastLSLFloatToInt() | ||
235 | { | ||
236 | int testNumber; | ||
237 | |||
238 | foreach (KeyValuePair<double, int> number in m_doubleIntSet) | ||
239 | { | ||
240 | testNumber = (int) new LSL_Types.LSLFloat(number.Key); | ||
241 | Assert.AreEqual(number.Value, testNumber, "Converting double " + number.Key + ", expecting int " + number.Value); | ||
242 | } | ||
243 | } | ||
244 | |||
245 | /// <summary> | ||
246 | /// Tests LSLFloat is correctly cast explicitly to unsigned integer. | ||
247 | /// </summary> | ||
248 | [Test] | ||
249 | public void TestExplicitCastLSLFloatToUint() | ||
250 | { | ||
251 | uint testNumber; | ||
252 | |||
253 | foreach (KeyValuePair<double, int> number in m_doubleUintSet) | ||
254 | { | ||
255 | testNumber = (uint) new LSL_Types.LSLFloat(number.Key); | ||
256 | Assert.AreEqual(number.Value, testNumber, "Converting double " + number.Key + ", expecting uint " + number.Value); | ||
257 | } | ||
258 | } | ||
259 | |||
260 | /// <summary> | ||
261 | /// Tests LSLFloat is correctly cast implicitly to Boolean if non-zero. | ||
262 | /// </summary> | ||
263 | [Test] | ||
264 | public void TestImplicitCastLSLFloatToBooleanTrue() | ||
265 | { | ||
266 | LSL_Types.LSLFloat testFloat; | ||
267 | bool testBool; | ||
268 | |||
269 | foreach (double number in m_doubleList) | ||
270 | { | ||
271 | testFloat = new LSL_Types.LSLFloat(number); | ||
272 | testBool = testFloat; | ||
273 | |||
274 | Assert.IsTrue(testBool); | ||
275 | } | ||
276 | } | ||
277 | |||
278 | /// <summary> | ||
279 | /// Tests LSLFloat is correctly cast implicitly to Boolean if zero. | ||
280 | /// </summary> | ||
281 | [Test] | ||
282 | public void TestImplicitCastLSLFloatToBooleanFalse() | ||
283 | { | ||
284 | LSL_Types.LSLFloat testFloat = new LSL_Types.LSLFloat(0.0); | ||
285 | bool testBool = testFloat; | ||
286 | |||
287 | Assert.IsFalse(testBool); | ||
288 | } | ||
289 | |||
290 | /// <summary> | ||
291 | /// Tests integer is correctly cast implicitly to LSLFloat. | ||
292 | /// </summary> | ||
293 | [Test] | ||
294 | public void TestImplicitCastIntToLSLFloat() | ||
295 | { | ||
296 | LSL_Types.LSLFloat testFloat; | ||
297 | |||
298 | foreach (int number in m_intList) | ||
299 | { | ||
300 | testFloat = number; | ||
301 | Assert.That(testFloat.value, new DoubleToleranceConstraint(number, _lowPrecisionTolerance)); | ||
302 | } | ||
303 | } | ||
304 | |||
305 | /// <summary> | ||
306 | /// Tests LSLInteger is correctly cast implicitly to LSLFloat. | ||
307 | /// </summary> | ||
308 | [Test] | ||
309 | public void TestImplicitCastLSLIntegerToLSLFloat() | ||
310 | { | ||
311 | LSL_Types.LSLFloat testFloat; | ||
312 | |||
313 | foreach (int number in m_intList) | ||
314 | { | ||
315 | testFloat = new LSL_Types.LSLInteger(number); | ||
316 | Assert.That(testFloat.value, new DoubleToleranceConstraint(number, _lowPrecisionTolerance)); | ||
317 | } | ||
318 | } | ||
319 | |||
320 | /// <summary> | ||
321 | /// Tests LSLInteger is correctly cast explicitly to LSLFloat. | ||
322 | /// </summary> | ||
323 | [Test] | ||
324 | public void TestExplicitCastLSLIntegerToLSLFloat() | ||
325 | { | ||
326 | LSL_Types.LSLFloat testFloat; | ||
327 | |||
328 | foreach (int number in m_intList) | ||
329 | { | ||
330 | testFloat = (LSL_Types.LSLFloat) new LSL_Types.LSLInteger(number); | ||
331 | Assert.That(testFloat.value, new DoubleToleranceConstraint(number, _lowPrecisionTolerance)); | ||
332 | } | ||
333 | } | ||
334 | |||
335 | /// <summary> | ||
336 | /// Tests string is correctly cast explicitly to LSLFloat. | ||
337 | /// </summary> | ||
338 | [Test] | ||
339 | public void TestExplicitCastStringToLSLFloat() | ||
340 | { | ||
341 | LSL_Types.LSLFloat testFloat; | ||
342 | |||
343 | foreach (KeyValuePair<string, double> number in m_stringDoubleSet) | ||
344 | { | ||
345 | testFloat = (LSL_Types.LSLFloat) number.Key; | ||
346 | Assert.That(testFloat.value, new DoubleToleranceConstraint(number.Value, _lowPrecisionTolerance)); | ||
347 | } | ||
348 | } | ||
349 | |||
350 | /// <summary> | ||
351 | /// Tests LSLString is correctly cast implicitly to LSLFloat. | ||
352 | /// </summary> | ||
353 | [Test] | ||
354 | public void TestExplicitCastLSLStringToLSLFloat() | ||
355 | { | ||
356 | LSL_Types.LSLFloat testFloat; | ||
357 | |||
358 | foreach (KeyValuePair<string, double> number in m_stringDoubleSet) | ||
359 | { | ||
360 | testFloat = (LSL_Types.LSLFloat) new LSL_Types.LSLString(number.Key); | ||
361 | Assert.That(testFloat.value, new DoubleToleranceConstraint(number.Value, _lowPrecisionTolerance)); | ||
362 | } | ||
363 | } | ||
364 | |||
365 | /// <summary> | ||
366 | /// Tests double is correctly cast implicitly to LSLFloat. | ||
367 | /// </summary> | ||
368 | [Test] | ||
369 | public void TestImplicitCastDoubleToLSLFloat() | ||
370 | { | ||
371 | LSL_Types.LSLFloat testFloat; | ||
372 | |||
373 | foreach (double number in m_doubleList) | ||
374 | { | ||
375 | testFloat = number; | ||
376 | Assert.That(testFloat.value, new DoubleToleranceConstraint(number, _lowPrecisionTolerance)); | ||
377 | } | ||
378 | } | ||
379 | |||
380 | /// <summary> | ||
381 | /// Tests LSLFloat is correctly cast implicitly to double. | ||
382 | /// </summary> | ||
383 | [Test] | ||
384 | public void TestImplicitCastLSLFloatToDouble() | ||
385 | { | ||
386 | double testNumber; | ||
387 | LSL_Types.LSLFloat testFloat; | ||
388 | |||
389 | foreach (double number in m_doubleList) | ||
390 | { | ||
391 | testFloat = new LSL_Types.LSLFloat(number); | ||
392 | testNumber = testFloat; | ||
393 | |||
394 | Assert.That(testNumber, new DoubleToleranceConstraint(number, _lowPrecisionTolerance)); | ||
395 | } | ||
396 | } | ||
397 | |||
398 | /// <summary> | ||
399 | /// Tests LSLFloat is correctly cast explicitly to float | ||
400 | /// </summary> | ||
401 | [Test] | ||
402 | public void TestExplicitCastLSLFloatToFloat() | ||
403 | { | ||
404 | float testFloat; | ||
405 | float numberAsFloat; | ||
406 | LSL_Types.LSLFloat testLSLFloat; | ||
407 | foreach (double number in m_doubleList) | ||
408 | { | ||
409 | testLSLFloat = new LSL_Types.LSLFloat(number); | ||
410 | numberAsFloat = (float)number; | ||
411 | testFloat = (float)testLSLFloat; | ||
412 | |||
413 | Assert.That((double)testFloat, new DoubleToleranceConstraint((double)numberAsFloat, _lowPrecisionTolerance)); | ||
414 | } | ||
415 | } | ||
416 | |||
417 | |||
418 | /// <summary> | ||
419 | /// Tests the equality (==) operator. | ||
420 | /// </summary> | ||
421 | [Test] | ||
422 | public void TestEqualsOperator() | ||
423 | { | ||
424 | LSL_Types.LSLFloat testFloatA, testFloatB; | ||
425 | |||
426 | foreach (double number in m_doubleList) | ||
427 | { | ||
428 | testFloatA = new LSL_Types.LSLFloat(number); | ||
429 | testFloatB = new LSL_Types.LSLFloat(number); | ||
430 | Assert.IsTrue(testFloatA == testFloatB); | ||
431 | |||
432 | testFloatB = new LSL_Types.LSLFloat(number + 1.0); | ||
433 | Assert.IsFalse(testFloatA == testFloatB); | ||
434 | } | ||
435 | } | ||
436 | |||
437 | /// <summary> | ||
438 | /// Tests the inequality (!=) operator. | ||
439 | /// </summary> | ||
440 | [Test] | ||
441 | public void TestNotEqualOperator() | ||
442 | { | ||
443 | LSL_Types.LSLFloat testFloatA, testFloatB; | ||
444 | |||
445 | foreach (double number in m_doubleList) | ||
446 | { | ||
447 | testFloatA = new LSL_Types.LSLFloat(number); | ||
448 | testFloatB = new LSL_Types.LSLFloat(number + 1.0); | ||
449 | Assert.IsTrue(testFloatA != testFloatB); | ||
450 | |||
451 | testFloatB = new LSL_Types.LSLFloat(number); | ||
452 | Assert.IsFalse(testFloatA != testFloatB); | ||
453 | } | ||
454 | } | ||
455 | |||
456 | /// <summary> | ||
457 | /// Tests the increment operator. | ||
458 | /// </summary> | ||
459 | [Test] | ||
460 | public void TestIncrementOperator() | ||
461 | { | ||
462 | LSL_Types.LSLFloat testFloat; | ||
463 | double testNumber; | ||
464 | |||
465 | foreach (double number in m_doubleList) | ||
466 | { | ||
467 | testFloat = new LSL_Types.LSLFloat(number); | ||
468 | |||
469 | testNumber = testFloat++; | ||
470 | Assert.That(testNumber, new DoubleToleranceConstraint(number, _lowPrecisionTolerance)); | ||
471 | |||
472 | testNumber = testFloat; | ||
473 | Assert.That(testNumber, new DoubleToleranceConstraint(number + 1.0, _lowPrecisionTolerance)); | ||
474 | |||
475 | testNumber = ++testFloat; | ||
476 | Assert.That(testNumber, new DoubleToleranceConstraint(number + 2.0, _lowPrecisionTolerance)); | ||
477 | } | ||
478 | } | ||
479 | |||
480 | /// <summary> | ||
481 | /// Tests the decrement operator. | ||
482 | /// </summary> | ||
483 | [Test] | ||
484 | public void TestDecrementOperator() | ||
485 | { | ||
486 | LSL_Types.LSLFloat testFloat; | ||
487 | double testNumber; | ||
488 | |||
489 | foreach (double number in m_doubleList) | ||
490 | { | ||
491 | testFloat = new LSL_Types.LSLFloat(number); | ||
492 | |||
493 | testNumber = testFloat--; | ||
494 | Assert.That(testNumber, new DoubleToleranceConstraint(number, _lowPrecisionTolerance)); | ||
495 | |||
496 | testNumber = testFloat; | ||
497 | Assert.That(testNumber, new DoubleToleranceConstraint(number - 1.0, _lowPrecisionTolerance)); | ||
498 | |||
499 | testNumber = --testFloat; | ||
500 | Assert.That(testNumber, new DoubleToleranceConstraint(number - 2.0, _lowPrecisionTolerance)); | ||
501 | } | ||
502 | } | ||
503 | |||
504 | /// <summary> | ||
505 | /// Tests LSLFloat.ToString(). | ||
506 | /// </summary> | ||
507 | [Test] | ||
508 | public void TestToString() | ||
509 | { | ||
510 | LSL_Types.LSLFloat testFloat; | ||
511 | |||
512 | foreach (KeyValuePair<double, string> number in m_doubleStringSet) | ||
513 | { | ||
514 | testFloat = new LSL_Types.LSLFloat(number.Key); | ||
515 | Assert.AreEqual(number.Value, testFloat.ToString()); | ||
516 | } | ||
517 | } | ||
518 | |||
519 | /// <summary> | ||
520 | /// Tests addition of two LSLFloats. | ||
521 | /// </summary> | ||
522 | [Test] | ||
523 | public void TestAddTwoLSLFloats() | ||
524 | { | ||
525 | LSL_Types.LSLFloat testResult; | ||
526 | |||
527 | foreach (KeyValuePair<double, double> number in m_doubleDoubleSet) | ||
528 | { | ||
529 | testResult = new LSL_Types.LSLFloat(number.Key) + new LSL_Types.LSLFloat(number.Value); | ||
530 | Assert.That(testResult.value, new DoubleToleranceConstraint(number.Key + number.Value, _lowPrecisionTolerance)); | ||
531 | } | ||
532 | } | ||
533 | |||
534 | /// <summary> | ||
535 | /// Tests subtraction of two LSLFloats. | ||
536 | /// </summary> | ||
537 | [Test] | ||
538 | public void TestSubtractTwoLSLFloats() | ||
539 | { | ||
540 | LSL_Types.LSLFloat testResult; | ||
541 | |||
542 | foreach (KeyValuePair<double, double> number in m_doubleDoubleSet) | ||
543 | { | ||
544 | testResult = new LSL_Types.LSLFloat(number.Key) - new LSL_Types.LSLFloat(number.Value); | ||
545 | Assert.That(testResult.value, new DoubleToleranceConstraint(number.Key - number.Value, _lowPrecisionTolerance)); | ||
546 | } | ||
547 | } | ||
548 | |||
549 | /// <summary> | ||
550 | /// Tests multiplication of two LSLFloats. | ||
551 | /// </summary> | ||
552 | [Test] | ||
553 | public void TestMultiplyTwoLSLFloats() | ||
554 | { | ||
555 | LSL_Types.LSLFloat testResult; | ||
556 | |||
557 | foreach (KeyValuePair<double, double> number in m_doubleDoubleSet) | ||
558 | { | ||
559 | testResult = new LSL_Types.LSLFloat(number.Key) * new LSL_Types.LSLFloat(number.Value); | ||
560 | Assert.That(testResult.value, new DoubleToleranceConstraint(number.Key * number.Value, _lowPrecisionTolerance)); | ||
561 | } | ||
562 | } | ||
563 | |||
564 | /// <summary> | ||
565 | /// Tests division of two LSLFloats. | ||
566 | /// </summary> | ||
567 | [Test] | ||
568 | public void TestDivideTwoLSLFloats() | ||
569 | { | ||
570 | LSL_Types.LSLFloat testResult; | ||
571 | |||
572 | foreach (KeyValuePair<double, double> number in m_doubleDoubleSet) | ||
573 | { | ||
574 | if (number.Value != 0.0) // Let's avoid divide by zero. | ||
575 | { | ||
576 | testResult = new LSL_Types.LSLFloat(number.Key) / new LSL_Types.LSLFloat(number.Value); | ||
577 | Assert.That(testResult.value, new DoubleToleranceConstraint(number.Key / number.Value, _lowPrecisionTolerance)); | ||
578 | } | ||
579 | } | ||
580 | } | ||
581 | |||
582 | /// <summary> | ||
583 | /// Tests boolean correctly cast implicitly to LSLFloat. | ||
584 | /// </summary> | ||
585 | [Test] | ||
586 | public void TestImplicitCastBooleanToLSLFloat() | ||
587 | { | ||
588 | LSL_Types.LSLFloat testFloat; | ||
589 | |||
590 | testFloat = (1 == 0); | ||
591 | Assert.That(testFloat.value, new DoubleToleranceConstraint(0.0, _lowPrecisionTolerance)); | ||
592 | |||
593 | testFloat = (1 == 1); | ||
594 | Assert.That(testFloat.value, new DoubleToleranceConstraint(1.0, _lowPrecisionTolerance)); | ||
595 | |||
596 | testFloat = false; | ||
597 | Assert.That(testFloat.value, new DoubleToleranceConstraint(0.0, _lowPrecisionTolerance)); | ||
598 | |||
599 | testFloat = true; | ||
600 | Assert.That(testFloat.value, new DoubleToleranceConstraint(1.0, _lowPrecisionTolerance)); | ||
601 | } | ||
602 | } | ||
603 | } | ||