Skip to content

Commit 96a2609

Browse files
introfogiText-CI
authored andcommitted
Add PointTest
DEVSIX-3866 Autoported commit. Original commit hash: [518a91fd5]
1 parent edc8b43 commit 96a2609

File tree

2 files changed

+245
-1
lines changed

2 files changed

+245
-1
lines changed
Lines changed: 244 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,244 @@
1+
/*
2+
This file is part of the iText (R) project.
3+
Copyright (c) 1998-2020 iText Group NV
4+
Authors: iText Software.
5+
6+
This program is free software; you can redistribute it and/or modify
7+
it under the terms of the GNU Affero General Public License version 3
8+
as published by the Free Software Foundation with the addition of the
9+
following permission added to Section 15 as permitted in Section 7(a):
10+
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
11+
ITEXT GROUP. ITEXT GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
12+
OF THIRD PARTY RIGHTS
13+
14+
This program is distributed in the hope that it will be useful, but
15+
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16+
or FITNESS FOR A PARTICULAR PURPOSE.
17+
See the GNU Affero General Public License for more details.
18+
You should have received a copy of the GNU Affero General Public License
19+
along with this program; if not, see http://www.gnu.org/licenses or write to
20+
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21+
Boston, MA, 02110-1301 USA, or download the license from the following URL:
22+
http://itextpdf.com/terms-of-use/
23+
24+
The interactive user interfaces in modified source and object code versions
25+
of this program must display Appropriate Legal Notices, as required under
26+
Section 5 of the GNU Affero General Public License.
27+
28+
In accordance with Section 7(b) of the GNU Affero General Public License,
29+
a covered work must retain the producer line in every PDF that is created
30+
or manipulated using iText.
31+
32+
You can be released from the requirements of the license by purchasing
33+
a commercial license. Buying such a license is mandatory as soon as you
34+
develop commercial activities involving the iText software without
35+
disclosing the source code of your own applications.
36+
These activities include: offering paid services to customers as an ASP,
37+
serving PDFs on the fly in a web application, shipping iText with a closed
38+
source product.
39+
40+
For more information, please contact iText Software Corp. at this
41+
42+
*/
43+
using System;
44+
45+
namespace iText.Kernel.Geom {
46+
public class PointTest {
47+
private static double EPSILON_COMPARISON = 1E-12;
48+
49+
[NUnit.Framework.Test]
50+
public virtual void DefaultConstructorTest() {
51+
Point first = new Point();
52+
NUnit.Framework.Assert.AreEqual(0, first.x, EPSILON_COMPARISON);
53+
NUnit.Framework.Assert.AreEqual(0, first.y, EPSILON_COMPARISON);
54+
}
55+
56+
[NUnit.Framework.Test]
57+
public virtual void DoubleParamConstructorTest() {
58+
Point first = new Point(0.13, 1.1);
59+
NUnit.Framework.Assert.AreEqual(0.13, first.GetX(), EPSILON_COMPARISON);
60+
NUnit.Framework.Assert.AreEqual(1.1, first.GetY(), EPSILON_COMPARISON);
61+
}
62+
63+
[NUnit.Framework.Test]
64+
public virtual void IntParamConstructorTest() {
65+
Point first = new Point(2, 3);
66+
NUnit.Framework.Assert.AreEqual(2, first.x, EPSILON_COMPARISON);
67+
NUnit.Framework.Assert.AreEqual(3, first.y, EPSILON_COMPARISON);
68+
}
69+
70+
[NUnit.Framework.Test]
71+
public virtual void CopyConstructorTest() {
72+
Point second = new Point(new Point(0.13, 1.1));
73+
NUnit.Framework.Assert.AreEqual(0.13, second.GetX(), EPSILON_COMPARISON);
74+
NUnit.Framework.Assert.AreEqual(1.1, second.GetY(), EPSILON_COMPARISON);
75+
}
76+
77+
[NUnit.Framework.Test]
78+
public virtual void EqualsItselfTest() {
79+
Point first = new Point(1.23, 1.1);
80+
NUnit.Framework.Assert.IsTrue(first.Equals(first));
81+
NUnit.Framework.Assert.AreEqual(first.GetHashCode(), first.GetHashCode());
82+
}
83+
84+
[NUnit.Framework.Test]
85+
public virtual void EqualsToAnotherPointTest() {
86+
Point first = new Point(1.23, 1.1);
87+
Point second = new Point(1.23, 1.1);
88+
NUnit.Framework.Assert.IsTrue(first.Equals(second));
89+
NUnit.Framework.Assert.IsTrue(second.Equals(first));
90+
NUnit.Framework.Assert.AreEqual(first.GetHashCode(), second.GetHashCode());
91+
}
92+
93+
[NUnit.Framework.Test]
94+
public virtual void NotEqualsToAnotherPointTest() {
95+
Point first = new Point(1.23, 1.1);
96+
Point second = new Point(1.23, 1.2);
97+
NUnit.Framework.Assert.IsFalse(first.Equals(second));
98+
NUnit.Framework.Assert.IsFalse(second.Equals(first));
99+
NUnit.Framework.Assert.AreNotEqual(first.GetHashCode(), second.GetHashCode());
100+
}
101+
102+
[NUnit.Framework.Test]
103+
public virtual void NotEqualsToNullTest() {
104+
Point first = new Point(1.23, 1.1);
105+
NUnit.Framework.Assert.IsFalse(first.Equals(null));
106+
}
107+
108+
[NUnit.Framework.Test]
109+
public virtual void DistanceSquareBetweenCoordinatesTest() {
110+
Point first = new Point(1, 1);
111+
Point second = new Point(1.1, 1.1);
112+
double expected = 0.02;
113+
NUnit.Framework.Assert.AreEqual(expected, Point.DistanceSq(first.x, first.y, second.x, second.y), EPSILON_COMPARISON
114+
);
115+
}
116+
117+
[NUnit.Framework.Test]
118+
public virtual void DistanceSquareByCoordinatesTest() {
119+
Point first = new Point(1, 1);
120+
Point second = new Point(1.1, 1.1);
121+
double expected = 0.02;
122+
NUnit.Framework.Assert.AreEqual(expected, first.DistanceSq(second.x, second.y), EPSILON_COMPARISON);
123+
}
124+
125+
[NUnit.Framework.Test]
126+
public virtual void DistanceSquareByPointTest() {
127+
Point first = new Point(1, 1);
128+
Point second = new Point(1.1, 1.1);
129+
double expected = 0.02;
130+
NUnit.Framework.Assert.AreEqual(expected, first.DistanceSq(second), EPSILON_COMPARISON);
131+
}
132+
133+
[NUnit.Framework.Test]
134+
public virtual void DistanceItselfSquareTest() {
135+
Point first = new Point(1, 1);
136+
NUnit.Framework.Assert.AreEqual(0, first.DistanceSq(first), EPSILON_COMPARISON);
137+
}
138+
139+
[NUnit.Framework.Test]
140+
public virtual void DistanceBetweenCoordinatesTest() {
141+
Point first = new Point(1, 1);
142+
Point second = new Point(1.1, 1.1);
143+
double expected = Math.Sqrt(0.02);
144+
NUnit.Framework.Assert.AreEqual(expected, Point.Distance(first.x, first.y, second.x, second.y), EPSILON_COMPARISON
145+
);
146+
}
147+
148+
[NUnit.Framework.Test]
149+
public virtual void DistanceByCoordinatesTest() {
150+
Point first = new Point(1, 1);
151+
Point second = new Point(1.1, 1.1);
152+
double expected = Math.Sqrt(0.02);
153+
NUnit.Framework.Assert.AreEqual(expected, first.Distance(second.x, second.y), EPSILON_COMPARISON);
154+
}
155+
156+
[NUnit.Framework.Test]
157+
public virtual void DistanceByPointTest() {
158+
Point first = new Point(1, 1);
159+
Point second = new Point(1.1, 1.1);
160+
double expected = Math.Sqrt(0.02);
161+
NUnit.Framework.Assert.AreEqual(expected, first.Distance(second), EPSILON_COMPARISON);
162+
}
163+
164+
[NUnit.Framework.Test]
165+
public virtual void DistanceItselfTest() {
166+
Point first = new Point(1, 1);
167+
NUnit.Framework.Assert.AreEqual(0, first.Distance(first), EPSILON_COMPARISON);
168+
}
169+
170+
[NUnit.Framework.Test]
171+
public virtual void ToStringTest() {
172+
Point first = new Point(1.23, 1.1);
173+
NUnit.Framework.Assert.AreEqual("Point: [x=1.23,y=1.1]", first.ToString());
174+
}
175+
176+
[NUnit.Framework.Test]
177+
public virtual void CloneTest() {
178+
Point first = new Point(1.23, 1.1);
179+
Point clone = (Point)first.Clone();
180+
NUnit.Framework.Assert.AreEqual(first, clone);
181+
NUnit.Framework.Assert.AreEqual(first.GetHashCode(), clone.GetHashCode());
182+
}
183+
184+
[NUnit.Framework.Test]
185+
public virtual void TranslateTest() {
186+
float w = 3.73f;
187+
float h = 5.23f;
188+
Rectangle rectangle = new Rectangle(0, 0, w, h);
189+
Point[] expectedPoints = rectangle.ToPointsArray();
190+
Point point = new Point(0, 0);
191+
point.Translate(w, 0);
192+
NUnit.Framework.Assert.AreEqual(expectedPoints[1], point);
193+
point.Translate(0, h);
194+
NUnit.Framework.Assert.AreEqual(expectedPoints[2], point);
195+
point.Translate(-w, 0);
196+
NUnit.Framework.Assert.AreEqual(expectedPoints[3], point);
197+
point.Translate(0, -h);
198+
NUnit.Framework.Assert.AreEqual(expectedPoints[0], point);
199+
}
200+
201+
[NUnit.Framework.Test]
202+
public virtual void PointVsItLocationTest() {
203+
Point first = new Point(1.23, 1.1);
204+
Point location = first.GetLocation();
205+
NUnit.Framework.Assert.IsTrue(first != location && first.Equals(location));
206+
}
207+
208+
[NUnit.Framework.Test]
209+
public virtual void SetLocationByPointTest() {
210+
Point first = new Point(1.23, 1.1);
211+
Point second = new Point(3.59, 0.87);
212+
NUnit.Framework.Assert.AreNotEqual(first, second);
213+
first.SetLocation(second);
214+
NUnit.Framework.Assert.AreEqual(first, second);
215+
}
216+
217+
[NUnit.Framework.Test]
218+
public virtual void SetLocationByDoubleParamTest() {
219+
Point first = new Point(1.23, 1.1);
220+
Point second = new Point(3.59, 0.87);
221+
NUnit.Framework.Assert.AreNotEqual(first, second);
222+
first.SetLocation(second.x, second.y);
223+
NUnit.Framework.Assert.AreEqual(first, second);
224+
}
225+
226+
[NUnit.Framework.Test]
227+
public virtual void SetLocationByIntParamTest() {
228+
Point first = new Point(1.23, 1.1);
229+
Point second = new Point(3.59, 0.87);
230+
NUnit.Framework.Assert.AreNotEqual(first, second);
231+
first.SetLocation((int)second.x, (int)second.y);
232+
NUnit.Framework.Assert.AreEqual(first, new Point(3, 0));
233+
}
234+
235+
[NUnit.Framework.Test]
236+
public virtual void MovePointTest() {
237+
Point first = new Point(1.23, 1.1);
238+
Point second = new Point(3.59, 0.87);
239+
NUnit.Framework.Assert.AreNotEqual(first, second);
240+
first.Move(second.x, second.y);
241+
NUnit.Framework.Assert.AreEqual(first, second);
242+
}
243+
}
244+
}

port-hash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0c718d95eb162a8526a7aaa4a59696d26691619b
1+
518a91fd51ac2ff426d276ba3cb24b829b5dda2a

0 commit comments

Comments
 (0)