[amd64] Save missing register
[mono.git] / mcs / class / WindowsBase / Test / System.Windows / VectorTest.cs
1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
8 // 
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
11 // 
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19 //
20 // Copyright (c) 2007 Novell, Inc. (http://www.novell.com)
21 //
22 // Authors:
23 //      Chris Toshok (toshok@ximian.com)
24 //
25
26 using System;
27 using System.Windows;
28 using System.Windows.Media;
29 using NUnit.Framework;
30
31 namespace MonoTests.System.Windows {
32
33         [TestFixture]
34         public class VectorTest
35         {
36                 const double DELTA = 0.000000001d;
37
38                 [Test]
39                 public void Accessors ()
40                 {
41                         Vector v = new Vector (4, 5);
42                         Assert.AreEqual (4, v.X);
43                         Assert.AreEqual (5, v.Y);
44                 }
45
46                 [Test]
47                 public void Equals ()
48                 {
49                         Vector v = new Vector (4, 5);
50                         Assert.IsTrue (v.Equals (new Vector (4, 5)));
51                         Assert.IsFalse (v.Equals (new Vector (5, 4)));
52                         Assert.IsFalse (v.Equals (new object()));
53                 }
54
55                 [Test]
56                 public void ToStringTest ()
57                 {
58                         Vector v = new Vector (4, 5);
59                         Assert.AreEqual ("4,5", v.ToString());
60                 }
61
62                 [Test]
63                 [Category ("NotWorking")]
64                 public void Parse ()
65                 {
66                         Vector v = Vector.Parse ("4,5");
67                         Assert.AreEqual (new Vector (4, 5), v);
68
69                         v = Vector.Parse ("-4,-5");
70                         Assert.AreEqual (new Vector (-4, -5), v);
71
72                         v = Vector.Parse ("-4.4,-5.5");
73                         Assert.AreEqual (new Vector (-4.4, -5.5), v);
74                 }
75
76                 [Test]
77                 public void Add ()
78                 {
79                         Point p = Vector.Add (new Vector (2, 3), new Point (4, 5));
80                         Assert.AreEqual (new Point (6, 8), p);
81
82                         Vector v = Vector.Add (new Vector (2, 3), new Vector (4, 5));
83                         Assert.AreEqual (new Vector (6, 8), v);
84                 }
85
86                 [Test]
87                 public void Length ()
88                 {
89                         Vector v = new Vector (1, 0);
90                         Assert.AreEqual (1, v.LengthSquared);
91                         Assert.AreEqual (1, v.Length);
92
93                         v = new Vector (5, 5);
94                         Assert.AreEqual (50, v.LengthSquared);
95                         Assert.AreEqual (Math.Sqrt(50), v.Length);
96                 }
97
98                 [Test]
99                 public void AngleBetween ()
100                 {
101                         double angle = Vector.AngleBetween (new Vector (1, 0), new Vector (0, 1));
102                         Assert.AreEqual (90, angle);
103
104                         angle = Vector.AngleBetween (new Vector (1, 0), new Vector (0.5, 0.5));
105                         Assert.AreEqual (45, angle, DELTA);
106                 }
107
108                 [Test]
109                 public void CrossProduct ()
110                 {
111                         Assert.AreEqual (1, Vector.CrossProduct (new Vector (1, 0), new Vector (0, 1)));
112                         Assert.AreEqual (50, Vector.CrossProduct (new Vector (20, 30), new Vector (45, 70)));
113                 }
114
115                 [Test]
116                 public void Determinant ()
117                 {
118                         Assert.AreEqual (1, Vector.Determinant (new Vector (1, 0), new Vector (0, 1)));
119                         Assert.AreEqual (50, Vector.Determinant (new Vector (20, 30), new Vector (45, 70)));
120                 }
121
122                 [Test]
123                 public void Divide ()
124                 {
125                         Assert.AreEqual (new Vector (5, 7), Vector.Divide (new Vector (10, 14), 2));
126                 }
127
128                 [Test]
129                 public void Multiply_VV_M ()
130                 {
131                         Assert.AreEqual (60, Vector.Multiply (new Vector (5, 7), new Vector (5, 5)));
132                 }
133
134                 [Test]
135                 public void Multiply_VM_V ()
136                 {
137                         Matrix m = Matrix.Identity;
138                         m.Rotate (45);
139
140                         Console.WriteLine (Vector.Multiply (new Vector (3, 4), m));
141                 }
142
143                 [Test]
144                 public void Multiply_dV_V ()
145                 {
146                         Assert.AreEqual (new Vector (10, 18), Vector.Multiply (2, new Vector (5, 9)));
147                 }
148
149                 [Test]
150                 public void Multiply_Vd_V ()
151                 {
152                         Assert.AreEqual (new Vector (10, 18), Vector.Multiply (new Vector (5, 9), 2));
153                 }
154
155                 [Test]
156                 public void Negate ()
157                 {
158                         Vector v = new Vector (4, 5);
159                         v.Negate ();
160
161                         Assert.AreEqual (new Vector (-4, -5), v);
162                 }
163
164                 [Test]
165                 public void Normalize ()
166                 {
167                         Vector v = new Vector (5, 5);
168                         v.Normalize ();
169
170                         Assert.AreEqual (v.X, v.Y);
171                         Assert.AreEqual (1, v.Length, DELTA);
172                 }
173
174                 [Test]
175                 public void Subtract ()
176                 {
177                         Assert.AreEqual (new Vector (3, 4), Vector.Subtract (new Vector (5, 7), new Vector (2, 3)));
178                 }
179         }
180 }
181