Skip to content

Commit 85f9086

Browse files
committed
Add tests for geometry/point
1 parent c094f1b commit 85f9086

File tree

1 file changed

+51
-2
lines changed

1 file changed

+51
-2
lines changed

sympy/geometry/tests/test_point.py

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
from sympy import I, Rational, Symbol, pi, sqrt, S
1+
from sympy import I, Rational, Symbol, pi, sqrt, sympify, S, Basic
22
from sympy.geometry import Line, Point, Point2D, Point3D, Line3D, Plane
3-
from sympy.geometry.entity import rotate, scale, translate
3+
from sympy.geometry.entity import rotate, scale, translate, GeometryEntity
44
from sympy.matrices import Matrix
55
from sympy.utilities.iterables import subsets, permutations, cartes
6+
from sympy.utilities.misc import Undecidable
67
from sympy.testing.pytest import raises, warns
78

89

@@ -27,6 +28,8 @@ def test_point():
2728
assert (p3 + p4) == p4
2829
assert (p2 - p1) == Point(y1 - x1, y2 - x2)
2930
assert -p2 == Point(-y1, -y2)
31+
raises(TypeError, lambda: Point(1))
32+
raises(ValueError, lambda: Point([1]))
3033
raises(ValueError, lambda: Point(3, I))
3134
raises(ValueError, lambda: Point(2*I, I))
3235
raises(ValueError, lambda: Point(3 + I, I))
@@ -36,10 +39,13 @@ def test_point():
3639
assert Point.midpoint(p1, p4) == Point(half + half*x1, half + half*x2)
3740
assert Point.midpoint(p2, p2) == p2
3841
assert p2.midpoint(p2) == p2
42+
assert p1.origin == Point(0, 0)
3943

4044
assert Point.distance(p3, p4) == sqrt(2)
4145
assert Point.distance(p1, p1) == 0
4246
assert Point.distance(p3, p2) == sqrt(p2.x**2 + p2.y**2)
47+
raises(TypeError, lambda: Point.distance(p1, 0))
48+
raises(TypeError, lambda: Point.distance(p1, GeometryEntity()))
4349

4450
# distance should be symmetric
4551
assert p1.distance(line) == line.distance(p1)
@@ -48,6 +54,7 @@ def test_point():
4854
assert Point.taxicab_distance(p4, p3) == 2
4955

5056
assert Point.canberra_distance(p4, p5) == 1
57+
raises(ValueError, lambda: Point.canberra_distance(p3, p3))
5158

5259
p1_1 = Point(x1, x1)
5360
p1_2 = Point(y2, y2)
@@ -67,6 +74,8 @@ def test_point():
6774

6875
assert p3.intersection(Point(0, 0)) == [p3]
6976
assert p3.intersection(p4) == []
77+
assert p3.intersection(line) == []
78+
assert Point.intersection(Point(0, 0, 0), Point(0, 0)) == [Point(0, 0, 0)]
7079

7180
x_pos = Symbol('x', real=True, positive=True)
7281
p2_1 = Point(x_pos, 0)
@@ -81,6 +90,25 @@ def test_point():
8190
assert Point.is_concyclic(*pts) is False
8291
assert Point.is_concyclic(p4, p4 * 2, p4 * 3) is False
8392
assert Point(0, 0).is_concyclic((1, 1), (2, 2), (2, 1)) is False
93+
assert Point.is_concyclic(Point(0, 0, 0, 0), Point(1, 0, 0, 0), Point(1, 1, 0, 0), Point(1, 1, 1, 0)) is False
94+
95+
assert p1.is_scalar_multiple(p1)
96+
assert p1.is_scalar_multiple(2*p1)
97+
assert not p1.is_scalar_multiple(p2)
98+
assert Point.is_scalar_multiple(Point(1, 1), (-1, -1))
99+
assert Point.is_scalar_multiple(Point(0, 0), (0, -1))
100+
# test when is_scalar_multiple can't be determined
101+
raises(Undecidable, lambda: Point.is_scalar_multiple(Point(sympify("x1%y1"), sympify("x2%y2")), Point(0, 1)))
102+
103+
assert Point(0, 1).orthogonal_direction == Point(1, 0)
104+
assert Point(1, 0).orthogonal_direction == Point(0, 1)
105+
106+
assert p1.is_zero is None
107+
assert p3.is_zero
108+
assert p4.is_zero is False
109+
assert p1.is_nonzero is None
110+
assert p3.is_nonzero is False
111+
assert p4.is_nonzero
84112

85113
assert p4.scale(2, 3) == Point(2, 3)
86114
assert p3.scale(2, 3) == p3
@@ -103,6 +131,11 @@ def test_point():
103131
Point(a.n(2), b.n(2), evaluate=False)
104132
raises(ValueError, lambda: Point(1, 2) + 1)
105133

134+
# test project
135+
assert Point.project((0, 1), (1, 0)) == Point(0, 0)
136+
assert Point.project((1, 1), (1, 0)) == Point(1, 0)
137+
raises(ValueError, lambda: Point.project(p1, Point(0, 0)))
138+
106139
# test transformations
107140
p = Point(1, 0)
108141
assert p.rotate(pi/2) == Point(0, 1)
@@ -118,6 +151,13 @@ def test_point():
118151
raises(ValueError, lambda: p3.transform(p3))
119152
raises(ValueError, lambda: p.transform(Matrix([[1, 0], [0, 1]])))
120153

154+
# test __contains__
155+
assert 0 in Point(0, 0, 0, 0)
156+
assert 1 not in Point(0, 0, 0, 0)
157+
158+
# test affine_rank
159+
assert Point.affine_rank() == -1
160+
121161

122162
def test_point3D():
123163
x = Symbol('x', real=True)
@@ -277,6 +317,9 @@ def test_Point2D():
277317
assert p1.coordinates == (1, 5)
278318
assert p2.coordinates == (4, 2.5)
279319

320+
# test bounds
321+
assert p1.bounds == (1, 5, 1, 5)
322+
280323
def test_issue_9214():
281324
p1 = Point3D(4, -2, 6)
282325
p2 = Point3D(1, 2, 3)
@@ -381,6 +424,12 @@ def test_arguments():
381424
# never raise error if creating an origin
382425
assert Point(dim=3, on_morph='error')
383426

427+
# raise error with unmatched dimension
428+
raises(ValueError, lambda: Point(1, 1, dim=3, on_morph='error'))
429+
# test unknown on_morph
430+
raises(ValueError, lambda: Point(1, 1, dim=3, on_morph='unknown'))
431+
# test invalid expressions
432+
raises(TypeError, lambda: Point(Basic(), Basic()))
384433

385434
def test_unit():
386435
assert Point(1, 1).unit == Point(sqrt(2)/2, sqrt(2)/2)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy