update eol-style

ThreadPoolClientBranch
Justin Clarke Casey 2008-02-08 18:18:56 +00:00
parent 23e0ef3492
commit 24ac86931a
5 changed files with 280 additions and 280 deletions

View File

@ -1,30 +1,30 @@
using System; using System;
using NUnit.Framework.Constraints; using NUnit.Framework.Constraints;
namespace OpenSim.Tests.Common namespace OpenSim.Tests.Common
{ {
public abstract class ANumericalToleranceConstraint : Constraint public abstract class ANumericalToleranceConstraint : Constraint
{ {
protected double _tolerance; protected double _tolerance;
public ANumericalToleranceConstraint(double tolerance) public ANumericalToleranceConstraint(double tolerance)
{ {
if (tolerance < 0) if (tolerance < 0)
{ {
throw new ArgumentException("Tolerance cannot be negative."); throw new ArgumentException("Tolerance cannot be negative.");
} }
_tolerance = tolerance; _tolerance = tolerance;
} }
protected bool IsWithinDoubleConstraint(double doubleValue, double baseValue) protected bool IsWithinDoubleConstraint(double doubleValue, double baseValue)
{ {
if (doubleValue >= baseValue - _tolerance && doubleValue <= baseValue + _tolerance) if (doubleValue >= baseValue - _tolerance && doubleValue <= baseValue + _tolerance)
{ {
return true; return true;
} }
return false; return false;
} }
} }
} }

View File

@ -1,52 +1,52 @@
using System; using System;
using NUnit.Framework; using NUnit.Framework;
using NUnit.Framework.Constraints; using NUnit.Framework.Constraints;
using OpenSim.Tests.Common; using OpenSim.Tests.Common;
namespace OpenSim.Tests.Common namespace OpenSim.Tests.Common
{ {
public class DoubleToleranceConstraint : ANumericalToleranceConstraint public class DoubleToleranceConstraint : ANumericalToleranceConstraint
{ {
private double _baseValue; private double _baseValue;
private double _valueToBeTested; private double _valueToBeTested;
public DoubleToleranceConstraint(double baseValue, double tolerance) : base(tolerance) public DoubleToleranceConstraint(double baseValue, double tolerance) : base(tolerance)
{ {
_baseValue = baseValue; _baseValue = baseValue;
} }
///<summary> ///<summary>
///Test whether the constraint is satisfied by a given value ///Test whether the constraint is satisfied by a given value
///</summary> ///</summary>
///<param name="valueToBeTested">The value to be tested</param> ///<param name="valueToBeTested">The value to be tested</param>
///<returns> ///<returns>
///True for success, false for failure ///True for success, false for failure
///</returns> ///</returns>
public override bool Matches(object valueToBeTested) public override bool Matches(object valueToBeTested)
{ {
if (valueToBeTested == null) if (valueToBeTested == null)
{ {
throw new ArgumentException("Constraint cannot be used upon null values."); throw new ArgumentException("Constraint cannot be used upon null values.");
} }
if( valueToBeTested.GetType() != typeof(double)) if( valueToBeTested.GetType() != typeof(double))
{ {
throw new ArgumentException("Constraint cannot be used upon non double-values."); throw new ArgumentException("Constraint cannot be used upon non double-values.");
} }
_valueToBeTested = (double)valueToBeTested; _valueToBeTested = (double)valueToBeTested;
return IsWithinDoubleConstraint(_valueToBeTested, _baseValue ); return IsWithinDoubleConstraint(_valueToBeTested, _baseValue );
} }
public override void WriteDescriptionTo(MessageWriter writer) public override void WriteDescriptionTo(MessageWriter writer)
{ {
writer.WriteExpectedValue(string.Format("A value {0} within tolerance of plus or minus {1}",_baseValue,_tolerance)); writer.WriteExpectedValue(string.Format("A value {0} within tolerance of plus or minus {1}",_baseValue,_tolerance));
} }
public override void WriteActualValueTo(MessageWriter writer) public override void WriteActualValueTo(MessageWriter writer)
{ {
writer.WriteActualValue(_valueToBeTested); writer.WriteActualValue(_valueToBeTested);
} }
} }
} }

View File

@ -1,25 +1,25 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
namespace OpenSim.Tests.Common namespace OpenSim.Tests.Common
{ {
public delegate void TestDelegate(); public delegate void TestDelegate();
public class TestHelper public class TestHelper
{ {
public static bool AssertThisDelegateCausesArgumentException(TestDelegate d) public static bool AssertThisDelegateCausesArgumentException(TestDelegate d)
{ {
try try
{ {
d(); d();
} }
catch(ArgumentException e) catch(ArgumentException e)
{ {
return true; return true;
} }
return false; return false;
} }
} }
} }

