aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Tests/Common
diff options
context:
space:
mode:
authorAdam Frisby2008-02-08 17:54:30 +0000
committerAdam Frisby2008-02-08 17:54:30 +0000
commita1625a54104da7872c15618db9e68656c6f6ec2a (patch)
tree2c9847e3085ee1c3252471af9c393a7f8265de3f /OpenSim/Tests/Common
parent* Adding console spam to help track 'The Steve Bug'. (diff)
downloadopensim-SC-a1625a54104da7872c15618db9e68656c6f6ec2a.zip
opensim-SC-a1625a54104da7872c15618db9e68656c6f6ec2a.tar.gz
opensim-SC-a1625a54104da7872c15618db9e68656c6f6ec2a.tar.bz2
opensim-SC-a1625a54104da7872c15618db9e68656c6f6ec2a.tar.xz
* Applying mantis 339 patches round 2 -- Thanks daedius
Diffstat (limited to '')
-rw-r--r--OpenSim/Tests/Common/ANumericalToleranceConstraint.cs30
-rw-r--r--OpenSim/Tests/Common/DoubleToleranceConstraint.cs52
-rw-r--r--OpenSim/Tests/Common/TestHelper.cs25
-rw-r--r--OpenSim/Tests/Common/VectorToleranceConstraint.cs58
4 files changed, 165 insertions, 0 deletions
diff --git a/OpenSim/Tests/Common/ANumericalToleranceConstraint.cs b/OpenSim/Tests/Common/ANumericalToleranceConstraint.cs
new file mode 100644
index 0000000..289e4bb
--- /dev/null
+++ b/OpenSim/Tests/Common/ANumericalToleranceConstraint.cs
@@ -0,0 +1,30 @@
1using System;
2using NUnit.Framework.Constraints;
3
4namespace OpenSim.Tests.Common
5{
6 public abstract class ANumericalToleranceConstraint : Constraint
7 {
8 protected double _tolerance;
9
10 public ANumericalToleranceConstraint(double tolerance)
11 {
12 if (tolerance < 0)
13 {
14 throw new ArgumentException("Tolerance cannot be negative.");
15 }
16 _tolerance = tolerance;
17 }
18
19
20 protected bool IsWithinDoubleConstraint(double doubleValue, double baseValue)
21 {
22 if (doubleValue >= baseValue - _tolerance && doubleValue <= baseValue + _tolerance)
23 {
24 return true;
25 }
26
27 return false;
28 }
29 }
30}
diff --git a/OpenSim/Tests/Common/DoubleToleranceConstraint.cs b/OpenSim/Tests/Common/DoubleToleranceConstraint.cs
new file mode 100644
index 0000000..f3da236
--- /dev/null
+++ b/OpenSim/Tests/Common/DoubleToleranceConstraint.cs
@@ -0,0 +1,52 @@
1using System;
2using NUnit.Framework;
3using NUnit.Framework.Constraints;
4using OpenSim.Tests.Common;
5
6namespace OpenSim.Tests.Common
7{
8 public class DoubleToleranceConstraint : ANumericalToleranceConstraint
9 {
10
11 private double _baseValue;
12 private double _valueToBeTested;
13
14 public DoubleToleranceConstraint(double baseValue, double tolerance) : base(tolerance)
15 {
16 _baseValue = baseValue;
17 }
18
19 ///<summary>
20 ///Test whether the constraint is satisfied by a given value
21 ///</summary>
22 ///<param name="valueToBeTested">The value to be tested</param>
23 ///<returns>
24 ///True for success, false for failure
25 ///</returns>
26 public override bool Matches(object valueToBeTested)
27 {
28 if (valueToBeTested == null)
29 {
30 throw new ArgumentException("Constraint cannot be used upon null values.");
31 }
32 if( valueToBeTested.GetType() != typeof(double))
33 {
34 throw new ArgumentException("Constraint cannot be used upon non double-values.");
35 }
36
37 _valueToBeTested = (double)valueToBeTested;
38
39 return IsWithinDoubleConstraint(_valueToBeTested, _baseValue );
40 }
41
42 public override void WriteDescriptionTo(MessageWriter writer)
43 {
44 writer.WriteExpectedValue(string.Format("A value {0} within tolerance of plus or minus {1}",_baseValue,_tolerance));
45 }
46
47 public override void WriteActualValueTo(MessageWriter writer)
48 {
49 writer.WriteActualValue(_valueToBeTested);
50 }
51 }
52}
diff --git a/OpenSim/Tests/Common/TestHelper.cs b/OpenSim/Tests/Common/TestHelper.cs
new file mode 100644
index 0000000..f59c157
--- /dev/null
+++ b/OpenSim/Tests/Common/TestHelper.cs
@@ -0,0 +1,25 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace OpenSim.Tests.Common
6{
7 public delegate void TestDelegate();
8
9 public class TestHelper
10 {
11 public static bool AssertThisDelegateCausesArgumentException(TestDelegate d)
12 {
13 try
14 {
15 d();
16 }
17 catch(ArgumentException e)
18 {
19 return true;
20 }
21
22 return false;
23 }
24 }
25}
diff --git a/OpenSim/Tests/Common/VectorToleranceConstraint.cs b/OpenSim/Tests/Common/VectorToleranceConstraint.cs
new file mode 100644
index 0000000..1faf7dd
--- /dev/null
+++ b/OpenSim/Tests/Common/VectorToleranceConstraint.cs
@@ -0,0 +1,58 @@
1using System;
2using libsecondlife;
3using NUnit.Framework;
4
5namespace OpenSim.Tests.Common
6{
7 public class VectorToleranceConstraint : ANumericalToleranceConstraint
8 {
9 private LLVector3 _baseValue;
10 private LLVector3 _valueToBeTested;
11
12 public VectorToleranceConstraint(LLVector3 baseValue, double tolerance) : base(tolerance)
13 {
14 _baseValue = baseValue;
15 }
16
17 ///<summary>
18 ///Test whether the constraint is satisfied by a given value
19 ///</summary>
20 ///<param name="valueToBeTested">The value to be tested</param>
21 ///<returns>
22 ///True for success, false for failure
23 ///</returns>
24 public override bool Matches(object valueToBeTested)
25 {
26 if (valueToBeTested == null)
27 {
28 throw new ArgumentException("Constraint cannot be used upon null values.");
29 }
30 if (valueToBeTested.GetType() != typeof (LLVector3))
31 {
32 throw new ArgumentException("Constraint cannot be used upon non vector values.");
33 }
34
35 _valueToBeTested = (LLVector3) valueToBeTested;
36
37 if ( IsWithinDoubleConstraint(_valueToBeTested.X,_baseValue.X) &&
38 IsWithinDoubleConstraint(_valueToBeTested.Y,_baseValue.Y) &&
39 IsWithinDoubleConstraint(_valueToBeTested.Z,_baseValue.Z) )
40 {
41 return true;
42 }
43
44 return false;
45 }
46
47 public override void WriteDescriptionTo(MessageWriter writer)
48 {
49 writer.WriteExpectedValue(
50 string.Format("A value {0} within tolerance of plus or minus {1}", _baseValue, _tolerance));
51 }
52
53 public override void WriteActualValueTo(MessageWriter writer)
54 {
55 writer.WriteActualValue(_valueToBeTested);
56 }
57 }
58}