From 82fa53a486b16687131a0f85ba02b579b5456f3a Mon Sep 17 00:00:00 2001 From: Mike Mazur Date: Mon, 28 Jul 2008 02:36:18 +0000 Subject: [PATCH] -copy LSL_Types tests from Common/ to Shared/ -fix some whitespace/formatting --- .../Region/ScriptEngine/Common/LSL_Types.cs | 6 +- .../Region/ScriptEngine/Shared/LSL_Types.cs | 12 +- .../Common/LSL_TypesTestLSLFloat.cs | 1 - .../Shared/LSL_TypesTestLSLFloat.cs | 562 ++++++++++++++++++ .../Shared/LSL_TypesTestLSLString.cs | 98 +++ .../ScriptEngine/Shared/LSL_TypesTestList.cs | 101 ++++ .../Shared/LSL_TypesTestVector3.cs | 62 ++ prebuild.xml | 22 + 8 files changed, 854 insertions(+), 10 deletions(-) create mode 100644 OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/LSL_TypesTestLSLFloat.cs create mode 100644 OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/LSL_TypesTestLSLString.cs create mode 100644 OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/LSL_TypesTestList.cs create mode 100644 OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/LSL_TypesTestVector3.cs diff --git a/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs b/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs index 5607706ad7..bb1fe2f0b2 100644 --- a/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs +++ b/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs @@ -1285,7 +1285,7 @@ namespace OpenSim.Region.ScriptEngine.Common { return new LSLInteger(u); } - + static public explicit operator LSLInteger(double d) { return new LSLInteger(d); @@ -1322,7 +1322,7 @@ namespace OpenSim.Region.ScriptEngine.Common { return new LSLInteger(i1.value / i2); } - + static public LSLFloat operator +(LSLInteger i1, double f) { return new LSLFloat((double)i1.value + f); @@ -1510,7 +1510,7 @@ namespace OpenSim.Region.ScriptEngine.Common { return new LSLFloat(f.value / (double)i); } - + static public LSLFloat operator +(LSLFloat lhs, LSLFloat rhs) { return new LSLFloat(lhs.value + rhs.value); diff --git a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs index 398e73df98..89722da1b6 100644 --- a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs +++ b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs @@ -1280,7 +1280,7 @@ namespace OpenSim.Region.ScriptEngine.Shared { return new LSLInteger(int.Parse(s)); } - + static public implicit operator LSLInteger(uint u) { return new LSLInteger(u); @@ -1347,7 +1347,7 @@ namespace OpenSim.Region.ScriptEngine.Shared { return new LSLInteger(-i.value); } - + public override bool Equals(Object o) { if (!(o is LSLInteger)) @@ -1362,7 +1362,7 @@ namespace OpenSim.Region.ScriptEngine.Shared static public LSLInteger operator &(LSLInteger i1, LSLInteger i2) { - int ret = i1.value & i2.value; + int ret = i1.value & i2.value; return ret; } @@ -1505,7 +1505,7 @@ namespace OpenSim.Region.ScriptEngine.Shared { return new LSLFloat(f.value * (double)i); } - + static public LSLFloat operator /(LSLFloat f, int i) { return new LSLFloat(f.value / (double)i); @@ -1535,12 +1535,12 @@ namespace OpenSim.Region.ScriptEngine.Shared { return new LSLFloat(-f.value); } - + static public implicit operator System.Double(LSLFloat f) { return f.value; } - + #endregion #region Overriders diff --git a/OpenSim/Tests/OpenSim/Region/ScriptEngine/Common/LSL_TypesTestLSLFloat.cs b/OpenSim/Tests/OpenSim/Region/ScriptEngine/Common/LSL_TypesTestLSLFloat.cs index 2a2603186b..c2d2a5a64d 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; using NUnit.Framework; using OpenSim.Tests.Common; using OpenSim.Region.ScriptEngine.Common; -using System; namespace OpenSim.Region.ScriptEngine.Common.Tests { 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 0000000000..035208b713 --- /dev/null +++ b/OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/LSL_TypesTestLSLFloat.cs @@ -0,0 +1,562 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSim Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System.Collections.Generic; +using NUnit.Framework; +using OpenSim.Tests.Common; +using OpenSim.Region.ScriptEngine.Shared; + +namespace OpenSim.Region.ScriptEngine.Shared.Tests +{ + [TestFixture] + public class LSL_TypesTestLSLFloat + { + // Used for testing equality of two floats. + private double _lowPrecisionTolerance = 0.000001; + + private Dictionary m_intDoubleSet; + private Dictionary m_doubleDoubleSet; + private Dictionary m_doubleIntSet; + private Dictionary m_doubleUintSet; + private Dictionary m_stringDoubleSet; + private Dictionary m_doubleStringSet; + private List m_intList; + private List m_doubleList; + + /// + /// Sets up dictionaries and arrays used in the tests. + /// + [TestFixtureSetUp] + public void SetUpDataSets() + { + m_intDoubleSet = new Dictionary(); + m_intDoubleSet.Add(2, 2.0); + m_intDoubleSet.Add(-2, -2.0); + m_intDoubleSet.Add(0, 0.0); + m_intDoubleSet.Add(1, 1.0); + m_intDoubleSet.Add(-1, -1.0); + m_intDoubleSet.Add(999999999, 999999999.0); + m_intDoubleSet.Add(-99999999, -99999999.0); + + m_doubleDoubleSet = new Dictionary(); + m_doubleDoubleSet.Add(2.0, 2.0); + m_doubleDoubleSet.Add(-2.0, -2.0); + m_doubleDoubleSet.Add(0.0, 0.0); + m_doubleDoubleSet.Add(1.0, 1.0); + m_doubleDoubleSet.Add(-1.0, -1.0); + m_doubleDoubleSet.Add(999999999.0, 999999999.0); + m_doubleDoubleSet.Add(-99999999.0, -99999999.0); + m_doubleDoubleSet.Add(0.5, 0.5); + m_doubleDoubleSet.Add(0.0005, 0.0005); + m_doubleDoubleSet.Add(0.6805, 0.6805); + m_doubleDoubleSet.Add(-0.5, -0.5); + m_doubleDoubleSet.Add(-0.0005, -0.0005); + m_doubleDoubleSet.Add(-0.6805, -0.6805); + m_doubleDoubleSet.Add(548.5, 548.5); + m_doubleDoubleSet.Add(2.0005, 2.0005); + m_doubleDoubleSet.Add(349485435.6805, 349485435.6805); + m_doubleDoubleSet.Add(-548.5, -548.5); + m_doubleDoubleSet.Add(-2.0005, -2.0005); + m_doubleDoubleSet.Add(-349485435.6805, -349485435.6805); + + m_doubleIntSet = new Dictionary(); + m_doubleIntSet.Add(2.0, 2); + m_doubleIntSet.Add(-2.0, -2); + m_doubleIntSet.Add(0.0, 0); + m_doubleIntSet.Add(1.0, 1); + m_doubleIntSet.Add(-1.0, -1); + m_doubleIntSet.Add(999999999.0, 999999999); + m_doubleIntSet.Add(-99999999.0, -99999999); + m_doubleIntSet.Add(0.5, 0); + m_doubleIntSet.Add(0.0005, 0); + m_doubleIntSet.Add(0.6805, 0); + m_doubleIntSet.Add(-0.5, 0); + m_doubleIntSet.Add(-0.0005, 0); + m_doubleIntSet.Add(-0.6805, 0); + m_doubleIntSet.Add(548.5, 548); + m_doubleIntSet.Add(2.0005, 2); + m_doubleIntSet.Add(349485435.6805, 349485435); + m_doubleIntSet.Add(-548.5, -548); + m_doubleIntSet.Add(-2.0005, -2); + m_doubleIntSet.Add(-349485435.6805, -349485435); + + m_doubleUintSet = new Dictionary(); + m_doubleUintSet.Add(2.0, 2); + m_doubleUintSet.Add(-2.0, 2); + m_doubleUintSet.Add(0.0, 0); + m_doubleUintSet.Add(1.0, 1); + m_doubleUintSet.Add(-1.0, 1); + m_doubleUintSet.Add(999999999.0, 999999999); + m_doubleUintSet.Add(-99999999.0, 99999999); + m_doubleUintSet.Add(0.5, 0); + m_doubleUintSet.Add(0.0005, 0); + m_doubleUintSet.Add(0.6805, 0); + m_doubleUintSet.Add(-0.5, 0); + m_doubleUintSet.Add(-0.0005, 0); + m_doubleUintSet.Add(-0.6805, 0); + m_doubleUintSet.Add(548.5, 548); + m_doubleUintSet.Add(2.0005, 2); + m_doubleUintSet.Add(349485435.6805, 349485435); + m_doubleUintSet.Add(-548.5, 548); + m_doubleUintSet.Add(-2.0005, 2); + m_doubleUintSet.Add(-349485435.6805, 349485435); + + m_stringDoubleSet = new Dictionary(); + m_stringDoubleSet.Add("2", 2.0); + m_stringDoubleSet.Add("-2", -2.0); + m_stringDoubleSet.Add("1", 1.0); + m_stringDoubleSet.Add("-1", -1.0); + m_stringDoubleSet.Add("0", 0.0); + m_stringDoubleSet.Add("999999999.0", 999999999.0); + m_stringDoubleSet.Add("-99999999.0", -99999999.0); + m_stringDoubleSet.Add("0.5", 0.5); + m_stringDoubleSet.Add("0.0005", 0.0005); + m_stringDoubleSet.Add("0.6805", 0.6805); + m_stringDoubleSet.Add("-0.5", -0.5); + m_stringDoubleSet.Add("-0.0005", -0.0005); + m_stringDoubleSet.Add("-0.6805", -0.6805); + m_stringDoubleSet.Add("548.5", 548.5); + m_stringDoubleSet.Add("2.0005", 2.0005); + m_stringDoubleSet.Add("349485435.6805", 349485435.6805); + m_stringDoubleSet.Add("-548.5", -548.5); + m_stringDoubleSet.Add("-2.0005", -2.0005); + m_stringDoubleSet.Add("-349485435.6805", -349485435.6805); + + m_doubleStringSet = new Dictionary(); + m_doubleStringSet.Add(2.0, "2.000000"); + m_doubleStringSet.Add(-2.0, "-2.000000"); + m_doubleStringSet.Add(1.0, "1.000000"); + m_doubleStringSet.Add(-1.0, "-1.000000"); + m_doubleStringSet.Add(0.0, "0.000000"); + m_doubleStringSet.Add(999999999.0, "999999999.000000"); + m_doubleStringSet.Add(-99999999.0, "-99999999.000000"); + m_doubleStringSet.Add(0.5, "0.500000"); + m_doubleStringSet.Add(0.0005, "0.000500"); + m_doubleStringSet.Add(0.6805, "0.680500"); + m_doubleStringSet.Add(-0.5, "-0.500000"); + m_doubleStringSet.Add(-0.0005, "-0.000500"); + m_doubleStringSet.Add(-0.6805, "-0.680500"); + m_doubleStringSet.Add(548.5, "548.500000"); + m_doubleStringSet.Add(2.0005, "2.000500"); + m_doubleStringSet.Add(349485435.6805, "349485435.680500"); + m_doubleStringSet.Add(-548.5, "-548.500000"); + m_doubleStringSet.Add(-2.0005, "-2.000500"); + m_doubleStringSet.Add(-349485435.6805, "-349485435.680500"); + + m_doubleList = new List(); + m_doubleList.Add(2.0); + m_doubleList.Add(-2.0); + m_doubleList.Add(1.0); + m_doubleList.Add(-1.0); + m_doubleList.Add(999999999.0); + m_doubleList.Add(-99999999.0); + m_doubleList.Add(0.5); + m_doubleList.Add(0.0005); + m_doubleList.Add(0.6805); + m_doubleList.Add(-0.5); + m_doubleList.Add(-0.0005); + m_doubleList.Add(-0.6805); + m_doubleList.Add(548.5); + m_doubleList.Add(2.0005); + m_doubleList.Add(349485435.6805); + m_doubleList.Add(-548.5); + m_doubleList.Add(-2.0005); + m_doubleList.Add(-349485435.6805); + + m_intList = new List(); + m_intList.Add(2); + m_intList.Add(-2); + m_intList.Add(0); + m_intList.Add(1); + m_intList.Add(-1); + m_intList.Add(999999999); + m_intList.Add(-99999999); + } + + /// + /// Tests constructing a LSLFloat from an integer. + /// + [Test] + public void TestConstructFromInt() + { + LSL_Types.LSLFloat testFloat; + + foreach (KeyValuePair number in m_intDoubleSet) + { + testFloat = new LSL_Types.LSLFloat(number.Key); + Assert.That(testFloat.value, new DoubleToleranceConstraint(number.Value, _lowPrecisionTolerance)); + } + } + + /// + /// Tests constructing a LSLFloat from a double. + /// + [Test] + public void TestConstructFromDouble() + { + LSL_Types.LSLFloat testFloat; + + foreach (KeyValuePair number in m_doubleDoubleSet) + { + testFloat = new LSL_Types.LSLFloat(number.Key); + Assert.That(testFloat.value, new DoubleToleranceConstraint(number.Value, _lowPrecisionTolerance)); + } + } + + /// + /// Tests LSLFloat is correctly cast implicitly to integer. + /// + [Test] + public void TestImplicitCastLSLFloatToInt() + { + int testNumber; + + foreach (KeyValuePair number in m_doubleIntSet) + { + testNumber = new LSL_Types.LSLFloat(number.Key); + Assert.AreEqual(number.Value, testNumber, "Converting double " + number.Key + ", expecting int " + number.Value); + } + } + + /// + /// Tests LSLFloat is correctly cast implicitly to unsigned integer. + /// + [Test] + public void TestImplicitCastLSLFloatToUint() + { + uint testNumber; + + foreach (KeyValuePair number in m_doubleUintSet) + { + testNumber = new LSL_Types.LSLFloat(number.Key); + Assert.AreEqual(number.Value, testNumber, "Converting double " + number.Key + ", expecting uint " + number.Value); + } + } + + /// + /// Tests LSLFloat is correctly cast implicitly to Boolean if non-zero. + /// + [Test] + public void TestImplicitCastLSLFloatToBooleanTrue() + { + LSL_Types.LSLFloat testFloat; + bool testBool; + + foreach (double number in m_doubleList) + { + testFloat = new LSL_Types.LSLFloat(number); + testBool = testFloat; + + Assert.IsTrue(testBool); + } + } + + /// + /// Tests LSLFloat is correctly cast implicitly to Boolean if zero. + /// + [Test] + public void TestImplicitCastLSLFloatToBooleanFalse() + { + LSL_Types.LSLFloat testFloat = new LSL_Types.LSLFloat(0.0); + bool testBool = testFloat; + + Assert.IsFalse(testBool); + } + + /// + /// Tests integer is correctly cast implicitly to LSLFloat. + /// + [Test] + public void TestImplicitCastIntToLSLFloat() + { + LSL_Types.LSLFloat testFloat; + + foreach (int number in m_intList) + { + testFloat = number; + Assert.That(testFloat.value, new DoubleToleranceConstraint(number, _lowPrecisionTolerance)); + } + } + + /// + /// Tests LSLInteger is correctly cast implicitly to LSLFloat. + /// + [Test] + public void TestImplicitCastLSLIntegerToLSLFloat() + { + LSL_Types.LSLFloat testFloat; + + foreach (int number in m_intList) + { + testFloat = new LSL_Types.LSLInteger(number); + Assert.That(testFloat.value, new DoubleToleranceConstraint(number, _lowPrecisionTolerance)); + } + } + + /// + /// Tests LSLInteger is correctly cast explicitly to LSLFloat. + /// + [Test] + public void TestExplicitCastLSLIntegerToLSLFloat() + { + LSL_Types.LSLFloat testFloat; + + foreach (int number in m_intList) + { + testFloat = (LSL_Types.LSLFloat) new LSL_Types.LSLInteger(number); + Assert.That(testFloat.value, new DoubleToleranceConstraint(number, _lowPrecisionTolerance)); + } + } + + /// + /// Tests string is correctly cast implicitly to LSLFloat. + /// + [Test] + public void TestImplicitCastStringToLSLFloat() + { + LSL_Types.LSLFloat testFloat; + + foreach (KeyValuePair number in m_stringDoubleSet) + { + testFloat = number.Key; + Assert.That(testFloat.value, new DoubleToleranceConstraint(number.Value, _lowPrecisionTolerance)); + } + } + + /// + /// Tests LSLString is correctly cast implicitly to LSLFloat. + /// + [Test] + public void TestExplicitCastLSLStringToLSLFloat() + { + LSL_Types.LSLFloat testFloat; + + foreach (KeyValuePair number in m_stringDoubleSet) + { + testFloat = (LSL_Types.LSLFloat) new LSL_Types.LSLString(number.Key); + Assert.That(testFloat.value, new DoubleToleranceConstraint(number.Value, _lowPrecisionTolerance)); + } + } + + /// + /// Tests double is correctly cast implicitly to LSLFloat. + /// + [Test] + public void TestImplicitCastDoubleToLSLFloat() + { + LSL_Types.LSLFloat testFloat; + + foreach (double number in m_doubleList) + { + testFloat = number; + Assert.That(testFloat.value, new DoubleToleranceConstraint(number, _lowPrecisionTolerance)); + } + } + + /// + /// Tests the equality (==) operator. + /// + [Test] + public void TestEqualsOperator() + { + LSL_Types.LSLFloat testFloatA, testFloatB; + + foreach (double number in m_doubleList) + { + testFloatA = new LSL_Types.LSLFloat(number); + testFloatB = new LSL_Types.LSLFloat(number); + Assert.IsTrue(testFloatA == testFloatB); + + testFloatB = new LSL_Types.LSLFloat(number + 1.0); + Assert.IsFalse(testFloatA == testFloatB); + } + } + + /// + /// Tests the inequality (!=) operator. + /// + [Test] + public void TestNotEqualOperator() + { + LSL_Types.LSLFloat testFloatA, testFloatB; + + foreach (double number in m_doubleList) + { + testFloatA = new LSL_Types.LSLFloat(number); + testFloatB = new LSL_Types.LSLFloat(number + 1.0); + Assert.IsTrue(testFloatA != testFloatB); + + testFloatB = new LSL_Types.LSLFloat(number); + Assert.IsFalse(testFloatA != testFloatB); + } + } + + /// + /// Tests the increment operator. + /// + [Test] + public void TestIncrementOperator() + { + LSL_Types.LSLFloat testFloat; + double testNumber; + + foreach (double number in m_doubleList) + { + testFloat = new LSL_Types.LSLFloat(number); + + testNumber = testFloat++; + Assert.That(testNumber, new DoubleToleranceConstraint(number, _lowPrecisionTolerance)); + + testNumber = testFloat; + Assert.That(testNumber, new DoubleToleranceConstraint(number + 1.0, _lowPrecisionTolerance)); + + testNumber = ++testFloat; + Assert.That(testNumber, new DoubleToleranceConstraint(number + 2.0, _lowPrecisionTolerance)); + } + } + + /// + /// Tests the decrement operator. + /// + [Test] + public void TestDecrementOperator() + { + LSL_Types.LSLFloat testFloat; + double testNumber; + + foreach (double number in m_doubleList) + { + testFloat = new LSL_Types.LSLFloat(number); + + testNumber = testFloat--; + Assert.That(testNumber, new DoubleToleranceConstraint(number, _lowPrecisionTolerance)); + + testNumber = testFloat; + Assert.That(testNumber, new DoubleToleranceConstraint(number - 1.0, _lowPrecisionTolerance)); + + testNumber = --testFloat; + Assert.That(testNumber, new DoubleToleranceConstraint(number - 2.0, _lowPrecisionTolerance)); + } + } + + /// + /// Tests LSLFloat is correctly cast implicitly to double. + /// + [Test] + public void TestImplicitCastLSLFloatToDouble() + { + double testNumber; + LSL_Types.LSLFloat testFloat; + + foreach (double number in m_doubleList) + { + testFloat = new LSL_Types.LSLFloat(number); + testNumber = testFloat; + + Assert.That(testNumber, new DoubleToleranceConstraint(number, _lowPrecisionTolerance)); + } + } + + /// + /// Tests LSLFloat.ToString(). + /// + [Test] + public void TestToString() + { + LSL_Types.LSLFloat testFloat; + + foreach (KeyValuePair number in m_doubleStringSet) + { + testFloat = new LSL_Types.LSLFloat(number.Key); + Assert.AreEqual(number.Value, testFloat.ToString()); + } + } + + /// + /// Tests addition of two LSLFloats. + /// + [Test] + public void TestAddTwoLSLFloats() + { + LSL_Types.LSLFloat testResult; + + foreach (KeyValuePair number in m_doubleDoubleSet) + { + testResult = new LSL_Types.LSLFloat(number.Key) + new LSL_Types.LSLFloat(number.Value); + Assert.That(testResult.value, new DoubleToleranceConstraint(number.Key + number.Value, _lowPrecisionTolerance)); + } + } + + /// + /// Tests subtraction of two LSLFloats. + /// + [Test] + public void TestSubtractTwoLSLFloats() + { + LSL_Types.LSLFloat testResult; + + foreach (KeyValuePair number in m_doubleDoubleSet) + { + testResult = new LSL_Types.LSLFloat(number.Key) - new LSL_Types.LSLFloat(number.Value); + Assert.That(testResult.value, new DoubleToleranceConstraint(number.Key - number.Value, _lowPrecisionTolerance)); + } + } + + /// + /// Tests multiplication of two LSLFloats. + /// + [Test] + public void TestMultiplyTwoLSLFloats() + { + LSL_Types.LSLFloat testResult; + + foreach (KeyValuePair number in m_doubleDoubleSet) + { + testResult = new LSL_Types.LSLFloat(number.Key) * new LSL_Types.LSLFloat(number.Value); + Assert.That(testResult.value, new DoubleToleranceConstraint(number.Key * number.Value, _lowPrecisionTolerance)); + } + } + + /// + /// Tests division of two LSLFloats. + /// + [Test] + public void TestDivideTwoLSLFloats() + { + LSL_Types.LSLFloat testResult; + + foreach (KeyValuePair number in m_doubleDoubleSet) + { + if (number.Value != 0.0) // Let's avoid divide by zero. + { + testResult = new LSL_Types.LSLFloat(number.Key) / new LSL_Types.LSLFloat(number.Value); + Assert.That(testResult.value, new DoubleToleranceConstraint(number.Key / number.Value, _lowPrecisionTolerance)); + } + } + } + } +} 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 0000000000..ceab376ac4 --- /dev/null +++ b/OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/LSL_TypesTestLSLString.cs @@ -0,0 +1,98 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSim Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System.Collections.Generic; +using NUnit.Framework; +using OpenSim.Tests.Common; +using OpenSim.Region.ScriptEngine.Shared; + +namespace OpenSim.Region.ScriptEngine.Shared.Tests +{ + [TestFixture] + public class LSL_TypesTestLSLString + { + private Dictionary m_doubleStringSet; + + /// + /// Sets up dictionaries and arrays used in the tests. + /// + [TestFixtureSetUp] + public void SetUpDataSets() + { + m_doubleStringSet = new Dictionary(); + m_doubleStringSet.Add(2, "2.000000"); + m_doubleStringSet.Add(-2, "-2.000000"); + m_doubleStringSet.Add(0, "0.000000"); + m_doubleStringSet.Add(1, "1.000000"); + m_doubleStringSet.Add(-1, "-1.000000"); + m_doubleStringSet.Add(999999999, "999999999.000000"); + m_doubleStringSet.Add(-99999999, "-99999999.000000"); + m_doubleStringSet.Add(0.5, "0.500000"); + m_doubleStringSet.Add(0.0005, "0.000500"); + m_doubleStringSet.Add(0.6805, "0.680500"); + m_doubleStringSet.Add(-0.5, "-0.500000"); + m_doubleStringSet.Add(-0.0005, "-0.000500"); + m_doubleStringSet.Add(-0.6805, "-0.680500"); + m_doubleStringSet.Add(548.5, "548.500000"); + m_doubleStringSet.Add(2.0005, "2.000500"); + m_doubleStringSet.Add(349485435.6805, "349485435.680500"); + m_doubleStringSet.Add(-548.5, "-548.500000"); + m_doubleStringSet.Add(-2.0005, "-2.000500"); + m_doubleStringSet.Add(-349485435.6805, "-349485435.680500"); + } + + /// + /// Tests constructing a LSLString from an LSLFloat. + /// + [Test] + public void TestConstructFromLSLFloat() + { + LSL_Types.LSLString testString; + + foreach (KeyValuePair number in m_doubleStringSet) + { + testString = new LSL_Types.LSLString(new LSL_Types.LSLFloat(number.Key)); + Assert.AreEqual(number.Value, testString.m_string); + } + } + + /// + /// Tests constructing a LSLString from an LSLFloat. + /// + [Test] + public void TestExplicitCastLSLFloatToLSLString() + { + LSL_Types.LSLString testString; + + foreach (KeyValuePair number in m_doubleStringSet) + { + testString = (LSL_Types.LSLString) new LSL_Types.LSLFloat(number.Key); + Assert.AreEqual(number.Value, testString.m_string); + } + } + } +} 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 0000000000..c1c9ef77c1 --- /dev/null +++ b/OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/LSL_TypesTestList.cs @@ -0,0 +1,101 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSim Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System.Collections.Generic; +using NUnit.Framework; +using OpenSim.Tests.Common; +using OpenSim.Region.ScriptEngine.Shared; + +namespace OpenSim.Region.ScriptEngine.Shared.Tests +{ + /// + /// Tests the LSL_Types.list class. + /// + [TestFixture] + public class LSL_TypesTestList + { + /// + /// Tests concatenating a string to a list. + /// + [Test] + public void TestConcatenateString() + { + LSL_Types.list testList = new LSL_Types.list(1, 'a', "test"); + testList += "addition"; + + Assert.AreEqual(4, testList.Length); + Assert.AreEqual("addition", testList.Data[3]); + Assert.AreEqual(typeof(System.String), testList.Data[3].GetType()); + + LSL_Types.list secondTestList = testList + "more"; + + Assert.AreEqual(5, secondTestList.Length); + Assert.AreEqual("more", secondTestList.Data[4]); + Assert.AreEqual(typeof(System.String), secondTestList.Data[4].GetType()); + } + + /// + /// Tests concatenating an integer to a list. + /// + [Test] + public void TestConcatenateInteger() + { + LSL_Types.list testList = new LSL_Types.list(1, 'a', "test"); + testList += 20; + + Assert.AreEqual(4, testList.Length); + Assert.AreEqual(20, testList.Data[3]); + Assert.AreEqual(typeof(int), testList.Data[3].GetType()); + + LSL_Types.list secondTestList = testList + 2; + + Assert.AreEqual(5, secondTestList.Length); + Assert.AreEqual(2, secondTestList.Data[4]); + Assert.AreEqual(typeof(int), secondTestList.Data[4].GetType()); + } + + /// + /// Tests concatenating a double to a list. + /// + [Test] + public void TestConcatenateDouble() + { + LSL_Types.list testList = new LSL_Types.list(1, 'a', "test"); + testList += 2.0; + + Assert.AreEqual(4, testList.Length); + Assert.AreEqual(2.0, testList.Data[3]); + Assert.AreEqual(typeof(double), testList.Data[3].GetType()); + + LSL_Types.list secondTestList = testList + 0.04; + + Assert.AreEqual(5, secondTestList.Length); + Assert.AreEqual(0.04, secondTestList.Data[4]); + Assert.AreEqual(typeof(double), secondTestList.Data[4].GetType()); + } + } +} 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 0000000000..fb2c00cb2a --- /dev/null +++ b/OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/LSL_TypesTestVector3.cs @@ -0,0 +1,62 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSim Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System.Collections.Generic; +using NUnit.Framework; +using OpenSim.Tests.Common; +using OpenSim.Region.ScriptEngine.Shared; + +namespace OpenSim.Region.ScriptEngine.Shared.Tests +{ + [TestFixture] + public class LSL_TypesTestVector3 + { + /// + /// Tests for Vector3 + /// + [Test] + + public void TestDotProduct() + { + // The numbers we test for. + Dictionary expectsSet = new Dictionary(); + expectsSet.Add("<1, 2, 3> * <2, 3, 4>", 20.0); + expectsSet.Add("<1, 2, 3> * <0, 0, 0>", 0.0); + + double result; + string[] parts; + string[] delim = { "*" }; + + foreach (KeyValuePair ex in expectsSet) + { + parts = ex.Key.Split(delim, System.StringSplitOptions.None); + result = new LSL_Types.Vector3(parts[0]) * new LSL_Types.Vector3(parts[1]); + Assert.AreEqual(ex.Value, result); + } + } + } +} diff --git a/prebuild.xml b/prebuild.xml index c98fd1754e..94412561b3 100644 --- a/prebuild.xml +++ b/prebuild.xml @@ -1487,6 +1487,28 @@ + + + + ../../../../../../bin/ + + + + + ../../../../../../bin/ + + + + ../../../../../../bin/ + + + + + + + + +