diff options
author | Vincent Rouvreau <10407034+VincentRouvreau@users.noreply.github.com> | 2022-04-11 09:39:16 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-11 09:39:16 +0200 |
commit | a43ca657787745e8b945943987b313106ec67f1f (patch) | |
tree | 7958e4bfc128cd0cb0c2cf02857be17b7b3f57cd /src/python/test | |
parent | b066b4376abf66ddc76e61a6a815a409b05fe59b (diff) | |
parent | 25172af7cbe5a3ea3017bed6fde53be471a7e4bf (diff) |
Merge pull request #596 from VincentRouvreau/float_relative_precision_alpha_python
Float relative precision alpha python
Diffstat (limited to 'src/python/test')
-rwxr-xr-x | src/python/test/test_alpha_complex.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/python/test/test_alpha_complex.py b/src/python/test/test_alpha_complex.py index f15284f3..f81e6137 100755 --- a/src/python/test/test_alpha_complex.py +++ b/src/python/test/test_alpha_complex.py @@ -286,3 +286,30 @@ def _weighted_doc_example(precision): def test_weighted_doc_example(): for precision in ['fast', 'safe', 'exact']: _weighted_doc_example(precision) + +def test_float_relative_precision(): + assert AlphaComplex.get_float_relative_precision() == 1e-5 + # Must be > 0. + with pytest.raises(ValueError): + AlphaComplex.set_float_relative_precision(0.) + # Must be < 1. + with pytest.raises(ValueError): + AlphaComplex.set_float_relative_precision(1.) + + points = [[1, 1], [7, 0], [4, 6], [9, 6], [0, 14], [2, 19], [9, 17]] + st = AlphaComplex(points=points).create_simplex_tree() + filtrations = list(st.get_filtration()) + + # Get a better precision + AlphaComplex.set_float_relative_precision(1e-15) + assert AlphaComplex.get_float_relative_precision() == 1e-15 + + st = AlphaComplex(points=points).create_simplex_tree() + filtrations_better_resolution = list(st.get_filtration()) + + assert len(filtrations) == len(filtrations_better_resolution) + for idx in range(len(filtrations)): + # check simplex is the same + assert filtrations[idx][0] == filtrations_better_resolution[idx][0] + # check filtration is about the same with a relative precision of the worst case + assert filtrations[idx][1] == pytest.approx(filtrations_better_resolution[idx][1], rel=1e-5) |