diff options
author | Sean Dague | 2008-09-04 22:06:18 +0000 |
---|---|---|
committer | Sean Dague | 2008-09-04 22:06:18 +0000 |
commit | fb9bd7dec67ae82efc92ba969ba3b6b929790df8 (patch) | |
tree | 3dde1e2cff284baafa0782c95e09257c4022c3a4 /OpenSim/Tests/Framework/UtilTest.cs | |
parent | added in find calls (diff) | |
download | opensim-SC_OLD-fb9bd7dec67ae82efc92ba969ba3b6b929790df8.zip opensim-SC_OLD-fb9bd7dec67ae82efc92ba969ba3b6b929790df8.tar.gz opensim-SC_OLD-fb9bd7dec67ae82efc92ba969ba3b6b929790df8.tar.bz2 opensim-SC_OLD-fb9bd7dec67ae82efc92ba969ba3b6b929790df8.tar.xz |
normalize naming for OpenSim.Tests.Framework.dll
Diffstat (limited to 'OpenSim/Tests/Framework/UtilTest.cs')
-rw-r--r-- | OpenSim/Tests/Framework/UtilTest.cs | 141 |
1 files changed, 141 insertions, 0 deletions
diff --git a/OpenSim/Tests/Framework/UtilTest.cs b/OpenSim/Tests/Framework/UtilTest.cs new file mode 100644 index 0000000..121ee93 --- /dev/null +++ b/OpenSim/Tests/Framework/UtilTest.cs | |||
@@ -0,0 +1,141 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using libsecondlife; | ||
29 | using NUnit.Framework; | ||
30 | using NUnit.Framework.SyntaxHelpers; | ||
31 | using OpenSim.Tests.Common; | ||
32 | |||
33 | namespace OpenSim.Framework.Tests | ||
34 | { | ||
35 | [TestFixture] | ||
36 | public class UtilTests | ||
37 | { | ||
38 | [Test] | ||
39 | public void VectorOperationTests() | ||
40 | { | ||
41 | LLVector3 v1, v2; | ||
42 | double expectedDistance; | ||
43 | double expectedMagnitude; | ||
44 | double lowPrecisionTolerance = 0.001; | ||
45 | |||
46 | //Lets test a simple case of <0,0,0> and <5,5,5> | ||
47 | { | ||
48 | v1 = new LLVector3(0, 0, 0); | ||
49 | v2 = new LLVector3(5, 5, 5); | ||
50 | expectedDistance = 8.66; | ||
51 | Assert.That(Util.GetDistanceTo(v1, v2), | ||
52 | new DoubleToleranceConstraint(expectedDistance, lowPrecisionTolerance), | ||
53 | "Calculated distance between two vectors was not within tolerances."); | ||
54 | |||
55 | expectedMagnitude = 0; | ||
56 | Assert.That(Util.GetMagnitude(v1), Is.EqualTo(0), "Magnitude of null vector was not zero."); | ||
57 | |||
58 | expectedMagnitude = 8.66; | ||
59 | Assert.That(Util.GetMagnitude(v2), | ||
60 | new DoubleToleranceConstraint(expectedMagnitude, lowPrecisionTolerance), | ||
61 | "Magnitude of vector was incorrect."); | ||
62 | |||
63 | TestDelegate d = delegate() { Util.GetNormalizedVector(v1); }; | ||
64 | bool causesArgumentException = TestHelper.AssertThisDelegateCausesArgumentException(d); | ||
65 | Assert.That(causesArgumentException, Is.True, | ||
66 | "Getting magnitude of null vector did not cause argument exception."); | ||
67 | |||
68 | LLVector3 expectedNormalizedVector = new LLVector3(.577f, .577f, .577f); | ||
69 | double expectedNormalizedMagnitude = 1; | ||
70 | LLVector3 normalizedVector = Util.GetNormalizedVector(v2); | ||
71 | Assert.That(normalizedVector, | ||
72 | new VectorToleranceConstraint(expectedNormalizedVector, lowPrecisionTolerance), | ||
73 | "Normalized vector generated from vector was not what was expected."); | ||
74 | Assert.That(Util.GetMagnitude(normalizedVector), | ||
75 | new DoubleToleranceConstraint(expectedNormalizedMagnitude, lowPrecisionTolerance), | ||
76 | "Normalized vector generated from vector does not have magnitude of 1."); | ||
77 | } | ||
78 | |||
79 | //Lets test a simple case of <0,0,0> and <0,0,0> | ||
80 | { | ||
81 | v1 = new LLVector3(0, 0, 0); | ||
82 | v2 = new LLVector3(0, 0, 0); | ||
83 | expectedDistance = 0; | ||
84 | Assert.That(Util.GetDistanceTo(v1, v2), | ||
85 | new DoubleToleranceConstraint(expectedDistance, lowPrecisionTolerance), | ||
86 | "Calculated distance between two vectors was not within tolerances."); | ||
87 | |||
88 | expectedMagnitude = 0; | ||
89 | Assert.That(Util.GetMagnitude(v1), Is.EqualTo(0), "Magnitude of null vector was not zero."); | ||
90 | |||
91 | expectedMagnitude = 0; | ||
92 | Assert.That(Util.GetMagnitude(v2), | ||
93 | new DoubleToleranceConstraint(expectedMagnitude, lowPrecisionTolerance), | ||
94 | "Magnitude of vector was incorrect."); | ||
95 | |||
96 | TestDelegate d = delegate() { Util.GetNormalizedVector(v1); }; | ||
97 | bool causesArgumentException = TestHelper.AssertThisDelegateCausesArgumentException(d); | ||
98 | Assert.That(causesArgumentException, Is.True, | ||
99 | "Getting magnitude of null vector did not cause argument exception."); | ||
100 | |||
101 | d = delegate() { Util.GetNormalizedVector(v2); }; | ||
102 | causesArgumentException = TestHelper.AssertThisDelegateCausesArgumentException(d); | ||
103 | Assert.That(causesArgumentException, Is.True, | ||
104 | "Getting magnitude of null vector did not cause argument exception."); | ||
105 | } | ||
106 | |||
107 | //Lets test a simple case of <0,0,0> and <-5,-5,-5> | ||
108 | { | ||
109 | v1 = new LLVector3(0, 0, 0); | ||
110 | v2 = new LLVector3(-5, -5, -5); | ||
111 | expectedDistance = 8.66; | ||
112 | Assert.That(Util.GetDistanceTo(v1, v2), | ||
113 | new DoubleToleranceConstraint(expectedDistance, lowPrecisionTolerance), | ||
114 | "Calculated distance between two vectors was not within tolerances."); | ||
115 | |||
116 | expectedMagnitude = 0; | ||
117 | Assert.That(Util.GetMagnitude(v1), Is.EqualTo(0), "Magnitude of null vector was not zero."); | ||
118 | |||
119 | expectedMagnitude = 8.66; | ||
120 | Assert.That(Util.GetMagnitude(v2), | ||
121 | new DoubleToleranceConstraint(expectedMagnitude, lowPrecisionTolerance), | ||
122 | "Magnitude of vector was incorrect."); | ||
123 | |||
124 | TestDelegate d = delegate() { Util.GetNormalizedVector(v1); }; | ||
125 | bool causesArgumentException = TestHelper.AssertThisDelegateCausesArgumentException(d); | ||
126 | Assert.That(causesArgumentException, Is.True, | ||
127 | "Getting magnitude of null vector did not cause argument exception."); | ||
128 | |||
129 | LLVector3 expectedNormalizedVector = new LLVector3(-.577f, -.577f, -.577f); | ||
130 | double expectedNormalizedMagnitude = 1; | ||
131 | LLVector3 normalizedVector = Util.GetNormalizedVector(v2); | ||
132 | Assert.That(normalizedVector, | ||
133 | new VectorToleranceConstraint(expectedNormalizedVector, lowPrecisionTolerance), | ||
134 | "Normalized vector generated from vector was not what was expected."); | ||
135 | Assert.That(Util.GetMagnitude(normalizedVector), | ||
136 | new DoubleToleranceConstraint(expectedNormalizedMagnitude, lowPrecisionTolerance), | ||
137 | "Normalized vector generated from vector does not have magnitude of 1."); | ||
138 | } | ||
139 | } | ||
140 | } | ||
141 | } | ||