View File

@ -1,58 +1,58 @@
using System; using System;
using libsecondlife; using libsecondlife;
using NUnit.Framework; using NUnit.Framework;
namespace OpenSim.Tests.Common namespace OpenSim.Tests.Common
{ {
public class VectorToleranceConstraint : ANumericalToleranceConstraint public class VectorToleranceConstraint : ANumericalToleranceConstraint
{ {
private LLVector3 _baseValue; private LLVector3 _baseValue;
private LLVector3 _valueToBeTested; private LLVector3 _valueToBeTested;
public VectorToleranceConstraint(LLVector3 baseValue, double tolerance) : base(tolerance) public VectorToleranceConstraint(LLVector3 baseValue, double tolerance) : base(tolerance)
{ {
_baseValue = baseValue; _baseValue = baseValue;
} }
///<summary> ///<summary>
///Test whether the constraint is satisfied by a given value ///Test whether the constraint is satisfied by a given value
///</summary> ///</summary>
///<param name="valueToBeTested">The value to be tested</param> ///<param name="valueToBeTested">The value to be tested</param>
///<returns> ///<returns>
///True for success, false for failure ///True for success, false for failure
///</returns> ///</returns>
public override bool Matches(object valueToBeTested) public override bool Matches(object valueToBeTested)
{ {
if (valueToBeTested == null) if (valueToBeTested == null)
{ {
throw new ArgumentException("Constraint cannot be used upon null values."); throw new ArgumentException("Constraint cannot be used upon null values.");
} }
if (valueToBeTested.GetType() != typeof (LLVector3)) if (valueToBeTested.GetType() != typeof (LLVector3))
{ {
throw new ArgumentException("Constraint cannot be used upon non vector values."); throw new ArgumentException("Constraint cannot be used upon non vector values.");
} }
_valueToBeTested = (LLVector3) valueToBeTested; _valueToBeTested = (LLVector3) valueToBeTested;
if ( IsWithinDoubleConstraint(_valueToBeTested.X,_baseValue.X) && if ( IsWithinDoubleConstraint(_valueToBeTested.X,_baseValue.X) &&
IsWithinDoubleConstraint(_valueToBeTested.Y,_baseValue.Y) && IsWithinDoubleConstraint(_valueToBeTested.Y,_baseValue.Y) &&
IsWithinDoubleConstraint(_valueToBeTested.Z,_baseValue.Z) ) IsWithinDoubleConstraint(_valueToBeTested.Z,_baseValue.Z) )
{ {
return true; return true;
} }
return false; return false;
} }
public override void WriteDescriptionTo(MessageWriter writer) public override void WriteDescriptionTo(MessageWriter writer)
{ {
writer.WriteExpectedValue( writer.WriteExpectedValue(
string.Format("A value {0} within tolerance of plus or minus {1}", _baseValue, _tolerance)); string.Format("A value {0} within tolerance of plus or minus {1}", _baseValue, _tolerance));
} }
public override void WriteActualValueTo(MessageWriter writer) public override void WriteActualValueTo(MessageWriter writer)
{ {
writer.WriteActualValue(_valueToBeTested); writer.WriteActualValue(_valueToBeTested);
} }
} }
} }

View File

