From edee14f62f0edac37a3f1e587c99e11a2e8e2917 Mon Sep 17 00:00:00 2001 From: Victor LEUNG Date: Wed, 10 Jul 2024 11:03:49 +0800 Subject: [PATCH 1/8] Test Tolerance Format Number --- tests/compas/test_tolerance.py | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 tests/compas/test_tolerance.py diff --git a/tests/compas/test_tolerance.py b/tests/compas/test_tolerance.py new file mode 100644 index 00000000000..4580b23b076 --- /dev/null +++ b/tests/compas/test_tolerance.py @@ -0,0 +1,6 @@ +from compas.tolerance import TOL + + +def test_tolerance_format_number(): + assert TOL.format_number(0, precision=3) == "0.000" + assert TOL.format_number(0.5, precision=3) == "0.500" From e2b9b82cf46dcf379e97870682e1b9274b81e817 Mon Sep 17 00:00:00 2001 From: Victor LEUNG Date: Wed, 10 Jul 2024 11:12:00 +0800 Subject: [PATCH 2/8] more tests --- tests/compas/test_tolerance.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/compas/test_tolerance.py b/tests/compas/test_tolerance.py index 4580b23b076..65f94802807 100644 --- a/tests/compas/test_tolerance.py +++ b/tests/compas/test_tolerance.py @@ -1,6 +1,18 @@ from compas.tolerance import TOL +from compas.geometry import Point 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" + + # Using 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)" From 4db4c12cda8218bd185d2c2913e7c3569eef9c21 Mon Sep 17 00:00:00 2001 From: Victor LEUNG Date: Wed, 10 Jul 2024 11:23:11 +0800 Subject: [PATCH 3/8] default precision problem? --- tests/compas/test_tolerance.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/compas/test_tolerance.py b/tests/compas/test_tolerance.py index 65f94802807..9bb938023f9 100644 --- a/tests/compas/test_tolerance.py +++ b/tests/compas/test_tolerance.py @@ -1,13 +1,19 @@ from compas.tolerance import TOL +from compas.tolerance import Tolerance from compas.geometry import Point +def test_tolerance_default_tolerance(): + TOL.precision == Tolerance.PRECISION + + 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" - # Using default precision + +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" From 423e665db1bdee816feba52c05ead67f549a3b0b Mon Sep 17 00:00:00 2001 From: Victor LEUNG Date: Wed, 10 Jul 2024 11:28:33 +0800 Subject: [PATCH 4/8] default precision is 3? --- tests/compas/test_tolerance.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/compas/test_tolerance.py b/tests/compas/test_tolerance.py index 9bb938023f9..8b4ae9373e2 100644 --- a/tests/compas/test_tolerance.py +++ b/tests/compas/test_tolerance.py @@ -5,6 +5,7 @@ def test_tolerance_default_tolerance(): TOL.precision == Tolerance.PRECISION + TOL.precision == 3 def test_tolerance_format_number(): From f7d962a0d44c43186916d095d271be0ac2ead786 Mon Sep 17 00:00:00 2001 From: Victor LEUNG Date: Wed, 10 Jul 2024 11:32:42 +0800 Subject: [PATCH 5/8] forgot the assert --- tests/compas/test_tolerance.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/compas/test_tolerance.py b/tests/compas/test_tolerance.py index 8b4ae9373e2..792137f59d9 100644 --- a/tests/compas/test_tolerance.py +++ b/tests/compas/test_tolerance.py @@ -4,8 +4,8 @@ def test_tolerance_default_tolerance(): - TOL.precision == Tolerance.PRECISION - TOL.precision == 3 + assert TOL.precision == Tolerance.PRECISION + assert TOL.precision == 3 def test_tolerance_format_number(): From f4fc15940b4d6ccfef1337d5b91a4077d600fae8 Mon Sep 17 00:00:00 2001 From: Victor LEUNG Date: Thu, 11 Jul 2024 14:27:48 +0800 Subject: [PATCH 6/8] Fix global precision in two test files bleeding to other tests --- tests/compas/files/test_gltf.py | 5 +++++ tests/compas/files/test_stl.py | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/tests/compas/files/test_gltf.py b/tests/compas/files/test_gltf.py index 4e680ad3025..d888d94fef7 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 = 3 diff --git a/tests/compas/files/test_stl.py b/tests/compas/files/test_stl.py index 5f0aa4b5a3c..db6eea6e9ae 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 = 3 From e2513cf5eaf1e6d299e449bcb2cf348ee5703652 Mon Sep 17 00:00:00 2001 From: Victor LEUNG Date: Fri, 12 Jul 2024 08:07:34 +0200 Subject: [PATCH 7/8] Update test_gltf.py --- tests/compas/files/test_gltf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/compas/files/test_gltf.py b/tests/compas/files/test_gltf.py index d888d94fef7..b921ad5adb8 100644 --- a/tests/compas/files/test_gltf.py +++ b/tests/compas/files/test_gltf.py @@ -179,4 +179,4 @@ def test_gltf_content(): # Reset the precision to its default value -TOL.precision = 3 +TOL.precision = TOL.PRECISION From 31da1909b367187850d8041e9716e14c9a0ca60d Mon Sep 17 00:00:00 2001 From: Victor LEUNG Date: Fri, 12 Jul 2024 08:07:59 +0200 Subject: [PATCH 8/8] Update test_stl.py --- tests/compas/files/test_stl.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/compas/files/test_stl.py b/tests/compas/files/test_stl.py index db6eea6e9ae..bb6ed2cddba 100644 --- a/tests/compas/files/test_stl.py +++ b/tests/compas/files/test_stl.py @@ -47,4 +47,4 @@ def test_binary_read_write_fidelity(): # Reset the precision to its default value -TOL.precision = 3 +TOL.precision = TOL.PRECISION