diff options
Diffstat (limited to 'src/cython/test')
-rwxr-xr-x | src/cython/test/test_cubical_complex.py | 10 | ||||
-rwxr-xr-x | src/cython/test/test_persistence_representations_intervals.py | 87 | ||||
-rwxr-xr-x | src/cython/test/test_persistence_representations_landscapes.py | 139 | ||||
-rwxr-xr-x | src/cython/test/test_persistence_representations_landscapes_on_grid.py | 120 | ||||
-rwxr-xr-x | src/cython/test/test_reader_utils.py | 88 | ||||
-rwxr-xr-x | src/cython/test/test_simplex_tree.py | 39 |
6 files changed, 128 insertions, 355 deletions
diff --git a/src/cython/test/test_cubical_complex.py b/src/cython/test/test_cubical_complex.py index 9a365823..0e81554d 100755 --- a/src/cython/test/test_cubical_complex.py +++ b/src/cython/test/test_cubical_complex.py @@ -62,17 +62,17 @@ def test_dimension_or_perseus_file_constructor(): assert cub.__is_defined() == False assert cub.__is_persistence_defined() == False -def test_dimension_constructor(): +def test_dimension_simple_constructor(): cub = CubicalComplex(dimensions=[3, 3], top_dimensional_cells = [1,2,3,4,5,6,7,8,9]) assert cub.__is_defined() == True assert cub.__is_persistence_defined() == False - assert cub.persistence() == [(1, (0.0, 100.0)), (0, (0.0, float('inf')))] + assert cub.persistence() == [(0, (1.0, float('inf')))] assert cub.__is_persistence_defined() == True - assert cub.betti_numbers() == [1, 0] - assert cub.persistent_betti_numbers(0, 1000) == [0, 0] + assert cub.betti_numbers() == [1, 0, 0] + assert cub.persistent_betti_numbers(0, 1000) == [0, 0, 0] -def test_dimension_constructor(): +def test_dimension_file_constructor(): # Create test file test_file = open('CubicalOneSphere.txt', 'w') test_file.write('2\n3\n3\n0\n0\n0\n0\n100\n0\n0\n0\n0\n') diff --git a/src/cython/test/test_persistence_representations_intervals.py b/src/cython/test/test_persistence_representations_intervals.py deleted file mode 100755 index a8f3686e..00000000 --- a/src/cython/test/test_persistence_representations_intervals.py +++ /dev/null @@ -1,87 +0,0 @@ -import gudhi - -"""This file is part of the Gudhi Library. The Gudhi library - (Geometric Understanding in Higher Dimensions) is a generic C++ - library for computational topology. - - Author(s): Pawel Dlotko - - Copyright (C) 2017 Swansea University - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. -""" - -__author__ = "Pawel Dlotko" -__copyright__ = "Copyright (C) 2017 Swansea University" -__license__ = "GPL v3" - -epsilon = 0.0000005; - -def test_check_min_max_function(): - p = gudhi.PersistenceIntervals(None,None,"data/file_with_diagram") - min_max_ = p.get_x_range() - assert fabs(min_max_[0] - 0.0290362) <= epsilon - assert fabs(min_max_[1] - 0.994537) <= epsilon - -def test_check_length_of_dominant_intervals(): - p = gudhi.PersistenceIntervals(None,None,"data/file_with_diagram") - dominant_ten_intervals_length = p.length_of_dominant_intervals(10) - dominant_intervals_length_ = [0.862625,0.800893,0.762061,0.756501,0.729367,0.718177,0.708395,0.702844,0.700468,0.622177] - assert dominant_ten_intervals_length == dominant_intervals_length_ - - -def test_check_dominant_intervals(): - p = gudhi.PersistenceIntervals(None,None,"data/file_with_diagram"); - ten_dominant_intervals = p.dominant_intervals(10); - templ = [ (0.114718, 0.977343) , (0.133638, 0.93453) , (0.104599, 0.866659) , (0.149798, 0.906299), (0.247352, 0.976719) , (0.192675, 0.910852) , (0.191836, 0.900231) , (0.284998, 0.987842) , (0.294069, 0.994537), (0.267421, 0.889597)] - assert fabs(ten_dominant_intervals - templ) <= epsilon - - -def test_check_histogram_of_lengths(): - p = gudhi.PersistenceIntervals(None,None,"data/file_with_diagram") - histogram = p.histogram_of_lengths(10); - template_histogram = [10,5,3,4,4,3,6,1,7,1,1] - assert fabs(histogram - template_histogram) <= epsilon - - -def test_check_cumulative_histograms_of_lengths(): - p = gudhi.PersistenceIntervals(None,None,"data/file_with_diagram") - cumulative_histogram = p.cumulative_histogram_of_lengths(10) - template_cumulative_histogram = [10,15,18,22,26,29,35,36,43,44,45] - assert fabs(cumulative_histogram - template_cumulative_histogram) <= epsilon - - -def test_check_characteristic_function_of_diagram(): - p = gudhi.PersistenceIntervals(None,None,"data/file_with_diagram") - min_max_ = p.get_x_range(); - char_funct_diag = p.characteristic_function_of_diagram(min_max_[0], min_max_[1]); - template_char_funct_diag = [0.370665,0.84058,1.24649,1.3664,1.34032,1.31904,1.14076,0.991259,0.800714,0.0676303] - assert fabs(char_funct_diag - template_char_funct_diag) <= 0.0001 - - -def test_check_cumulative_characteristic_function_of_diagram(): - p = gudhi.PersistenceIntervals(None,None,"data/file_with_diagram") - min_max_ = p.get_x_range() - cumul_char_funct_diag = p.cumulative_characteristic_function_of_diagram(min_max_.first, min_max_.second,None); - template_char_funct_diag_cumul = [0.370665,1.21125,2.45774,3.82414,5.16446,6.4835,7.62426,8.61552,9.41623,9.48386] - assert fabs(cumul_char_funct_diag - template_char_funct_diag_cumul) <= 0.0001 - - -def test_check_compute_persistent_betti_numbers(): - p = gudhi.PersistenceIntervals(None,None,"data/file_with_diagram") - pbns = [(0.0290362, 1),(0.0307676, 2),(0.0366312, 3),(0.0544614, 4),(0.0920033, 5),(0.104599, 6),(0.114718, 7),(0.117379, 8),(0.123493, 9),(0.133638, 10)(0.137798, 9),(0.149798, 10),(0.155421, 11),(0.158443, 12)(0.176956, 13),(0.183234, 12),(0.191069, 13),(0.191333, 14),(0.191836, 15),(0.192675, 16),(0.208564, 17),(0.218425, 18),(0.219902, 17),(0.23233, 16),(0.234558, 17),(0.237166, 16),(0.247352, 17),(0.267421, 18),(0.268093, 19),(0.278734, 18),(0.284722, 19),(0.284998, 20),(0.294069, 21),(0.306293, 22),(0.322361, 21),(0.323152, 22),(0.371021, 23),(0.372395, 24),(0.387744, 25),(0.435537, 26),(0.462911, 25),(0.483569, 26),(0.489209, 25),(0.517115, 24),(0.522197, 23),(0.532665, 22),(0.545262, 23),(0.587227, 22),(0.593036, 23),(0.602647, 24),(0.605044, 25),(0.621962, 24),(0.629449, 23),(0.636719, 22),(0.64957, 21),(0.650781, 22),(0.654951, 23),(0.683489, 24),(0.687172, 23),(0.69703, 22),(0.701174, 21),(0.717623, 22),(0.722023, 21),(0.722298, 20),(0.725347, 19),(0.73071, 18),(0.758355, 17),(0.770913, 18),(0.790833, 17),(0.821211, 16),(0.849305, 17),(0.853669, 16),(0.866659, 15),(0.872896, 16),(0.889597, 15),(0.900231, 14),(0.903847, 13),(0.906299, 12),(0.910852, 11),(0.93453, 10),(0.944757, 9),(0.947812, 8),(0.959154, 7),(0.975654, 6),(0.976719, 5),(0.977343, 4),(0.980129, 3),(0.987842, 2),(0.990127, 1),(0.994537, 0)] - pbns_new = p.compute_persistent_betti_numbers(); - assert fabs(pbns - pbns_new) <= epsilon - - diff --git a/src/cython/test/test_persistence_representations_landscapes.py b/src/cython/test/test_persistence_representations_landscapes.py deleted file mode 100755 index f5e6f351..00000000 --- a/src/cython/test/test_persistence_representations_landscapes.py +++ /dev/null @@ -1,139 +0,0 @@ -import gudhi - -""" - This file is part of the Gudhi Library. The Gudhi library - (Geometric Understanding in Higher Dimensions) is a generic C++ - library for computational topology. - - Author(s): Pawel Dlotko - - Copyright (C) 2017 Swansea University - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. -""" - -__author__ = "Pawel Dlotko" -__copyright__ = "Copyright (C) 2017 Swansea University" -__license__ = "GPL v3" - -epsilon = 0.0000005; - -def test_check_construction_of_landscape(): - p = gudhi.Persistence_landscape("data/file_with_diagram",0) - q = gudhi.Persistence_landscape() - q.load_landscape_from_file("data/file_with_landscape_from_file_with_diagram") - assert p == q - - -def test_check_construction_of_landscape_form_gudhi_style_file(): - p = gudhi.Persistence_landscape("data/persistence_file_with_four_entries_per_line", 1) - q = gudhi.Persistence_landscape() - q.load_landscape_from_file("data/persistence_file_with_four_entries_per_line_landscape"); - assert p == q; - -def test_check_computations_of_integrals(): - p = gudhi.Persistence_landscape("data/file_with_diagram",0) - integral = p.compute_integral_of_landscape() - assert fabs(integral - 2.34992) <= 0.00001 - - -def test_check_computations_of_integrals_for_each_level_separatelly(): - diag = read_persistence_intervals_in_one_dimension_from_file("data/file_with_diagram"); - p = gudhi.Persistence_landscape(diag) - integrals_for_different_levels = [0.216432,0.204763,0.188793,0.178856,0.163142,0.155015,0.143046,0.133765,0.123531,0.117393,0.111269,0.104283,0.0941308,0.0811208,0.0679001,0.0580801,0.0489647,0.0407936,0.0342599,0.02896,0.0239881,0.0171792,0.0071511,0.00462067,0.00229033,0.000195296] - for lv in range(0, len(integrals_for_different_levels)): - integral = p.compute_integral_of_a_level_of_a_landscape(lv); - assert fabs(integral - integrals_fir_different_levels[lv]) <= 0.00001 - -def test_check_computations_of_integrals_of_powers_of_landscape(): - diag = read_persistence_intervals_in_one_dimension_from_file("data/file_with_diagram") - p = gudhi.Persistence_landscape(diag) - integrals_fir_different_powers = [17.1692,2.34992,0.49857,0.126405,0.0355235] - for power in range(0,5): - integral = p.compute_integral_of_landscape(power) - assert fabs(integral - integrals_fir_different_powers[power]) <= 0.00005 - - -def test_check_computations_of_values_on_different_points(): - diag = read_persistence_intervals_in_one_dimension_from_file("data/file_with_diagram") - p = gudhi.Persistence_landscape(diag); - assert fabs(p.compute_value_at_a_given_point(1, 0.0)) <= 0.00001 - assert fabs(p.compute_value_at_a_given_point(1, 0.1) - 0.0692324) <= 0.00001 - assert fabs(p.compute_value_at_a_given_point(1, 0.2) - 0.163369) <= 0.00001 - assert fabs(p.compute_value_at_a_given_point(1, 0.3) - 0.217115) <= 0.00001 - assert fabs(p.compute_value_at_a_given_point(2, 0.0)) <= 0.00001 - assert fabs(p.compute_value_at_a_given_point(2, 0.1) - 0.0633688) <= 0.00001 - assert fabs(p.compute_value_at_a_given_point(2, 0.2) - 0.122361) <= 0.00001 - assert fabs(p.compute_value_at_a_given_point(2, 0.3) - 0.195401) <= 0.00001 - assert fabs(p.compute_value_at_a_given_point(3, 0.0)) <= 0.00001 - assert fabs(p.compute_value_at_a_given_point(3, 0.1) - 0.0455386) <= 0.00001 - assert fabs(p.compute_value_at_a_given_point(3, 0.2) - 0.0954012) <= 0.00001 - assert fabs(p.compute_value_at_a_given_point(3, 0.3) - 0.185282) <= 0.00001 - - -def test_check_computations_of_maxima_and_norms(): - diag = read_persistence_intervals_in_one_dimension_from_file("data/file_with_diagram") - p = gudhi.Persistence_landscape(diag) - second = gudhi.Persistence_landscape() - second.load_landscape_from_file("data/file_with_landscape_from_file_with_diagram_1") - sum_ = gudhi.Persistence_landscape() - sum_ = p + second; - assert fabs(p.compute_maximum() - 0.431313) <= 0.00001 - assert fabs(p.compute_norm_of_landscape(1) - 2.34992) <= 0.00001 - assert fabs(p.compute_norm_of_landscape(2) - 0.706095) <= 0.00001 - assert fabs(p.compute_norm_of_landscape(3) - 0.501867) <= 0.00001 - assert fabs(compute_distance_of_landscapes(p, sum_, 1) - 27.9323) <= 0.00005 - assert fabs(compute_distance_of_landscapes(p, sum_, 2) - 2.35199) <= 0.00001 - - - -def test_check_default_parameters_of_distances(): - diag = read_persistence_intervals_in_one_dimension_from_file("data/file_with_diagram") - p = gudhi.Persistence_landscape(diag) - diag1 = read_persistence_intervals_in_one_dimension_from_file("data/file_with_diagram_1") - q = gudhi.Persistence_landscape(diag1) - dist_numeric_limit_max = p.distance(q, sys.float_info.max); - dist_infinity = p.distance(q, sys.float_info.max); - assert dist_numeric_limit_max == dist_infinity - - -def test_check_computations_of_averages(): - diag = read_persistence_intervals_in_one_dimension_from_file("data/file_with_diagram") - p = gudhi.Persistence_landscape(diag) - diag2 = read_persistence_intervals_in_one_dimension_from_file("data/file_with_diagram_1") - q = gudhi.Persistence_landscape(diag2) - av = gudhi.Persistence_landscape() - av.compute_average({p, q}) - template_average = Persistence_landscape() - template_averagetemplate_average.load_landscape_from_file("data/average") - assert template_average == av - - -def test_check_computations_of_distances(): - diag = read_persistence_intervals_in_one_dimension_from_file("data/file_with_diagram") - p = gudhi.Persistence_landscape(diag) - diag2 = read_persistence_intervals_in_one_dimension_from_file("data/file_with_diagram_1") - q = Persistence_landscape(diag2) - assert fabs(p.distance(q) - 25.5824) <= 0.00005 - assert fabs(p.distance(q, 2) - 2.12636) <= 0.00001 - assert fabs(p.distance(q, sys.float_info.max) - 0.359068) <= 0.00001 - - -def test_check_computations_of_scalar_product(): - diag = read_persistence_intervals_in_one_dimension_from_file("data/file_with_diagram") - p = gudhi.Persistence_landscape(diag) - diag2 = read_persistence_intervals_in_one_dimension_from_file("data/file_with_diagram_1") - q = Persistence_landscape(diag2) - assert fabs(p.compute_scalar_product(q) - 0.754498) <= 0.00001 - diff --git a/src/cython/test/test_persistence_representations_landscapes_on_grid.py b/src/cython/test/test_persistence_representations_landscapes_on_grid.py deleted file mode 100755 index 7a1f2b49..00000000 --- a/src/cython/test/test_persistence_representations_landscapes_on_grid.py +++ /dev/null @@ -1,120 +0,0 @@ -import gudhi - -""" - This file is part of the Gudhi Library. The Gudhi library - (Geometric Understanding in Higher Dimensions) is a generic C++ - library for computational topology. - - Author(s): Pawel Dlotko - - Copyright (C) 2017 Swansea University - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. -""" - -__author__ = "Pawel Dlotko" -__copyright__ = "Copyright (C) 2017 Swansea University" -__license__ = "GPL v3" - -epsilon = 0.0000005; - - - -def test_check_construction_of_landscape: - l = gudhi.PersistenceLandscapeOnGrid("data/file_with_diagram_1", 100,sys.maxsize) - l.print_to_file("landscape_from_file_with_diagram_1") - g = gudhi.PersistenceLandscapeOnGrid() - g.load_landscape_from_file("landscape_from_file_with_diagram_1") - assert l == g - - -def test_check_construction_of_landscape_using_only_ten_levels: - number = 10 - l = gudhi.PersistenceLandscapeOnGrid("data/file_with_diagram_1", 100, number) - g = gudhi.PersistenceLandscapeOnGrid("data/file_with_diagram_1", 100, sys.maxsize) - for level in range(0,number): - v1 = l.vectorize(level) - v2 = g.vectorize(level) - assert v1 == v2 - -def test_check_computations_of_integrals: - p = gudhi.PersistenceLandscapeOnGrid("data/file_with_diagram_1", 100, sys.maxsize) - integral = p.compute_integral_of_landscape() - assert fabs(integral - 27.343) <= 0.00005 - -def test_check_computations_of_integrals_for_each_level_separatelly: - p = gudhi.PersistenceLandscapeOnGrid("data/file_with_diagram_1", 100, sys.maxsize) - integrals_fir_different_levels = [0.241168,0.239276,0.237882,0.235193,0.230115,0.227626,0.226132.0.223643,0.221651,0.220556,0.21727,0.215976,0.213685,0.211993,0.2102,0.208707,0.207014,0.205122,0.204226,0.202633] - for level in range(0,len(integrals_fir_different_levels)) - integral = p.compute_integral_of_landscape(level); - assert fabs(integral - integrals_fir_different_levels[level]) <= 0.00005 - -def test_check_computations_of_integrals_of_powers_of_landscape: - p = gudhi.PersistenceLandscapeOnGrid("data/file_with_diagram_1", 100, sys.maxsize) - integrals_fir_different_powers = [0.241168,0.239276,0.237882,0.235193,0.23011] - for power in range(0:5): - integral = p.compute_integral_of_landscape(power) - assert fabs(integral - integrals_fir_different_powers[power]) <= 0.00001 - -def test_check_computations_of_values_on_different_points: - p = gudhi.PersistenceLandscapeOnGrid("data/file_with_diagram_1", 100, sys.maxsize) - results_level_0 = [0.00997867,0.0521921,0.104312,0.156432,0.208552,0.260672,0.312792,0.364912,0.417032,0.429237] - results_level_10 = [7.21433e-05,0.0422135,0.0943335,0.146453,0.198573,0.240715,0.272877,0.324997,0.359232,0.379344] - double x = 0.0012321; - double dx = 0.05212; - for i in range(0,10): - assert almost_equal(p.compute_value_at_a_given_point(0, x), results_level_0[i])); - assert almost_equal(p.compute_value_at_a_given_point(10, x), results_level_10[i])); - x += dx; - -def test_check_computations_of_maxima_and_norms: - p = gudhi.PersistenceLandscapeOnGrid("data/file_with_diagram_1", 0., 1., 100) - second = gudhi.PersistenceLandscapeOnGrid("data/file_with_diagram_2", 0., 1., 100) - assert fabs(p.compute_maximum() - 0.46) <= 0.00001 - assert fabs(p.compute_norm_of_landscape(1) - 27.3373) <= 0.00001 - assert fabs(p.compute_norm_of_landscape(2) - 1.84143) <= 0.00001 - assert fabs(p.compute_norm_of_landscape(3) - 0.927067) <= 0.00001 - -def test_check_default_parameters_of_distances: - diag = read_persistence_intervals_in_dimension("data/file_with_diagram") - p = gudhi.PersistenceLandscapeOnGrid(diag, 0., 1., 100) - diag1 = read_persistence_intervals_in_dimension("data/file_with_diagram_1") - q = gudhi.PersistenceLandscapeOnGrid(diag1, 0., 1., 100) - dist_numeric_limit_max = p.distance(q, sys.maxsize); - dist_infinity = p.distance(q, sys.maxsize); - assert dist_numeric_limit_max == dist_infinity - -def test_check_computations_of_averages: - p = gudhi.PersistenceLandscapeOnGrid("data/file_with_diagram", 0., 1., 100) - q = gudhi.PersistenceLandscapeOnGrid("data/file_with_diagram_1", 0., 1., 100) - av = gudhi.PersistenceLandscapeOnGrid() - av.compute_average({&p, &q) - - template_average = gudhi.PersistenceLandscapeOnGrid() - template_average.load_landscape_from_file("data/average_on_a_grid") - assert template_average == av - - -def test_check_computations_of_distances: - p = gudhi.PersistenceLandscapeOnGrid("data/file_with_diagram", 0., 1., 10000) - q = gudhi.PersistenceLandscapeOnGrid("data/file_with_diagram_1", 0., 1., 10000) - assert fabs(p.distance(q) - 25.5779) <= 0.00005 - assert fabs(p.distance(q, 2) - 2.04891) <= 0.00001 - assert fabs(p.distance(q, sys.maxsize) - 0.359) <= 0.00001 - - -def test_check_computations_of_scalar_product: - p = gudhi.PersistenceLandscapeOnGrid("data/file_with_diagram", 0., 1., 10000) - q = gudhi.PersistenceLandscapeOnGrid("data/file_with_diagram_1", 0., 1., 10000) - assert almost_equal(p.compute_scalar_product(q), 0.754367) diff --git a/src/cython/test/test_reader_utils.py b/src/cython/test/test_reader_utils.py new file mode 100755 index 00000000..25591fb3 --- /dev/null +++ b/src/cython/test/test_reader_utils.py @@ -0,0 +1,88 @@ +import gudhi + +"""This file is part of the Gudhi Library. The Gudhi library + (Geometric Understanding in Higher Dimensions) is a generic C++ + library for computational topology. + + Author(s): Vincent Rouvreau + + Copyright (C) 2017 INRIA + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +""" + +__author__ = "Vincent Rouvreau" +__copyright__ = "Copyright (C) 2017 INRIA" +__license__ = "GPL v3" + + +def test_non_existing_csv_file(): + # Try to open a non existing file + matrix = gudhi.read_lower_triangular_matrix_from_csv_file(csv_file='pouetpouettralala.toubiloubabdou') + assert matrix == [] + +def test_full_square_distance_matrix_csv_file(): + # Create test file + test_file = open('full_square_distance_matrix.csv', 'w') + test_file.write('0;1;2;3;\n1;0;4;5;\n2;4;0;6;\n3;5;6;0;') + test_file.close() + matrix = gudhi.read_lower_triangular_matrix_from_csv_file(csv_file="full_square_distance_matrix.csv") + assert matrix == [[], [1.0], [2.0, 4.0], [3.0, 5.0, 6.0]] + +def test_lower_triangular_distance_matrix_csv_file(): + # Create test file + test_file = open('lower_triangular_distance_matrix.csv', 'w') + test_file.write('\n1,\n2,3,\n4,5,6,\n7,8,9,10,') + test_file.close() + matrix = gudhi.read_lower_triangular_matrix_from_csv_file(csv_file="lower_triangular_distance_matrix.csv", separator=",") + assert matrix == [[], [1.0], [2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0, 10.0]] + +def test_non_existing_persistence_file(): + # Try to open a non existing file + persistence = gudhi.read_persistence_intervals_grouped_by_dimension(persistence_file='pouetpouettralala.toubiloubabdou') + assert persistence == [] + persistence = gudhi.read_persistence_intervals_in_dimension(persistence_file='pouetpouettralala.toubiloubabdou', only_this_dim=1) + assert persistence == [] + +def test_read_persistence_intervals_without_dimension(): + # Create test file + test_file = open('persistence_intervals_without_dimension.pers', 'w') + test_file.write('# Simple persistence diagram without dimension\n2.7 3.7\n9.6 14.\n34.2 34.974\n3. inf') + test_file.close() + persistence = gudhi.read_persistence_intervals_in_dimension(persistence_file='persistence_intervals_without_dimension.pers') + assert persistence == [(2.7, 3.7), (9.6, 14.), (34.2, 34.974), (3., float('Inf'))] + persistence = gudhi.read_persistence_intervals_in_dimension(persistence_file='persistence_intervals_without_dimension.pers', only_this_dim=0) + assert persistence == [] + persistence = gudhi.read_persistence_intervals_in_dimension(persistence_file='persistence_intervals_without_dimension.pers', only_this_dim=1) + assert persistence == [] + persistence = gudhi.read_persistence_intervals_grouped_by_dimension(persistence_file='persistence_intervals_without_dimension.pers') + assert persistence == {-1: [(2.7, 3.7), (9.6, 14.0), (34.2, 34.974), (3.0, float('Inf'))]} + +def test_read_persistence_intervals_with_dimension(): + # Create test file + test_file = open('persistence_intervals_with_dimension.pers', 'w') + test_file.write('# Simple persistence diagram with dimension\n0 2.7 3.7\n1 9.6 14.\n3 34.2 34.974\n1 3. inf') + test_file.close() + persistence = gudhi.read_persistence_intervals_in_dimension(persistence_file='persistence_intervals_with_dimension.pers') + assert persistence == [(2.7, 3.7), (9.6, 14.), (34.2, 34.974), (3., float('Inf'))] + persistence = gudhi.read_persistence_intervals_in_dimension(persistence_file='persistence_intervals_with_dimension.pers', only_this_dim=0) + assert persistence == [(2.7, 3.7)] + persistence = gudhi.read_persistence_intervals_in_dimension(persistence_file='persistence_intervals_with_dimension.pers', only_this_dim=1) + assert persistence == [(9.6, 14.), (3., float('Inf'))] + persistence = gudhi.read_persistence_intervals_in_dimension(persistence_file='persistence_intervals_with_dimension.pers', only_this_dim=2) + assert persistence == [] + persistence = gudhi.read_persistence_intervals_in_dimension(persistence_file='persistence_intervals_with_dimension.pers', only_this_dim=3) + assert persistence == [(34.2, 34.974)] + persistence = gudhi.read_persistence_intervals_grouped_by_dimension(persistence_file='persistence_intervals_with_dimension.pers') + assert persistence == {0: [(2.7, 3.7)], 1: [(9.6, 14.0), (3.0, float('Inf'))], 3: [(34.2, 34.974)]} diff --git a/src/cython/test/test_simplex_tree.py b/src/cython/test/test_simplex_tree.py index 3ae537e3..6dec5d94 100755 --- a/src/cython/test/test_simplex_tree.py +++ b/src/cython/test/test_simplex_tree.py @@ -34,9 +34,13 @@ def test_insertion(): # insert test assert st.insert([0, 1]) == True + + assert st.dimension() == 1 + assert st.insert([0, 1, 2], filtration=4.0) == True - # FIXME: Remove this line - st.set_dimension(2) + + assert st.dimension() == 2 + assert st.num_simplices() == 7 assert st.num_vertices() == 3 @@ -53,7 +57,6 @@ def test_insertion(): assert st.find([2, 3]) == False # filtration test - st.set_filtration(5.0) st.initialize_filtration() assert st.filtration([0, 1, 2]) == 4.0 assert st.filtration([0, 2]) == 4.0 @@ -87,8 +90,9 @@ def test_insertion(): assert st.find([2]) == True st.initialize_filtration() - assert st.persistence() == [(1, (4.0, float('inf'))), (0, (0.0, float('inf')))] + assert st.persistence(persistence_dim_max = True) == [(1, (4.0, float('inf'))), (0, (0.0, float('inf')))] assert st.__is_persistence_defined() == True + assert st.betti_numbers() == [1, 1] assert st.persistent_betti_numbers(-0.1, 10000.0) == [0, 0] assert st.persistent_betti_numbers(0.0, 10000.0) == [1, 0] @@ -130,3 +134,30 @@ def test_expansion(): ([1, 2], 0.5), ([0, 1, 2], 0.5), ([1, 2, 3], 0.5), ([5], 0.6), ([6], 0.6), ([5, 6], 0.6), ([4], 0.7), ([2, 4], 0.7), ([0, 3], 0.8), ([0, 1, 3], 0.8), ([0, 2, 3], 0.8), ([0, 1, 2, 3], 0.8), ([4, 6], 0.9), ([3, 6], 1.0)] + +def test_automatic_dimension(): + st = SimplexTree() + assert st.__is_defined() == True + assert st.__is_persistence_defined() == False + + # insert test + assert st.insert([0,1,3], filtration=0.5) == True + assert st.insert([0,1,2], filtration=1.) == True + + assert st.num_vertices() == 4 + assert st.num_simplices() == 11 + + assert st.dimension() == 2 + assert st.upper_bound_dimension() == 2 + + assert st.prune_above_filtration(0.6) == True + assert st.dimension() == 2 + assert st.upper_bound_dimension() == 2 + + st.assign_filtration([0, 1, 3], 0.7) + assert st.filtration([0, 1, 3]) == 0.7 + + st.remove_maximal_simplex([0, 1, 3]) + assert st.upper_bound_dimension() == 2 + assert st.dimension() == 1 + assert st.upper_bound_dimension() == 1 |