Skip to content

Commit bf90aba

Browse files
committed
tests for str and repr
1 parent 2f3c0c2 commit bf90aba

File tree

6 files changed

+33
-1
lines changed

6 files changed

+33
-1
lines changed

src/compas/geometry/polygon.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def __repr__(self):
105105
return "{0}(points={1!r})".format(type(self).__name__, self.points)
106106

107107
def __str__(self):
108-
return "{0}(points={1})".format(type(self).__name__, [str(point) for point in self.points])
108+
return "{0}(points=[{1}])".format(type(self).__name__, ", ".join([str(point) for point in self.points]))
109109

110110
def __len__(self):
111111
return len(self.points)

tests/compas/geometry/test_frame.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ def test_frame_data():
5555
assert Frame.validate_data(other.__data__)
5656

5757

58+
def test_frame_str_repr():
59+
frame = Frame.worldXY()
60+
assert str(frame) == "Frame(point=Point(x=0.000, y=0.000, z=0.000), xaxis=Vector(x=1.000, y=0.000, z=0.000), yaxis=Vector(x=0.000, y=1.000, z=0.000))"
61+
assert repr(frame) == "Frame(point=Point(x=0.0, y=0.0, z=0.0), xaxis=Vector(x=1.0, y=0.0, z=0.0), yaxis=Vector(x=0.0, y=1.0, z=0.0))"
62+
63+
5864
def test_frame_predefined():
5965
frame = Frame.worldXY()
6066
assert frame.point == Point(0, 0, 0)

tests/compas/geometry/test_plane.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ def test_plane_data():
4646
assert Plane.validate_data(other.__data__)
4747

4848

49+
def test_plane_str_repr():
50+
plane = Plane.worldXY()
51+
assert str(plane) == "Plane(point=Point(x=0.000, y=0.000, z=0.000), normal=Vector(x=0.000, y=0.000, z=1.000))"
52+
assert repr(plane) == "Plane(point=Point(x=0.0, y=0.0, z=0.0), normal=Vector(x=0.0, y=0.0, z=1.0))"
53+
54+
4955
def test_plane_predefined():
5056
plane = Plane.worldXY()
5157
assert plane.point == Point(0, 0, 0)

tests/compas/geometry/test_pointcloud.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ def test_pointcloud_data():
3939
assert Pointcloud.validate_data(other.__data__)
4040

4141

42+
def test_pointcloud_str_repr():
43+
points = [[0, 0, x] for x in range(3)]
44+
pointcloud = Pointcloud(points)
45+
assert str(pointcloud) == "Pointcloud(len(points)=3)"
46+
assert repr(pointcloud) == "Pointcloud(points=[Point(x=0.0, y=0.0, z=0.0), Point(x=0.0, y=0.0, z=1.0), Point(x=0.0, y=0.0, z=2.0)])"
47+
48+
4249
def test_pointcloud__eq__():
4350
a = Pointcloud.from_bounds(10, 10, 10, 10)
4451
points = a.points[:]

tests/compas/geometry/test_polygon.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ def test_polygon_data():
5252
assert Polygon.validate_data(other.__data__)
5353

5454

55+
def test_polygon_str_repr():
56+
points = [[0, 0, x] for x in range(3)]
57+
polygon = Polygon(points)
58+
assert str(polygon) == "Polygon(points=[Point(x=0.000, y=0.000, z=0.000), Point(x=0.000, y=0.000, z=1.000), Point(x=0.000, y=0.000, z=2.000)])"
59+
assert repr(polygon) == "Polygon(points=[Point(x=0.0, y=0.0, z=0.0), Point(x=0.0, y=0.0, z=1.0), Point(x=0.0, y=0.0, z=2.0)])"
60+
61+
5562
def test_polygon__eq__():
5663
points1 = [[0, 0, x] for x in range(5)]
5764
polygon1 = Polygon(points1)

tests/compas/geometry/test_quaternion.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ def test_quaternion_data():
6464
assert Quaternion.validate_data(other.__data__)
6565

6666

67+
def test_quaternion_str_repr():
68+
quaternion = Quaternion(0.5, 0.5, 0.5, 0.5)
69+
assert str(quaternion) == "Quaternion(0.500, 0.500, 0.500, 0.500)"
70+
assert repr(quaternion) == "Quaternion(0.5, 0.5, 0.5, 0.5)"
71+
72+
6773
# =============================================================================
6874
# Properties and Geometry
6975
# =============================================================================

0 commit comments

Comments
 (0)