diff --git a/tests/compas/files/test_gltf.py b/tests/compas/files/test_gltf.py index 4e680ad3025..b921ad5adb8 100644 --- a/tests/compas/files/test_gltf.py +++ b/tests/compas/files/test_gltf.py @@ -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__) @@ -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 diff --git a/tests/compas/files/test_stl.py b/tests/compas/files/test_stl.py index 5f0aa4b5a3c..bb6ed2cddba 100644 --- a/tests/compas/files/test_stl.py +++ b/tests/compas/files/test_stl.py @@ -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__) @@ -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 diff --git a/tests/compas/test_tolerance.py b/tests/compas/test_tolerance.py new file mode 100644 index 00000000000..792137f59d9 --- /dev/null +++ b/tests/compas/test_tolerance.py @@ -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)"