Skip to content

Commit

Permalink
Merge pull request #1380 from compas-dev/yck011522/test_tol_format_nu…
Browse files Browse the repository at this point in the history
…mber

Testing Tolerance.format_number
  • Loading branch information
yck011522 committed Jul 18, 2024
2 parents f4cf9cb + 31da190 commit 82af17e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tests/compas/files/test_gltf.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from compas.files import GLTFContent
from compas.tolerance import TOL

# Temporary change the global precision in the TOL class to 12
TOL.precision = 12

BASE_FOLDER = os.path.dirname(__file__)
Expand Down Expand Up @@ -175,3 +176,7 @@ def test_gltf_content():
assert len(node_0.children) == 0
assert len(content.nodes) == 1
assert len(scene.nodes) == 1


# Reset the precision to its default value
TOL.precision = TOL.PRECISION
5 changes: 5 additions & 0 deletions tests/compas/files/test_stl.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from compas.files import STL
from compas.tolerance import TOL

# Temporary change the global precision in the TOL class to 12
TOL.precision = 12

BASE_FOLDER = os.path.dirname(__file__)
Expand Down Expand Up @@ -43,3 +44,7 @@ def test_binary_read_write_fidelity():
mesh_2 = Mesh.from_stl(fp)
assert mesh.adjacency == mesh_2.adjacency
assert mesh.vertex == mesh_2.vertex


# Reset the precision to its default value
TOL.precision = TOL.PRECISION
25 changes: 25 additions & 0 deletions tests/compas/test_tolerance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from compas.tolerance import TOL
from compas.tolerance import Tolerance
from compas.geometry import Point


def test_tolerance_default_tolerance():
assert TOL.precision == Tolerance.PRECISION
assert TOL.precision == 3


def test_tolerance_format_number():
assert TOL.format_number(0, precision=3) == "0.000"
assert TOL.format_number(0.5, precision=3) == "0.500"
assert TOL.format_number(float(0), precision=3) == "0.000"


def test_tolerance_format_number_with_default_precision():
assert TOL.format_number(0) == "0.000"
assert TOL.format_number(0.5) == "0.500"
assert TOL.format_number(float(0)) == "0.000"


def test_tolerance_format_point():
point = Point(0, 0, 0)
assert str(point) == "Point(x=0.000, y=0.000, z=0.000)"

0 comments on commit 82af17e

Please sign in to comment.