aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Tests
diff options
context:
space:
mode:
authorSean Dague2008-09-08 20:34:45 +0000
committerSean Dague2008-09-08 20:34:45 +0000
commitce0a8d7beffccbaeb6b603a96b7729278c4c9e75 (patch)
treefaccd65637c0dab11b2dd787c8985cd7f2c9452b /OpenSim/Framework/Tests
parentFix component order on a quaternion for the sit target. This caused (diff)
downloadopensim-SC_OLD-ce0a8d7beffccbaeb6b603a96b7729278c4c9e75.zip
opensim-SC_OLD-ce0a8d7beffccbaeb6b603a96b7729278c4c9e75.tar.gz
opensim-SC_OLD-ce0a8d7beffccbaeb6b603a96b7729278c4c9e75.tar.bz2
opensim-SC_OLD-ce0a8d7beffccbaeb6b603a96b7729278c4c9e75.tar.xz
changes to Test directory structure per opensim-dev conversation
Diffstat (limited to 'OpenSim/Framework/Tests')
-rw-r--r--OpenSim/Framework/Tests/UtilTest.cs141
1 files changed, 141 insertions, 0 deletions
diff --git a/OpenSim/Framework/Tests/UtilTest.cs b/OpenSim/Framework/Tests/UtilTest.cs
new file mode 100644
index 0000000..a973ed2
--- /dev/null
+++ b/OpenSim/Framework/Tests/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
28using OpenMetaverse;
29using NUnit.Framework;
30using NUnit.Framework.SyntaxHelpers;
31using OpenSim.Tests.Common;
32
33namespace OpenSim.Framework.Tests
34{
35 [TestFixture]
36 public class UtilTests
37 {
38 [Test]
39 public void VectorOperationTests()
40 {
41 Vector3 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 Vector3(0, 0, 0);
49 v2 = new Vector3(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 Vector3 expectedNormalizedVector = new Vector3(.577f, .577f, .577f);
69 double expectedNormalizedMagnitude = 1;
70 Vector3 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 Vector3(0, 0, 0);
82 v2 = new Vector3(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 Vector3(0, 0, 0);
110 v2 = new Vector3(-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 Vector3 expectedNormalizedVector = new Vector3(-.577f, -.577f, -.577f);
130 double expectedNormalizedMagnitude = 1;
131 Vector3 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}