@ -1,115 +1,115 @@
using libsecondlife; using libsecondlife;
using NUnit.Framework; using NUnit.Framework;
using NUnit.Framework.SyntaxHelpers; using NUnit.Framework.SyntaxHelpers;
using OpenSim.Tests.Common; using OpenSim.Tests.Common;
namespace OpenSim.Framework.Tests namespace OpenSim.Framework.Tests
{ {
[TestFixture] [TestFixture]
public class UtilTests public class UtilTests
{ {
[Test] [Test]
public void VectorOperationTests() public void VectorOperationTests()
{ {
LLVector3 v1, v2; LLVector3 v1, v2;
double expectedDistance; double expectedDistance;
double expectedMagnitude; double expectedMagnitude;
double lowPrecisionTolerance = 0.001; double lowPrecisionTolerance = 0.001;
//Lets test a simple case of <0,0,0> and <5,5,5> //Lets test a simple case of <0,0,0> and <5,5,5>
{ {
v1 = new LLVector3(0, 0, 0); v1 = new LLVector3(0, 0, 0);
v2 = new LLVector3(5, 5, 5); v2 = new LLVector3(5, 5, 5);
expectedDistance = 8.66; expectedDistance = 8.66;
Assert.That(Util.GetDistanceTo(v1, v2), Assert.That(Util.GetDistanceTo(v1, v2),
new DoubleToleranceConstraint(expectedDistance, lowPrecisionTolerance), new DoubleToleranceConstraint(expectedDistance, lowPrecisionTolerance),
"Calculated distance between two vectors was not within tolerances."); "Calculated distance between two vectors was not within tolerances.");
expectedMagnitude = 0; expectedMagnitude = 0;
Assert.That(Util.GetMagnitude(v1), Is.EqualTo(0), "Magnitude of null vector was not zero."); Assert.That(Util.GetMagnitude(v1), Is.EqualTo(0), "Magnitude of null vector was not zero.");
expectedMagnitude = 8.66; expectedMagnitude = 8.66;
Assert.That(Util.GetMagnitude(v2), Assert.That(Util.GetMagnitude(v2),
new DoubleToleranceConstraint(expectedMagnitude, lowPrecisionTolerance), new DoubleToleranceConstraint(expectedMagnitude, lowPrecisionTolerance),
"Magnitude of vector was incorrect."); "Magnitude of vector was incorrect.");
TestDelegate d = delegate() { Util.GetNormalizedVector(v1); }; TestDelegate d = delegate() { Util.GetNormalizedVector(v1); };
bool causesArgumentException = TestHelper.AssertThisDelegateCausesArgumentException(d); bool causesArgumentException = TestHelper.AssertThisDelegateCausesArgumentException(d);
Assert.That(causesArgumentException, Is.True, Assert.That(causesArgumentException, Is.True,
"Getting magnitude of null vector did not cause argument exception."); "Getting magnitude of null vector did not cause argument exception.");
LLVector3 expectedNormalizedVector = new LLVector3(.577f, .577f, .577f); LLVector3 expectedNormalizedVector = new LLVector3(.577f, .577f, .577f);
double expectedNormalizedMagnitude = 1; double expectedNormalizedMagnitude = 1;
LLVector3 normalizedVector = Util.GetNormalizedVector(v2); LLVector3 normalizedVector = Util.GetNormalizedVector(v2);
Assert.That(normalizedVector, Assert.That(normalizedVector,
new VectorToleranceConstraint(expectedNormalizedVector, lowPrecisionTolerance), new VectorToleranceConstraint(expectedNormalizedVector, lowPrecisionTolerance),
"Normalized vector generated from vector was not what was expected."); "Normalized vector generated from vector was not what was expected.");
Assert.That(Util.GetMagnitude(normalizedVector), Assert.That(Util.GetMagnitude(normalizedVector),
new DoubleToleranceConstraint(expectedNormalizedMagnitude, lowPrecisionTolerance), new DoubleToleranceConstraint(expectedNormalizedMagnitude, lowPrecisionTolerance),
"Normalized vector generated from vector does not have magnitude of 1."); "Normalized vector generated from vector does not have magnitude of 1.");
} }
//Lets test a simple case of <0,0,0> and <0,0,0> //Lets test a simple case of <0,0,0> and <0,0,0>
{ {
v1 = new LLVector3(0, 0, 0); v1 = new LLVector3(0, 0, 0);
v2 = new LLVector3(0, 0, 0); v2 = new LLVector3(0, 0, 0);
expectedDistance = 0; expectedDistance = 0;
Assert.That(Util.GetDistanceTo(v1, v2), Assert.That(Util.GetDistanceTo(v1, v2),
new DoubleToleranceConstraint(expectedDistance, lowPrecisionTolerance), new DoubleToleranceConstraint(expectedDistance, lowPrecisionTolerance),
"Calculated distance between two vectors was not within tolerances."); "Calculated distance between two vectors was not within tolerances.");
expectedMagnitude = 0; expectedMagnitude = 0;
Assert.That(Util.GetMagnitude(v1), Is.EqualTo(0), "Magnitude of null vector was not zero."); Assert.That(Util.GetMagnitude(v1), Is.EqualTo(0), "Magnitude of null vector was not zero.");
expectedMagnitude = 0; expectedMagnitude = 0;
Assert.That(Util.GetMagnitude(v2), Assert.That(Util.GetMagnitude(v2),
new DoubleToleranceConstraint(expectedMagnitude, lowPrecisionTolerance), new DoubleToleranceConstraint(expectedMagnitude, lowPrecisionTolerance),
"Magnitude of vector was incorrect."); "Magnitude of vector was incorrect.");
TestDelegate d = delegate() { Util.GetNormalizedVector(v1); }; TestDelegate d = delegate() { Util.GetNormalizedVector(v1); };
bool causesArgumentException = TestHelper.AssertThisDelegateCausesArgumentException(d); bool causesArgumentException = TestHelper.AssertThisDelegateCausesArgumentException(d);
Assert.That(causesArgumentException, Is.True, Assert.That(causesArgumentException, Is.True,
"Getting magnitude of null vector did not cause argument exception."); "Getting magnitude of null vector did not cause argument exception.");
d = delegate() { Util.GetNormalizedVector(v2); }; d = delegate() { Util.GetNormalizedVector(v2); };
causesArgumentException = TestHelper.AssertThisDelegateCausesArgumentException(d); causesArgumentException = TestHelper.AssertThisDelegateCausesArgumentException(d);
Assert.That(causesArgumentException, Is.True, Assert.That(causesArgumentException, Is.True,
"Getting magnitude of null vector did not cause argument exception."); "Getting magnitude of null vector did not cause argument exception.");
} }
//Lets test a simple case of <0,0,0> and <-5,-5,-5> //Lets test a simple case of <0,0,0> and <-5,-5,-5>
{ {
v1 = new LLVector3(0, 0, 0); v1 = new LLVector3(0, 0, 0);
v2 = new LLVector3(-5, -5, -5); v2 = new LLVector3(-5, -5, -5);
expectedDistance = 8.66; expectedDistance = 8.66;
Assert.That(Util.GetDistanceTo(v1, v2), Assert.That(Util.GetDistanceTo(v1, v2),
new DoubleToleranceConstraint(expectedDistance, lowPrecisionTolerance), new DoubleToleranceConstraint(expectedDistance, lowPrecisionTolerance),
"Calculated distance between two vectors was not within tolerances."); "Calculated distance between two vectors was not within tolerances.");
expectedMagnitude = 0; expectedMagnitude = 0;
Assert.That(Util.GetMagnitude(v1), Is.EqualTo(0), "Magnitude of null vector was not zero."); Assert.That(Util.GetMagnitude(v1), Is.EqualTo(0), "Magnitude of null vector was not zero.");
expectedMagnitude = 8.66; expectedMagnitude = 8.66;
Assert.That(Util.GetMagnitude(v2), Assert.That(Util.GetMagnitude(v2),
new DoubleToleranceConstraint(expectedMagnitude, lowPrecisionTolerance), new DoubleToleranceConstraint(expectedMagnitude, lowPrecisionTolerance),
"Magnitude of vector was incorrect."); "Magnitude of vector was incorrect.");
TestDelegate d = delegate() { Util.GetNormalizedVector(v1); }; TestDelegate d = delegate() { Util.GetNormalizedVector(v1); };
bool causesArgumentException = TestHelper.AssertThisDelegateCausesArgumentException(d); bool causesArgumentException = TestHelper.AssertThisDelegateCausesArgumentException(d);
Assert.That(causesArgumentException, Is.True, Assert.That(causesArgumentException, Is.True,
"Getting magnitude of null vector did not cause argument exception."); "Getting magnitude of null vector did not cause argument exception.");
LLVector3 expectedNormalizedVector = new LLVector3(-.577f, -.577f, -.577f); LLVector3 expectedNormalizedVector = new LLVector3(-.577f, -.577f, -.577f);
double expectedNormalizedMagnitude = 1; double expectedNormalizedMagnitude = 1;
LLVector3 normalizedVector = Util.GetNormalizedVector(v2); LLVector3 normalizedVector = Util.GetNormalizedVector(v2);
Assert.That(normalizedVector, Assert.That(normalizedVector,
new VectorToleranceConstraint(expectedNormalizedVector, lowPrecisionTolerance), new VectorToleranceConstraint(expectedNormalizedVector, lowPrecisionTolerance),
"Normalized vector generated from vector was not what was expected."); "Normalized vector generated from vector was not what was expected.");
Assert.That(Util.GetMagnitude(normalizedVector), Assert.That(Util.GetMagnitude(normalizedVector),
new DoubleToleranceConstraint(expectedNormalizedMagnitude, lowPrecisionTolerance), new DoubleToleranceConstraint(expectedNormalizedMagnitude, lowPrecisionTolerance),
"Normalized vector generated from vector does not have magnitude of 1."); "Normalized vector generated from vector does not have magnitude of 1.");
} }
} }
} }
} }