aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Tests/OpenSim/Framework/UtilTest.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Tests/OpenSim/Framework/UtilTest.cs')
-rw-r--r--OpenSim/Tests/OpenSim/Framework/UtilTest.cs115
1 files changed, 115 insertions, 0 deletions
diff --git a/OpenSim/Tests/OpenSim/Framework/UtilTest.cs b/OpenSim/Tests/OpenSim/Framework/UtilTest.cs
new file mode 100644
index 0000000..ef42eee
--- /dev/null
+++ b/OpenSim/Tests/OpenSim/Framework/UtilTest.cs
@@ -0,0 +1,115 @@
1using libsecondlife;
2using NUnit.Framework;
3using NUnit.Framework.SyntaxHelpers;
4
5using OpenSim.Tests.Common;
6
7namespace OpenSim.Framework.Tests
8{
9 [TestFixture]
10 public class UtilTests
11 {
12 [Test]
13 public void VectorOperationTests()
14 {
15 LLVector3 v1, v2;
16 double expectedDistance;
17 double expectedMagnitude;
18 double lowPrecisionTolerance = 0.001;
19
20 //Lets test a simple case of <0,0,0> and <5,5,5>
21 {
22 v1 = new LLVector3(0, 0, 0);
23 v2 = new LLVector3(5, 5, 5);
24 expectedDistance = 8.66;
25 Assert.That(Util.GetDistanceTo(v1, v2),
26 new DoubleToleranceConstraint(expectedDistance, lowPrecisionTolerance),
27 "Calculated distance between two vectors was not within tolerances.");
28
29 expectedMagnitude = 0;
30 Assert.That(Util.GetMagnitude(v1), Is.EqualTo(0), "Magnitude of null vector was not zero.");
31
32 expectedMagnitude = 8.66;
33 Assert.That(Util.GetMagnitude(v2),
34 new DoubleToleranceConstraint(expectedMagnitude, lowPrecisionTolerance),
35 "Magnitude of vector was incorrect.");
36
37 TestDelegate d = delegate() { Util.GetNormalizedVector(v1); };
38 bool causesArgumentException = TestHelper.AssertThisDelegateCausesArgumentException(d);
39 Assert.That(causesArgumentException, Is.True,
40 "Getting magnitude of null vector did not cause argument exception.");
41
42 LLVector3 expectedNormalizedVector = new LLVector3(.577f, .577f, .577f);
43 double expectedNormalizedMagnitude = 1;
44 LLVector3 normalizedVector = Util.GetNormalizedVector(v2);
45 Assert.That(normalizedVector,
46 new VectorToleranceConstraint(expectedNormalizedVector, lowPrecisionTolerance),
47 "Normalized vector generated from vector was not what was expected.");
48 Assert.That(Util.GetMagnitude(normalizedVector),
49 new DoubleToleranceConstraint(expectedNormalizedMagnitude, lowPrecisionTolerance),
50 "Normalized vector generated from vector does not have magnitude of 1.");
51 }
52
53 //Lets test a simple case of <0,0,0> and <0,0,0>
54 {
55 v1 = new LLVector3(0, 0, 0);
56 v2 = new LLVector3(0, 0, 0);
57 expectedDistance = 0;
58 Assert.That(Util.GetDistanceTo(v1, v2),
59 new DoubleToleranceConstraint(expectedDistance, lowPrecisionTolerance),
60 "Calculated distance between two vectors was not within tolerances.");
61
62 expectedMagnitude = 0;
63 Assert.That(Util.GetMagnitude(v1), Is.EqualTo(0), "Magnitude of null vector was not zero.");
64
65 expectedMagnitude = 0;
66 Assert.That(Util.GetMagnitude(v2),
67 new DoubleToleranceConstraint(expectedMagnitude, lowPrecisionTolerance),
68 "Magnitude of vector was incorrect.");
69
70 TestDelegate d = delegate() { Util.GetNormalizedVector(v1); };
71 bool causesArgumentException = TestHelper.AssertThisDelegateCausesArgumentException(d);
72 Assert.That(causesArgumentException, Is.True,
73 "Getting magnitude of null vector did not cause argument exception.");
74
75 d = delegate() { Util.GetNormalizedVector(v2); };
76 causesArgumentException = TestHelper.AssertThisDelegateCausesArgumentException(d);
77 Assert.That(causesArgumentException, Is.True,
78 "Getting magnitude of null vector did not cause argument exception.");
79 }
80
81 //Lets test a simple case of <0,0,0> and <-5,-5,-5>
82 {
83 v1 = new LLVector3(0, 0, 0);
84 v2 = new LLVector3(-5, -5, -5);
85 expectedDistance = 8.66;
86 Assert.That(Util.GetDistanceTo(v1, v2),
87 new DoubleToleranceConstraint(expectedDistance, lowPrecisionTolerance),
88 "Calculated distance between two vectors was not within tolerances.");
89
90 expectedMagnitude = 0;
91 Assert.That(Util.GetMagnitude(v1), Is.EqualTo(0), "Magnitude of null vector was not zero.");
92
93 expectedMagnitude = 8.66;
94 Assert.That(Util.GetMagnitude(v2),
95 new DoubleToleranceConstraint(expectedMagnitude, lowPrecisionTolerance),
96 "Magnitude of vector was incorrect.");
97
98 TestDelegate d = delegate() { Util.GetNormalizedVector(v1); };
99 bool causesArgumentException = TestHelper.AssertThisDelegateCausesArgumentException(d);
100 Assert.That(causesArgumentException, Is.True,
101 "Getting magnitude of null vector did not cause argument exception.");
102
103 LLVector3 expectedNormalizedVector = new LLVector3(-.577f, -.577f, -.577f);
104 double expectedNormalizedMagnitude = 1;
105 LLVector3 normalizedVector = Util.GetNormalizedVector(v2);
106 Assert.That(normalizedVector,
107 new VectorToleranceConstraint(expectedNormalizedVector, lowPrecisionTolerance),
108 "Normalized vector generated from vector was not what was expected.");
109 Assert.That(Util.GetMagnitude(normalizedVector),
110 new DoubleToleranceConstraint(expectedNormalizedMagnitude, lowPrecisionTolerance),
111 "Normalized vector generated from vector does not have magnitude of 1.");
112 }
113 }
114 }
115}