28 using System.Collections.Generic;
29 using NUnit.Framework;
30 using OpenSim.Tests.Common;
31 using OpenSim.Region.ScriptEngine.Shared;
33 namespace OpenSim.
Region.ScriptEngine.Shared.Tests
39 private double _lowPrecisionTolerance = 0.000001;
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;
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);
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);
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);
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);
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);
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);
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");
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);
200 m_intList =
new List<int>();
206 m_intList.Add(999999999);
207 m_intList.Add(-99999999);
216 TestHelpers.InMethod();
220 foreach (KeyValuePair<int, double> number
in m_intDoubleSet)
233 TestHelpers.InMethod();
237 foreach (KeyValuePair<double, double> number
in m_doubleDoubleSet)
250 TestHelpers.InMethod();
254 foreach (KeyValuePair<double, int> number
in m_doubleIntSet)
256 testNumber = (int)
new LSL_Types.LSLFloat(number.Key);
257 Assert.AreEqual(number.Value, testNumber,
"Converting double " + number.Key +
", expecting int " + number.Value);
267 TestHelpers.InMethod();
271 foreach (KeyValuePair<double, int> number
in m_doubleUintSet)
273 testNumber = (uint)
new LSL_Types.LSLFloat(number.Key);
274 Assert.AreEqual(number.Value, testNumber,
"Converting double " + number.Key +
", expecting uint " + number.Value);
284 TestHelpers.InMethod();
289 foreach (
double number
in m_doubleList)
292 testBool = testFloat;
294 Assert.IsTrue(testBool);
304 TestHelpers.InMethod();
307 bool testBool = testFloat;
309 Assert.IsFalse(testBool);
318 TestHelpers.InMethod();
322 foreach (
int number
in m_intList)
335 TestHelpers.InMethod();
339 foreach (
int number
in m_intList)
352 TestHelpers.InMethod();
356 foreach (
int number
in m_intList)
369 TestHelpers.InMethod();
373 foreach (KeyValuePair<string, double> number
in m_stringDoubleSet)
386 TestHelpers.InMethod();
390 foreach (KeyValuePair<string, double> number
in m_stringDoubleSet)
403 TestHelpers.InMethod();
407 foreach (
double number
in m_doubleList)
420 TestHelpers.InMethod();
425 foreach (
double number
in m_doubleList)
428 testNumber = testFloat;
440 TestHelpers.InMethod();
446 foreach (
double number
in m_doubleList)
449 numberAsFloat = (float)number;
450 testFloat = (float)testLSLFloat;
462 TestHelpers.InMethod();
466 foreach (
double number
in m_doubleList)
470 Assert.IsTrue(testFloatA == testFloatB);
473 Assert.IsFalse(testFloatA == testFloatB);
483 TestHelpers.InMethod();
487 foreach (
double number
in m_doubleList)
491 Assert.IsTrue(testFloatA != testFloatB);
494 Assert.IsFalse(testFloatA != testFloatB);
504 TestHelpers.InMethod();
509 foreach (
double number
in m_doubleList)
513 testNumber = testFloat++;
516 testNumber = testFloat;
519 testNumber = ++testFloat;
530 TestHelpers.InMethod();
535 foreach (
double number
in m_doubleList)
539 testNumber = testFloat--;
542 testNumber = testFloat;
545 testNumber = --testFloat;
556 TestHelpers.InMethod();
560 foreach (KeyValuePair<double, string> number
in m_doubleStringSet)
563 Assert.AreEqual(number.Value, testFloat.ToString());
573 TestHelpers.InMethod();
577 foreach (KeyValuePair<double, double> number
in m_doubleDoubleSet)
590 TestHelpers.InMethod();
594 foreach (KeyValuePair<double, double> number
in m_doubleDoubleSet)
607 TestHelpers.InMethod();
611 foreach (KeyValuePair<double, double> number
in m_doubleDoubleSet)
624 TestHelpers.InMethod();
628 foreach (KeyValuePair<double, double> number
in m_doubleDoubleSet)
630 if (number.Value != 0.0)
644 TestHelpers.InMethod();
648 testFloat = (1 == 0);
651 testFloat = (1 == 1);
void TestConstructFromDouble()
Tests constructing a LSLFloat from a double.
void TestImplicitCastIntToLSLFloat()
Tests integer is correctly cast implicitly to LSLFloat.
void TestImplicitCastDoubleToLSLFloat()
Tests double is correctly cast implicitly to LSLFloat.
void TestImplicitCastBooleanToLSLFloat()
Tests boolean correctly cast implicitly to LSLFloat.
void TestExplicitCastLSLFloatToInt()
Tests LSLFloat is correctly cast explicitly to integer.
void TestIncrementOperator()
Tests the increment operator.
void TestNotEqualOperator()
Tests the inequality (!=) operator.
void TestImplicitCastLSLIntegerToLSLFloat()
Tests LSLInteger is correctly cast implicitly to LSLFloat.
void TestExplicitCastLSLStringToLSLFloat()
Tests LSLString is correctly cast implicitly to LSLFloat.
void TestDecrementOperator()
Tests the decrement operator.
void TestExplicitCastLSLIntegerToLSLFloat()
Tests LSLInteger is correctly cast explicitly to LSLFloat.
void TestMultiplyTwoLSLFloats()
Tests multiplication of two LSLFloats.
void TestToString()
Tests LSLFloat.ToString().
void TestDivideTwoLSLFloats()
Tests division of two LSLFloats.
void SetUpDataSets()
Sets up dictionaries and arrays used in the tests.
void TestExplicitCastStringToLSLFloat()
Tests string is correctly cast explicitly to LSLFloat.
void TestConstructFromInt()
Tests constructing a LSLFloat from an integer.
void TestAddTwoLSLFloats()
Tests addition of two LSLFloats.
void TestEqualsOperator()
Tests the equality (==) operator.
void TestImplicitCastLSLFloatToDouble()
Tests LSLFloat is correctly cast implicitly to double.
void TestExplicitCastLSLFloatToUint()
Tests LSLFloat is correctly cast explicitly to unsigned integer.
void TestExplicitCastLSLFloatToFloat()
Tests LSLFloat is correctly cast explicitly to float
void TestImplicitCastLSLFloatToBooleanFalse()
Tests LSLFloat is correctly cast implicitly to Boolean if zero.
void TestSubtractTwoLSLFloats()
Tests subtraction of two LSLFloats.
void TestImplicitCastLSLFloatToBooleanTrue()
Tests LSLFloat is correctly cast implicitly to Boolean if non-zero.