Skip to content

Commit 82af17e

Browse files
authored
Merge pull request #1380 from compas-dev/yck011522/test_tol_format_number
Testing Tolerance.format_number
2 parents f4cf9cb + 31da190 commit 82af17e

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

tests/compas/files/test_gltf.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from compas.files import GLTFContent
66
from compas.tolerance import TOL
77

8+
# Temporary change the global precision in the TOL class to 12
89
TOL.precision = 12
910

1011
BASE_FOLDER = os.path.dirname(__file__)
@@ -175,3 +176,7 @@ def test_gltf_content():
175176
assert len(node_0.children) == 0
176177
assert len(content.nodes) == 1
177178
assert len(scene.nodes) == 1
179+
180+
181+
# Reset the precision to its default value
182+
TOL.precision = TOL.PRECISION

tests/compas/files/test_stl.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from compas.files import STL
66
from compas.tolerance import TOL
77

8+
# Temporary change the global precision in the TOL class to 12
89
TOL.precision = 12
910

1011
BASE_FOLDER = os.path.dirname(__file__)
@@ -43,3 +44,7 @@ def test_binary_read_write_fidelity():
4344
mesh_2 = Mesh.from_stl(fp)
4445
assert mesh.adjacency == mesh_2.adjacency
4546
assert mesh.vertex == mesh_2.vertex
47+
48+
49+
# Reset the precision to its default value
50+
TOL.precision = TOL.PRECISION

tests/compas/test_tolerance.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from compas.tolerance import TOL
2+
from compas.tolerance import Tolerance
3+
from compas.geometry import Point
4+
5+
6+
def test_tolerance_default_tolerance():
7+
assert TOL.precision == Tolerance.PRECISION
8+
assert TOL.precision == 3
9+
10+
11+
def test_tolerance_format_number():
12+
assert TOL.format_number(0, precision=3) == "0.000"
13+
assert TOL.format_number(0.5, precision=3) == "0.500"
14+
assert TOL.format_number(float(0), precision=3) == "0.000"
15+
16+
17+
def test_tolerance_format_number_with_default_precision():
18+
assert TOL.format_number(0) == "0.000"
19+
assert TOL.format_number(0.5) == "0.500"
20+
assert TOL.format_number(float(0)) == "0.000"
21+
22+
23+
def test_tolerance_format_point():
24+
point = Point(0, 0, 0)
25+
assert str(point) == "Point(x=0.000, y=0.000, z=0.000)"

0 commit comments

Comments
 (0)