aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Tests
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Tests')
-rw-r--r--OpenSim/Tests/OpenSim/Region/ScriptEngine/Common/LSL_TypesTestLSLFloat.cs1
-rw-r--r--OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/LSL_TypesTestLSLFloat.cs562
-rw-r--r--OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/LSL_TypesTestLSLString.cs98
-rw-r--r--OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/LSL_TypesTestList.cs101
-rw-r--r--OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/LSL_TypesTestVector3.cs62
5 files changed, 823 insertions, 1 deletions
diff --git a/OpenSim/Tests/OpenSim/Region/ScriptEngine/Common/LSL_TypesTestLSLFloat.cs b/OpenSim/Tests/OpenSim/Region/ScriptEngine/Common/LSL_TypesTestLSLFloat.cs
index 2a26031..c2d2a5a 100644
--- a/OpenSim/Tests/OpenSim/Region/ScriptEngine/Common/LSL_TypesTestLSLFloat.cs
+++ b/OpenSim/Tests/OpenSim/Region/ScriptEngine/Common/LSL_TypesTestLSLFloat.cs
@@ -29,7 +29,6 @@ using System.Collections.Generic;
29using NUnit.Framework; 29using NUnit.Framework;
30using OpenSim.Tests.Common; 30using OpenSim.Tests.Common;
31using OpenSim.Region.ScriptEngine.Common; 31using OpenSim.Region.ScriptEngine.Common;
32using System;
33 32
34namespace OpenSim.Region.ScriptEngine.Common.Tests 33namespace OpenSim.Region.ScriptEngine.Common.Tests
35{ 34{
diff --git a/OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/LSL_TypesTestLSLFloat.cs b/OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/LSL_TypesTestLSLFloat.cs
new file mode 100644
index 0000000..035208b
--- /dev/null
+++ b/OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/LSL_TypesTestLSLFloat.cs
@@ -0,0 +1,562 @@
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
28using System.Collections.Generic;
29using NUnit.Framework;
30using OpenSim.Tests.Common;
31using OpenSim.Region.ScriptEngine.Shared;
32
33namespace 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 implicitly to integer.
232 /// </summary>
233 [Test]
234 public void TestImplicitCastLSLFloatToInt()
235 {
236 int testNumber;
237
238 foreach (KeyValuePair<double, int> number in m_doubleIntSet)
239 {
240 testNumber = 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 implicitly to unsigned integer.
247 /// </summary>
248 [Test]
249 public void TestImplicitCastLSLFloatToUint()
250 {
251 uint testNumber;
252
253 foreach (KeyValuePair<double, int> number in m_doubleUintSet)
254 {
255 testNumber = 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 implicitly to LSLFloat.
337 /// </summary>
338 [Test]
339 public void TestImplicitCastStringToLSLFloat()
340 {
341 LSL_Types.LSLFloat testFloat;
342
343 foreach (KeyValuePair<string, double> number in m_stringDoubleSet)
344 {
345 testFloat = 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 the equality (==) operator.
382 /// </summary>
383 [Test]
384 public void TestEqualsOperator()
385 {
386 LSL_Types.LSLFloat testFloatA, testFloatB;
387
388 foreach (double number in m_doubleList)
389 {
390 testFloatA = new LSL_Types.LSLFloat(number);
391 testFloatB = new LSL_Types.LSLFloat(number);
392 Assert.IsTrue(testFloatA == testFloatB);
393
394 testFloatB = new LSL_Types.LSLFloat(number + 1.0);
395 Assert.IsFalse(testFloatA == testFloatB);
396 }
397 }
398
399 /// <summary>
400 /// Tests the inequality (!=) operator.
401 /// </summary>
402 [Test]
403 public void TestNotEqualOperator()
404 {
405 LSL_Types.LSLFloat testFloatA, testFloatB;
406
407 foreach (double number in m_doubleList)
408 {
409 testFloatA = new LSL_Types.LSLFloat(number);
410 testFloatB = new LSL_Types.LSLFloat(number + 1.0);
411 Assert.IsTrue(testFloatA != testFloatB);
412
413 testFloatB = new LSL_Types.LSLFloat(number);
414 Assert.IsFalse(testFloatA != testFloatB);
415 }
416 }
417
418 /// <summary>
419 /// Tests the increment operator.
420 /// </summary>
421 [Test]
422 public void TestIncrementOperator()
423 {
424 LSL_Types.LSLFloat testFloat;
425 double testNumber;
426
427 foreach (double number in m_doubleList)
428 {
429 testFloat = new LSL_Types.LSLFloat(number);
430
431 testNumber = testFloat++;
432 Assert.That(testNumber, new DoubleToleranceConstraint(number, _lowPrecisionTolerance));
433
434 testNumber = testFloat;
435 Assert.That(testNumber, new DoubleToleranceConstraint(number + 1.0, _lowPrecisionTolerance));
436
437 testNumber = ++testFloat;
438 Assert.That(testNumber, new DoubleToleranceConstraint(number + 2.0, _lowPrecisionTolerance));
439 }
440 }
441
442 /// <summary>
443 /// Tests the decrement operator.
444 /// </summary>
445 [Test]
446 public void TestDecrementOperator()
447 {
448 LSL_Types.LSLFloat testFloat;
449 double testNumber;
450
451 foreach (double number in m_doubleList)
452 {
453 testFloat = new LSL_Types.LSLFloat(number);
454
455 testNumber = testFloat--;
456 Assert.That(testNumber, new DoubleToleranceConstraint(number, _lowPrecisionTolerance));
457
458 testNumber = testFloat;
459 Assert.That(testNumber, new DoubleToleranceConstraint(number - 1.0, _lowPrecisionTolerance));
460
461 testNumber = --testFloat;
462 Assert.That(testNumber, new DoubleToleranceConstraint(number - 2.0, _lowPrecisionTolerance));
463 }
464 }
465
466 /// <summary>
467 /// Tests LSLFloat is correctly cast implicitly to double.
468 /// </summary>
469 [Test]
470 public void TestImplicitCastLSLFloatToDouble()
471 {
472 double testNumber;
473 LSL_Types.LSLFloat testFloat;
474
475 foreach (double number in m_doubleList)
476 {
477 testFloat = new LSL_Types.LSLFloat(number);
478 testNumber = testFloat;
479
480 Assert.That(testNumber, new DoubleToleranceConstraint(number, _lowPrecisionTolerance));
481 }
482 }
483
484 /// <summary>
485 /// Tests LSLFloat.ToString().
486 /// </summary>
487 [Test]
488 public void TestToString()
489 {
490 LSL_Types.LSLFloat testFloat;
491
492 foreach (KeyValuePair<double, string> number in m_doubleStringSet)
493 {
494 testFloat = new LSL_Types.LSLFloat(number.Key);
495 Assert.AreEqual(number.Value, testFloat.ToString());
496 }
497 }
498
499 /// <summary>
500 /// Tests addition of two LSLFloats.
501 /// </summary>
502 [Test]
503 public void TestAddTwoLSLFloats()
504 {
505 LSL_Types.LSLFloat testResult;
506
507 foreach (KeyValuePair<double, double> number in m_doubleDoubleSet)
508 {
509 testResult = new LSL_Types.LSLFloat(number.Key) + new LSL_Types.LSLFloat(number.Value);
510 Assert.That(testResult.value, new DoubleToleranceConstraint(number.Key + number.Value, _lowPrecisionTolerance));
511 }
512 }
513
514 /// <summary>
515 /// Tests subtraction of two LSLFloats.
516 /// </summary>
517 [Test]
518 public void TestSubtractTwoLSLFloats()
519 {
520 LSL_Types.LSLFloat testResult;
521
522 foreach (KeyValuePair<double, double> number in m_doubleDoubleSet)
523 {
524 testResult = new LSL_Types.LSLFloat(number.Key) - new LSL_Types.LSLFloat(number.Value);
525 Assert.That(testResult.value, new DoubleToleranceConstraint(number.Key - number.Value, _lowPrecisionTolerance));
526 }
527 }
528
529 /// <summary>
530 /// Tests multiplication of two LSLFloats.
531 /// </summary>
532 [Test]
533 public void TestMultiplyTwoLSLFloats()
534 {
535 LSL_Types.LSLFloat testResult;
536
537 foreach (KeyValuePair<double, double> number in m_doubleDoubleSet)
538 {
539 testResult = new LSL_Types.LSLFloat(number.Key) * new LSL_Types.LSLFloat(number.Value);
540 Assert.That(testResult.value, new DoubleToleranceConstraint(number.Key * number.Value, _lowPrecisionTolerance));
541 }
542 }
543
544 /// <summary>
545 /// Tests division of two LSLFloats.
546 /// </summary>
547 [Test]
548 public void TestDivideTwoLSLFloats()
549 {
550 LSL_Types.LSLFloat testResult;
551
552 foreach (KeyValuePair<double, double> number in m_doubleDoubleSet)
553 {
554 if (number.Value != 0.0) // Let's avoid divide by zero.
555 {
556 testResult = new LSL_Types.LSLFloat(number.Key) / new LSL_Types.LSLFloat(number.Value);
557 Assert.That(testResult.value, new DoubleToleranceConstraint(number.Key / number.Value, _lowPrecisionTolerance));
558 }
559 }
560 }
561 }
562}
diff --git a/OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/LSL_TypesTestLSLString.cs b/OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/LSL_TypesTestLSLString.cs
new file mode 100644
index 0000000..ceab376
--- /dev/null
+++ b/OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/LSL_TypesTestLSLString.cs
@@ -0,0 +1,98 @@
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
28using System.Collections.Generic;
29using NUnit.Framework;
30using OpenSim.Tests.Common;
31using OpenSim.Region.ScriptEngine.Shared;
32
33namespace OpenSim.Region.ScriptEngine.Shared.Tests
34{
35 [TestFixture]
36 public class LSL_TypesTestLSLString
37 {
38 private Dictionary<double, string> m_doubleStringSet;
39
40 /// <summary>
41 /// Sets up dictionaries and arrays used in the tests.
42 /// </summary>
43 [TestFixtureSetUp]
44 public void SetUpDataSets()
45 {
46 m_doubleStringSet = new Dictionary<double, string>();
47 m_doubleStringSet.Add(2, "2.000000");
48 m_doubleStringSet.Add(-2, "-2.000000");
49 m_doubleStringSet.Add(0, "0.000000");
50 m_doubleStringSet.Add(1, "1.000000");
51 m_doubleStringSet.Add(-1, "-1.000000");
52 m_doubleStringSet.Add(999999999, "999999999.000000");
53 m_doubleStringSet.Add(-99999999, "-99999999.000000");
54 m_doubleStringSet.Add(0.5, "0.500000");
55 m_doubleStringSet.Add(0.0005, "0.000500");
56 m_doubleStringSet.Add(0.6805, "0.680500");
57 m_doubleStringSet.Add(-0.5, "-0.500000");
58 m_doubleStringSet.Add(-0.0005, "-0.000500");
59 m_doubleStringSet.Add(-0.6805, "-0.680500");
60 m_doubleStringSet.Add(548.5, "548.500000");
61 m_doubleStringSet.Add(2.0005, "2.000500");
62 m_doubleStringSet.Add(349485435.6805, "349485435.680500");
63 m_doubleStringSet.Add(-548.5, "-548.500000");
64 m_doubleStringSet.Add(-2.0005, "-2.000500");
65 m_doubleStringSet.Add(-349485435.6805, "-349485435.680500");
66 }
67
68 /// <summary>
69 /// Tests constructing a LSLString from an LSLFloat.
70 /// </summary>
71 [Test]
72 public void TestConstructFromLSLFloat()
73 {
74 LSL_Types.LSLString testString;
75
76 foreach (KeyValuePair<double, string> number in m_doubleStringSet)
77 {
78 testString = new LSL_Types.LSLString(new LSL_Types.LSLFloat(number.Key));
79 Assert.AreEqual(number.Value, testString.m_string);
80 }
81 }
82
83 /// <summary>
84 /// Tests constructing a LSLString from an LSLFloat.
85 /// </summary>
86 [Test]
87 public void TestExplicitCastLSLFloatToLSLString()
88 {
89 LSL_Types.LSLString testString;
90
91 foreach (KeyValuePair<double, string> number in m_doubleStringSet)
92 {
93 testString = (LSL_Types.LSLString) new LSL_Types.LSLFloat(number.Key);
94 Assert.AreEqual(number.Value, testString.m_string);
95 }
96 }
97 }
98}
diff --git a/OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/LSL_TypesTestList.cs b/OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/LSL_TypesTestList.cs
new file mode 100644
index 0000000..c1c9ef7
--- /dev/null
+++ b/OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/LSL_TypesTestList.cs
@@ -0,0 +1,101 @@
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
28using System.Collections.Generic;
29using NUnit.Framework;
30using OpenSim.Tests.Common;
31using OpenSim.Region.ScriptEngine.Shared;
32
33namespace OpenSim.Region.ScriptEngine.Shared.Tests
34{
35 /// <summary>
36 /// Tests the LSL_Types.list class.
37 /// </summary>
38 [TestFixture]
39 public class LSL_TypesTestList
40 {
41 /// <summary>
42 /// Tests concatenating a string to a list.
43 /// </summary>
44 [Test]
45 public void TestConcatenateString()
46 {
47 LSL_Types.list testList = new LSL_Types.list(1, 'a', "test");
48 testList += "addition";
49
50 Assert.AreEqual(4, testList.Length);
51 Assert.AreEqual("addition", testList.Data[3]);
52 Assert.AreEqual(typeof(System.String), testList.Data[3].GetType());
53
54 LSL_Types.list secondTestList = testList + "more";
55
56 Assert.AreEqual(5, secondTestList.Length);
57 Assert.AreEqual("more", secondTestList.Data[4]);
58 Assert.AreEqual(typeof(System.String), secondTestList.Data[4].GetType());
59 }
60
61 /// <summary>
62 /// Tests concatenating an integer to a list.
63 /// </summary>
64 [Test]
65 public void TestConcatenateInteger()
66 {
67 LSL_Types.list testList = new LSL_Types.list(1, 'a', "test");
68 testList += 20;
69
70 Assert.AreEqual(4, testList.Length);
71 Assert.AreEqual(20, testList.Data[3]);
72 Assert.AreEqual(typeof(int), testList.Data[3].GetType());
73
74 LSL_Types.list secondTestList = testList + 2;
75
76 Assert.AreEqual(5, secondTestList.Length);
77 Assert.AreEqual(2, secondTestList.Data[4]);
78 Assert.AreEqual(typeof(int), secondTestList.Data[4].GetType());
79 }
80
81 /// <summary>
82 /// Tests concatenating a double to a list.
83 /// </summary>
84 [Test]
85 public void TestConcatenateDouble()
86 {
87 LSL_Types.list testList = new LSL_Types.list(1, 'a', "test");
88 testList += 2.0;
89
90 Assert.AreEqual(4, testList.Length);
91 Assert.AreEqual(2.0, testList.Data[3]);
92 Assert.AreEqual(typeof(double), testList.Data[3].GetType());
93
94 LSL_Types.list secondTestList = testList + 0.04;
95
96 Assert.AreEqual(5, secondTestList.Length);
97 Assert.AreEqual(0.04, secondTestList.Data[4]);
98 Assert.AreEqual(typeof(double), secondTestList.Data[4].GetType());
99 }
100 }
101}
diff --git a/OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/LSL_TypesTestVector3.cs b/OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/LSL_TypesTestVector3.cs
new file mode 100644
index 0000000..fb2c00c
--- /dev/null
+++ b/OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/LSL_TypesTestVector3.cs
@@ -0,0 +1,62 @@
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
28using System.Collections.Generic;
29using NUnit.Framework;
30using OpenSim.Tests.Common;
31using OpenSim.Region.ScriptEngine.Shared;
32
33namespace OpenSim.Region.ScriptEngine.Shared.Tests
34{
35 [TestFixture]
36 public class LSL_TypesTestVector3
37 {
38 /// <summary>
39 /// Tests for Vector3
40 /// </summary>
41 [Test]
42
43 public void TestDotProduct()
44 {
45 // The numbers we test for.
46 Dictionary<string, double> expectsSet = new Dictionary<string, double>();
47 expectsSet.Add("<1, 2, 3> * <2, 3, 4>", 20.0);
48 expectsSet.Add("<1, 2, 3> * <0, 0, 0>", 0.0);
49
50 double result;
51 string[] parts;
52 string[] delim = { "*" };
53
54 foreach (KeyValuePair<string, double> ex in expectsSet)
55 {
56 parts = ex.Key.Split(delim, System.StringSplitOptions.None);
57 result = new LSL_Types.Vector3(parts[0]) * new LSL_Types.Vector3(parts[1]);
58 Assert.AreEqual(ex.Value, result);
59 }
60 }
61 }
62}