diff options
Diffstat (limited to 'OpenSim/Tests/OpenSim/Framework/UtilTest.cs')
-rw-r--r-- | OpenSim/Tests/OpenSim/Framework/UtilTest.cs | 230 |
1 files changed, 115 insertions, 115 deletions
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 @@ | |||
1 | using libsecondlife; | 1 | using libsecondlife; |
2 | using NUnit.Framework; | 2 | using NUnit.Framework; |
3 | using NUnit.Framework.SyntaxHelpers; | 3 | using NUnit.Framework.SyntaxHelpers; |
4 | 4 | ||
5 | using OpenSim.Tests.Common; | 5 | using OpenSim.Tests.Common; |
6 | 6 | ||
7 | namespace OpenSim.Framework.Tests | 7 | namespace 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 | } |