aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Tests
diff options
context:
space:
mode:
authorJustin Clarke Casey2008-02-08 18:18:56 +0000
committerJustin Clarke Casey2008-02-08 18:18:56 +0000
commit24ac86931a79b3968c5c6c00f93bb92bf967ea75 (patch)
treefbc90f13b13a3e7024ab92f3238746da85f3ae62 /OpenSim/Tests
parent* Made some terrain functions faster computationally. (diff)
downloadopensim-SC-24ac86931a79b3968c5c6c00f93bb92bf967ea75.zip
opensim-SC-24ac86931a79b3968c5c6c00f93bb92bf967ea75.tar.gz
opensim-SC-24ac86931a79b3968c5c6c00f93bb92bf967ea75.tar.bz2
opensim-SC-24ac86931a79b3968c5c6c00f93bb92bf967ea75.tar.xz
update eol-style
Diffstat (limited to 'OpenSim/Tests')
-rw-r--r--OpenSim/Tests/Common/ANumericalToleranceConstraint.cs60
-rw-r--r--OpenSim/Tests/Common/DoubleToleranceConstraint.cs104
-rw-r--r--OpenSim/Tests/Common/TestHelper.cs50
-rw-r--r--OpenSim/Tests/Common/VectorToleranceConstraint.cs116
-rw-r--r--OpenSim/Tests/OpenSim/Framework/UtilTest.cs230
5 files changed, 280 insertions, 280 deletions
diff --git a/OpenSim/Tests/Common/ANumericalToleranceConstraint.cs b/OpenSim/Tests/Common/ANumericalToleranceConstraint.cs
index 289e4bb..2a6993d 100644
--- a/OpenSim/Tests/Common/ANumericalToleranceConstraint.cs
+++ b/OpenSim/Tests/Common/ANumericalToleranceConstraint.cs
@@ -1,30 +1,30 @@
1using System; 1using System;
2using NUnit.Framework.Constraints; 2using NUnit.Framework.Constraints;
3 3
4namespace OpenSim.Tests.Common 4namespace OpenSim.Tests.Common
5{ 5{
6 public abstract class ANumericalToleranceConstraint : Constraint 6 public abstract class ANumericalToleranceConstraint : Constraint
7 { 7 {
8 protected double _tolerance; 8 protected double _tolerance;
9 9
10 public ANumericalToleranceConstraint(double tolerance) 10 public ANumericalToleranceConstraint(double tolerance)
11 { 11 {
12 if (tolerance < 0) 12 if (tolerance < 0)
13 { 13 {
14 throw new ArgumentException("Tolerance cannot be negative."); 14 throw new ArgumentException("Tolerance cannot be negative.");
15 } 15 }
16 _tolerance = tolerance; 16 _tolerance = tolerance;
17 } 17 }
18 18
19 19
20 protected bool IsWithinDoubleConstraint(double doubleValue, double baseValue) 20 protected bool IsWithinDoubleConstraint(double doubleValue, double baseValue)
21 { 21 {
22 if (doubleValue >= baseValue - _tolerance && doubleValue <= baseValue + _tolerance) 22 if (doubleValue >= baseValue - _tolerance && doubleValue <= baseValue + _tolerance)
23 { 23 {
24 return true; 24 return true;
25 } 25 }
26 26
27 return false; 27 return false;
28 } 28 }
29 } 29 }
30} 30}
diff --git a/OpenSim/Tests/Common/DoubleToleranceConstraint.cs b/OpenSim/Tests/Common/DoubleToleranceConstraint.cs
index f3da236..eb71aeb 100644
--- a/OpenSim/Tests/Common/DoubleToleranceConstraint.cs
+++ b/OpenSim/Tests/Common/DoubleToleranceConstraint.cs
@@ -1,52 +1,52 @@
1using System; 1using System;
2using NUnit.Framework; 2using NUnit.Framework;
3using NUnit.Framework.Constraints; 3using NUnit.Framework.Constraints;
4using OpenSim.Tests.Common; 4using OpenSim.Tests.Common;
5 5
6namespace OpenSim.Tests.Common 6namespace OpenSim.Tests.Common
7{ 7{
8 public class DoubleToleranceConstraint : ANumericalToleranceConstraint 8 public class DoubleToleranceConstraint : ANumericalToleranceConstraint
9 { 9 {
10 10
11 private double _baseValue; 11 private double _baseValue;
12 private double _valueToBeTested; 12 private double _valueToBeTested;
13 13
14 public DoubleToleranceConstraint(double baseValue, double tolerance) : base(tolerance) 14 public DoubleToleranceConstraint(double baseValue, double tolerance) : base(tolerance)
15 { 15 {
16 _baseValue = baseValue; 16 _baseValue = baseValue;
17 } 17 }
18 18
19 ///<summary> 19 ///<summary>
20 ///Test whether the constraint is satisfied by a given value 20 ///Test whether the constraint is satisfied by a given value
21 ///</summary> 21 ///</summary>
22 ///<param name="valueToBeTested">The value to be tested</param> 22 ///<param name="valueToBeTested">The value to be tested</param>
23 ///<returns> 23 ///<returns>
24 ///True for success, false for failure 24 ///True for success, false for failure
25 ///</returns> 25 ///</returns>
26 public override bool Matches(object valueToBeTested) 26 public override bool Matches(object valueToBeTested)
27 { 27 {
28 if (valueToBeTested == null) 28 if (valueToBeTested == null)
29 { 29 {
30 throw new ArgumentException("Constraint cannot be used upon null values."); 30 throw new ArgumentException("Constraint cannot be used upon null values.");
31 } 31 }
32 if( valueToBeTested.GetType() != typeof(double)) 32 if( valueToBeTested.GetType() != typeof(double))
33 { 33 {
34 throw new ArgumentException("Constraint cannot be used upon non double-values."); 34 throw new ArgumentException("Constraint cannot be used upon non double-values.");
35 } 35 }
36 36
37 _valueToBeTested = (double)valueToBeTested; 37 _valueToBeTested = (double)valueToBeTested;
38 38
39 return IsWithinDoubleConstraint(_valueToBeTested, _baseValue ); 39 return IsWithinDoubleConstraint(_valueToBeTested, _baseValue );
40 } 40 }
41 41
42 public override void WriteDescriptionTo(MessageWriter writer) 42 public override void WriteDescriptionTo(MessageWriter writer)
43 { 43 {
44 writer.WriteExpectedValue(string.Format("A value {0} within tolerance of plus or minus {1}",_baseValue,_tolerance)); 44 writer.WriteExpectedValue(string.Format("A value {0} within tolerance of plus or minus {1}",_baseValue,_tolerance));
45 } 45 }
46 46
47 public override void WriteActualValueTo(MessageWriter writer) 47 public override void WriteActualValueTo(MessageWriter writer)
48 { 48 {
49 writer.WriteActualValue(_valueToBeTested); 49 writer.WriteActualValue(_valueToBeTested);
50 } 50 }
51 } 51 }
52} 52}
diff --git a/OpenSim/Tests/Common/TestHelper.cs b/OpenSim/Tests/Common/TestHelper.cs
index f59c157..9dc6aa7 100644
--- a/OpenSim/Tests/Common/TestHelper.cs
+++ b/OpenSim/Tests/Common/TestHelper.cs
@@ -1,25 +1,25 @@
1using System; 1using System;
2using System.Collections.Generic; 2using System.Collections.Generic;
3using System.Text; 3using System.Text;
4 4
5namespace OpenSim.Tests.Common 5namespace OpenSim.Tests.Common
6{ 6{
7 public delegate void TestDelegate(); 7 public delegate void TestDelegate();
8 8
9 public class TestHelper 9 public class TestHelper
10 { 10 {
11 public static bool AssertThisDelegateCausesArgumentException(TestDelegate d) 11 public static bool AssertThisDelegateCausesArgumentException(TestDelegate d)
12 { 12 {
13 try 13 try
14 { 14 {
15 d(); 15 d();
16 } 16 }
17 catch(ArgumentException e) 17 catch(ArgumentException e)
18 { 18 {
19 return true; 19 return true;
20 } 20 }
21 21
22 return false; 22 return false;
23 } 23 }
24 } 24 }
25} 25}
diff --git a/OpenSim/Tests/Common/VectorToleranceConstraint.cs b/OpenSim/Tests/Common/VectorToleranceConstraint.cs
index 1faf7dd..3f32830 100644
--- a/OpenSim/Tests/Common/VectorToleranceConstraint.cs
+++ b/OpenSim/Tests/Common/VectorToleranceConstraint.cs
@@ -1,58 +1,58 @@
1using System; 1using System;
2using libsecondlife; 2using libsecondlife;
3using NUnit.Framework; 3using NUnit.Framework;
4 4
5namespace OpenSim.Tests.Common 5namespace OpenSim.Tests.Common
6{ 6{
7 public class VectorToleranceConstraint : ANumericalToleranceConstraint 7 public class VectorToleranceConstraint : ANumericalToleranceConstraint
8 { 8 {
9 private LLVector3 _baseValue; 9 private LLVector3 _baseValue;
10 private LLVector3 _valueToBeTested; 10 private LLVector3 _valueToBeTested;
11 11
12 public VectorToleranceConstraint(LLVector3 baseValue, double tolerance) : base(tolerance) 12 public VectorToleranceConstraint(LLVector3 baseValue, double tolerance) : base(tolerance)
13 { 13 {
14 _baseValue = baseValue; 14 _baseValue = baseValue;
15 } 15 }
16 16
17 ///<summary> 17 ///<summary>
18 ///Test whether the constraint is satisfied by a given value 18 ///Test whether the constraint is satisfied by a given value
19 ///</summary> 19 ///</summary>
20 ///<param name="valueToBeTested">The value to be tested</param> 20 ///<param name="valueToBeTested">The value to be tested</param>
21 ///<returns> 21 ///<returns>
22 ///True for success, false for failure 22 ///True for success, false for failure
23 ///</returns> 23 ///</returns>
24 public override bool Matches(object valueToBeTested) 24 public override bool Matches(object valueToBeTested)
25 { 25 {
26 if (valueToBeTested == null) 26 if (valueToBeTested == null)
27 { 27 {
28 throw new ArgumentException("Constraint cannot be used upon null values."); 28 throw new ArgumentException("Constraint cannot be used upon null values.");
29 } 29 }
30 if (valueToBeTested.GetType() != typeof (LLVector3)) 30 if (valueToBeTested.GetType() != typeof (LLVector3))
31 { 31 {
32 throw new ArgumentException("Constraint cannot be used upon non vector values."); 32 throw new ArgumentException("Constraint cannot be used upon non vector values.");
33 } 33 }
34 34
35 _valueToBeTested = (LLVector3) valueToBeTested; 35 _valueToBeTested = (LLVector3) valueToBeTested;
36 36
37 if ( IsWithinDoubleConstraint(_valueToBeTested.X,_baseValue.X) && 37 if ( IsWithinDoubleConstraint(_valueToBeTested.X,_baseValue.X) &&
38 IsWithinDoubleConstraint(_valueToBeTested.Y,_baseValue.Y) && 38 IsWithinDoubleConstraint(_valueToBeTested.Y,_baseValue.Y) &&
39 IsWithinDoubleConstraint(_valueToBeTested.Z,_baseValue.Z) ) 39 IsWithinDoubleConstraint(_valueToBeTested.Z,_baseValue.Z) )
40 { 40 {
41 return true; 41 return true;
42 } 42 }
43 43
44 return false; 44 return false;
45 } 45 }
46 46
47 public override void WriteDescriptionTo(MessageWriter writer) 47 public override void WriteDescriptionTo(MessageWriter writer)
48 { 48 {
49 writer.WriteExpectedValue( 49 writer.WriteExpectedValue(
50 string.Format("A value {0} within tolerance of plus or minus {1}", _baseValue, _tolerance)); 50 string.Format("A value {0} within tolerance of plus or minus {1}", _baseValue, _tolerance));
51 } 51 }
52 52
53 public override void WriteActualValueTo(MessageWriter writer) 53 public override void WriteActualValueTo(MessageWriter writer)
54 { 54 {
55 writer.WriteActualValue(_valueToBeTested); 55 writer.WriteActualValue(_valueToBeTested);
56 } 56 }
57 } 57 }
58} 58}
diff --git a/OpenSim/Tests/OpenSim/Framework/UtilTest.cs b/OpenSim/Tests/OpenSim/Framework/UtilTest.cs
index ef42eee..8aaacc6 100644
--- a/OpenSim/Tests/OpenSim/Framework/UtilTest.cs
+++ b/OpenSim/Tests/OpenSim/Framework/UtilTest.cs
@@ -1,115 +1,115 @@
1using libsecondlife; 1using libsecondlife;
2using NUnit.Framework; 2using NUnit.Framework;
3using NUnit.Framework.SyntaxHelpers; 3using NUnit.Framework.SyntaxHelpers;
4 4
5using OpenSim.Tests.Common; 5using OpenSim.Tests.Common;
6 6
7namespace OpenSim.Framework.Tests 7namespace OpenSim.Framework.Tests
8{ 8{
9 [TestFixture] 9 [TestFixture]
10 public class UtilTests 10 public class UtilTests
11 { 11 {
12 [Test] 12 [Test]
13 public void VectorOperationTests() 13 public void VectorOperationTests()
14 { 14 {
15 LLVector3 v1, v2; 15 LLVector3 v1, v2;
16 double expectedDistance; 16 double expectedDistance;
17 double expectedMagnitude; 17 double expectedMagnitude;
18 double lowPrecisionTolerance = 0.001; 18 double lowPrecisionTolerance = 0.001;
19 19
20 //Lets test a simple case of <0,0,0> and <5,5,5> 20 //Lets test a simple case of <0,0,0> and <5,5,5>
21 { 21 {
22 v1 = new LLVector3(0, 0, 0); 22 v1 = new LLVector3(0, 0, 0);
23 v2 = new LLVector3(5, 5, 5); 23 v2 = new LLVector3(5, 5, 5);
24 expectedDistance = 8.66; 24 expectedDistance = 8.66;
25 Assert.That(Util.GetDistanceTo(v1, v2), 25 Assert.That(Util.GetDistanceTo(v1, v2),
26 new DoubleToleranceConstraint(expectedDistance, lowPrecisionTolerance), 26 new DoubleToleranceConstraint(expectedDistance, lowPrecisionTolerance),
27 "Calculated distance between two vectors was not within tolerances."); 27 "Calculated distance between two vectors was not within tolerances.");
28 28
29 expectedMagnitude = 0; 29 expectedMagnitude = 0;
30 Assert.That(Util.GetMagnitude(v1), Is.EqualTo(0), "Magnitude of null vector was not zero."); 30 Assert.That(Util.GetMagnitude(v1), Is.EqualTo(0), "Magnitude of null vector was not zero.");
31 31
32 expectedMagnitude = 8.66; 32 expectedMagnitude = 8.66;
33 Assert.That(Util.GetMagnitude(v2), 33 Assert.That(Util.GetMagnitude(v2),
34 new DoubleToleranceConstraint(expectedMagnitude, lowPrecisionTolerance), 34 new DoubleToleranceConstraint(expectedMagnitude, lowPrecisionTolerance),
35 "Magnitude of vector was incorrect."); 35 "Magnitude of vector was incorrect.");
36 36
37 TestDelegate d = delegate() { Util.GetNormalizedVector(v1); }; 37 TestDelegate d = delegate() { Util.GetNormalizedVector(v1); };
38 bool causesArgumentException = TestHelper.AssertThisDelegateCausesArgumentException(d); 38 bool causesArgumentException = TestHelper.AssertThisDelegateCausesArgumentException(d);
39 Assert.That(causesArgumentException, Is.True, 39 Assert.That(causesArgumentException, Is.True,
40 "Getting magnitude of null vector did not cause argument exception."); 40 "Getting magnitude of null vector did not cause argument exception.");
41 41
42 LLVector3 expectedNormalizedVector = new LLVector3(.577f, .577f, .577f); 42 LLVector3 expectedNormalizedVector = new LLVector3(.577f, .577f, .577f);
43 double expectedNormalizedMagnitude = 1; 43 double expectedNormalizedMagnitude = 1;
44 LLVector3 normalizedVector = Util.GetNormalizedVector(v2); 44 LLVector3 normalizedVector = Util.GetNormalizedVector(v2);
45 Assert.That(normalizedVector, 45 Assert.That(normalizedVector,
46 new VectorToleranceConstraint(expectedNormalizedVector, lowPrecisionTolerance), 46 new VectorToleranceConstraint(expectedNormalizedVector, lowPrecisionTolerance),
47 "Normalized vector generated from vector was not what was expected."); 47 "Normalized vector generated from vector was not what was expected.");
48 Assert.That(Util.GetMagnitude(normalizedVector), 48 Assert.That(Util.GetMagnitude(normalizedVector),
49 new DoubleToleranceConstraint(expectedNormalizedMagnitude, lowPrecisionTolerance), 49 new DoubleToleranceConstraint(expectedNormalizedMagnitude, lowPrecisionTolerance),
50 "Normalized vector generated from vector does not have magnitude of 1."); 50 "Normalized vector generated from vector does not have magnitude of 1.");
51 } 51 }
52 52
53 //Lets test a simple case of <0,0,0> and <0,0,0> 53 //Lets test a simple case of <0,0,0> and <0,0,0>
54 { 54 {
55 v1 = new LLVector3(0, 0, 0); 55 v1 = new LLVector3(0, 0, 0);
56 v2 = new LLVector3(0, 0, 0); 56 v2 = new LLVector3(0, 0, 0);
57 expectedDistance = 0; 57 expectedDistance = 0;
58 Assert.That(Util.GetDistanceTo(v1, v2), 58 Assert.That(Util.GetDistanceTo(v1, v2),
59 new DoubleToleranceConstraint(expectedDistance, lowPrecisionTolerance), 59 new DoubleToleranceConstraint(expectedDistance, lowPrecisionTolerance),
60 "Calculated distance between two vectors was not within tolerances."); 60 "Calculated distance between two vectors was not within tolerances.");
61 61
62 expectedMagnitude = 0; 62 expectedMagnitude = 0;
63 Assert.That(Util.GetMagnitude(v1), Is.EqualTo(0), "Magnitude of null vector was not zero."); 63 Assert.That(Util.GetMagnitude(v1), Is.EqualTo(0), "Magnitude of null vector was not zero.");
64 64
65 expectedMagnitude = 0; 65 expectedMagnitude = 0;
66 Assert.That(Util.GetMagnitude(v2), 66 Assert.That(Util.GetMagnitude(v2),
67 new DoubleToleranceConstraint(expectedMagnitude, lowPrecisionTolerance), 67 new DoubleToleranceConstraint(expectedMagnitude, lowPrecisionTolerance),
68 "Magnitude of vector was incorrect."); 68 "Magnitude of vector was incorrect.");
69 69
70 TestDelegate d = delegate() { Util.GetNormalizedVector(v1); }; 70 TestDelegate d = delegate() { Util.GetNormalizedVector(v1); };
71 bool causesArgumentException = TestHelper.AssertThisDelegateCausesArgumentException(d); 71 bool causesArgumentException = TestHelper.AssertThisDelegateCausesArgumentException(d);
72 Assert.That(causesArgumentException, Is.True, 72 Assert.That(causesArgumentException, Is.True,
73 "Getting magnitude of null vector did not cause argument exception."); 73 "Getting magnitude of null vector did not cause argument exception.");
74 74
75 d = delegate() { Util.GetNormalizedVector(v2); }; 75 d = delegate() { Util.GetNormalizedVector(v2); };
76 causesArgumentException = TestHelper.AssertThisDelegateCausesArgumentException(d); 76 causesArgumentException = TestHelper.AssertThisDelegateCausesArgumentException(d);
77 Assert.That(causesArgumentException, Is.True, 77 Assert.That(causesArgumentException, Is.True,
78 "Getting magnitude of null vector did not cause argument exception."); 78 "Getting magnitude of null vector did not cause argument exception.");
79 } 79 }
80 80
81 //Lets test a simple case of <0,0,0> and <-5,-5,-5> 81 //Lets test a simple case of <0,0,0> and <-5,-5,-5>
82 { 82 {
83 v1 = new LLVector3(0, 0, 0); 83 v1 = new LLVector3(0, 0, 0);
84 v2 = new LLVector3(-5, -5, -5); 84 v2 = new LLVector3(-5, -5, -5);
85 expectedDistance = 8.66; 85 expectedDistance = 8.66;
86 Assert.That(Util.GetDistanceTo(v1, v2), 86 Assert.That(Util.GetDistanceTo(v1, v2),
87 new DoubleToleranceConstraint(expectedDistance, lowPrecisionTolerance), 87 new DoubleToleranceConstraint(expectedDistance, lowPrecisionTolerance),
88 "Calculated distance between two vectors was not within tolerances."); 88 "Calculated distance between two vectors was not within tolerances.");
89 89
90 expectedMagnitude = 0; 90 expectedMagnitude = 0;
91 Assert.That(Util.GetMagnitude(v1), Is.EqualTo(0), "Magnitude of null vector was not zero."); 91 Assert.That(Util.GetMagnitude(v1), Is.EqualTo(0), "Magnitude of null vector was not zero.");
92 92
93 expectedMagnitude = 8.66; 93 expectedMagnitude = 8.66;
94 Assert.That(Util.GetMagnitude(v2), 94 Assert.That(Util.GetMagnitude(v2),
95 new DoubleToleranceConstraint(expectedMagnitude, lowPrecisionTolerance), 95 new DoubleToleranceConstraint(expectedMagnitude, lowPrecisionTolerance),
96 "Magnitude of vector was incorrect."); 96 "Magnitude of vector was incorrect.");
97 97
98 TestDelegate d = delegate() { Util.GetNormalizedVector(v1); }; 98 TestDelegate d = delegate() { Util.GetNormalizedVector(v1); };
99 bool causesArgumentException = TestHelper.AssertThisDelegateCausesArgumentException(d); 99 bool causesArgumentException = TestHelper.AssertThisDelegateCausesArgumentException(d);
100 Assert.That(causesArgumentException, Is.True, 100 Assert.That(causesArgumentException, Is.True,
101 "Getting magnitude of null vector did not cause argument exception."); 101 "Getting magnitude of null vector did not cause argument exception.");
102 102
103 LLVector3 expectedNormalizedVector = new LLVector3(-.577f, -.577f, -.577f); 103 LLVector3 expectedNormalizedVector = new LLVector3(-.577f, -.577f, -.577f);
104 double expectedNormalizedMagnitude = 1; 104 double expectedNormalizedMagnitude = 1;
105 LLVector3 normalizedVector = Util.GetNormalizedVector(v2); 105 LLVector3 normalizedVector = Util.GetNormalizedVector(v2);
106 Assert.That(normalizedVector, 106 Assert.That(normalizedVector,
107 new VectorToleranceConstraint(expectedNormalizedVector, lowPrecisionTolerance), 107 new VectorToleranceConstraint(expectedNormalizedVector, lowPrecisionTolerance),
108 "Normalized vector generated from vector was not what was expected."); 108 "Normalized vector generated from vector was not what was expected.");
109 Assert.That(Util.GetMagnitude(normalizedVector), 109 Assert.That(Util.GetMagnitude(normalizedVector),
110 new DoubleToleranceConstraint(expectedNormalizedMagnitude, lowPrecisionTolerance), 110 new DoubleToleranceConstraint(expectedNormalizedMagnitude, lowPrecisionTolerance),
111 "Normalized vector generated from vector does not have magnitude of 1."); 111 "Normalized vector generated from vector does not have magnitude of 1.");
112 } 112 }
113 } 113 }
114 } 114 }
115} 115}