Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing Tolerance.format_number #1380

Merged
merged 8 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)"
Loading