1 // Tests for System.Drawing.Point.cs
3 // Author: Mike Kestner (mkestner@speakeasy.net)
4 // Improvements by Jordi Mas i Hernàndez <jmas@softcatala.org>
5 // Copyright (c) 2001 Ximian, Inc.
8 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 using NUnit
.Framework
;
34 namespace MonoTests
.System
.Drawing
{
37 public class PointTest
: Assertion
{
43 public void Clean() {}
46 public void GetReady()
48 pt1_1
= new Point (1, 1);
49 pt1_0
= new Point (1, 0);
50 pt0_1
= new Point (0, 1);
55 public void EqualsTest ()
57 AssertEquals (pt1_1
, pt1_1
);
58 AssertEquals (pt1_1
, new Point (1, 1));
59 Assert (!pt1_1
.Equals (pt1_0
));
60 Assert (!pt1_1
.Equals (pt0_1
));
61 Assert (!pt1_0
.Equals (pt0_1
));
65 public void EqualityOpTest ()
67 Assert (pt1_1
== pt1_1
);
68 Assert (pt1_1
== new Point (1, 1));
69 Assert (!(pt1_1
== pt1_0
));
70 Assert (!(pt1_1
== pt0_1
));
71 Assert (!(pt1_0
== pt0_1
));
75 public void InequalityOpTest ()
77 Assert (!(pt1_1
!= pt1_1
));
78 Assert (!(pt1_1
!= new Point (1, 1)));
79 Assert (pt1_1
!= pt1_0
);
80 Assert (pt1_1
!= pt0_1
);
81 Assert (pt1_0
!= pt0_1
);
85 public void CeilingTest ()
87 PointF ptf
= new PointF (0.8f
, 0.3f
);
88 AssertEquals (pt1_1
, Point
.Ceiling (ptf
));
92 public void RoundTest ()
94 PointF ptf
= new PointF (0.8f
, 1.3f
);
95 AssertEquals (pt1_1
, Point
.Round (ptf
));
99 public void TruncateTest ()
101 PointF ptf
= new PointF (0.8f
, 1.3f
);
102 AssertEquals (pt0_1
, Point
.Truncate (ptf
));
106 public void NullTest ()
108 Point pt
= new Point (0, 0);
109 AssertEquals (pt
, Point
.Empty
);
113 public void AdditionTest ()
115 AssertEquals (pt1_1
, pt1_0
+ new Size (0, 1));
116 AssertEquals (pt1_1
, pt0_1
+ new Size (1, 0));
120 public void SubtractionTest ()
122 AssertEquals (pt1_0
, pt1_1
- new Size (0, 1));
123 AssertEquals (pt0_1
, pt1_1
- new Size (1, 0));
127 public void Point2SizeTest ()
129 Size sz1
= new Size (1, 1);
130 Size sz2
= (Size
) pt1_1
;
132 AssertEquals (sz1
, sz2
);
136 public void Point2PointFTest ()
138 PointF ptf1
= new PointF (1, 1);
141 AssertEquals (ptf1
, ptf2
);
145 public void ConstructorTest ()
147 int i
= (1 << 16) + 1;
148 Size sz
= new Size (1, 1);
149 Point pt_i
= new Point (i
);
150 Point pt_sz
= new Point (sz
);
152 AssertEquals (pt_i
, pt_sz
);
153 AssertEquals (pt_i
, pt1_1
);
154 AssertEquals (pt_sz
, pt1_1
);
158 public void PropertyTest ()
160 Point pt
= new Point (0, 0);
163 Assert (!pt1_1
.IsEmpty
);
164 AssertEquals (1, pt1_0
.X
);
165 AssertEquals (1, pt0_1
.Y
);
169 public void OffsetTest ()
171 Point pt
= new Point (0, 0);
173 AssertEquals (pt
, pt0_1
);
175 AssertEquals (pt
, pt1_1
);
177 AssertEquals (pt
, pt1_0
);