diff options
Diffstat (limited to 'src/cython')
-rw-r--r-- | src/cython/Makefile | 10 | ||||
-rw-r--r-- | src/cython/src/cython/alpha_complex.pyx | 17 | ||||
-rw-r--r-- | src/cython/src/cython/cubical_complex.pyx | 4 | ||||
-rw-r--r-- | src/cython/src/cython/mini_simplex_tree.pyx | 10 | ||||
-rw-r--r-- | src/cython/src/cython/rips_complex.pyx | 12 | ||||
-rw-r--r-- | src/cython/src/cython/simplex_tree.pyx | 10 | ||||
-rw-r--r-- | src/cython/src/cython/witness_complex.pyx | 9 | ||||
-rwxr-xr-x | src/cython/test/test_alpha_complex.py | 114 | ||||
-rwxr-xr-x | src/cython/test/test_mini_simplex_tree.py | 49 | ||||
-rwxr-xr-x | src/cython/test/test_rips_complex.py | 70 | ||||
-rwxr-xr-x | src/cython/test/test_simplex_tree.py | 133 | ||||
-rwxr-xr-x | src/cython/test/test_witness_complex.py | 48 |
12 files changed, 267 insertions, 219 deletions
diff --git a/src/cython/Makefile b/src/cython/Makefile index fdf4956c..406f59ae 100644 --- a/src/cython/Makefile +++ b/src/cython/Makefile @@ -2,11 +2,11 @@ ext: python setup.py build_ext --inplace test: - python test/test_simplex_tree.py - python test/test_mini_simplex_tree.py - python test/test_rips_complex.py - python test/test_alpha_complex.py - python test/test_witness_complex.py + python -m pytest test/test_simplex_tree.py + python -m pytest test/test_mini_simplex_tree.py + python -m pytest test/test_rips_complex.py + python -m pytest test/test_alpha_complex.py + python -m pytest test/test_witness_complex.py python -m pytest test/test_cubical_complex.py example: diff --git a/src/cython/src/cython/alpha_complex.pyx b/src/cython/src/cython/alpha_complex.pyx index 6f8f5eca..39e930f4 100644 --- a/src/cython/src/cython/alpha_complex.pyx +++ b/src/cython/src/cython/alpha_complex.pyx @@ -81,16 +81,15 @@ cdef class AlphaComplex: cdef Alpha_complex_persistence_interface * pcohptr - def __cinit__(self, points=None, max_alpha_square=float('inf')): + def __cinit__(self, points=[], max_alpha_square=float('inf')): """AlphaComplex constructor. Args: points (list): A list of points in d-Dimension. max_alpha_square (float): Maximum Alpha square value. """ - if points is not None: - self.thisptr = new Alpha_complex_interface(points, - max_alpha_square) + self.thisptr = new Alpha_complex_interface(points, + max_alpha_square) def __dealloc__(self): if self.thisptr != NULL: @@ -98,6 +97,16 @@ cdef class AlphaComplex: if self.pcohptr != NULL: del self.pcohptr + def __is_defined(self): + """Returns true if AlphaComplex pointer is not NULL. + """ + return self.thisptr != NULL + + def __is_persistence_defined(self): + """Returns true if Persistence pointer is not NULL. + """ + return self.pcohptr != NULL + def get_filtration(self): """This function returns the main simplicial complex filtration value. diff --git a/src/cython/src/cython/cubical_complex.pyx b/src/cython/src/cython/cubical_complex.pyx index 375d2e0c..4192b195 100644 --- a/src/cython/src/cython/cubical_complex.pyx +++ b/src/cython/src/cython/cubical_complex.pyx @@ -85,9 +85,13 @@ cdef class CubicalComplex: del self.pcohptr def __is_defined(self): + """Returns true if CubicalComplex pointer is not NULL. + """ return self.thisptr != NULL def __is_persistence_defined(self): + """Returns true if Persistence pointer is not NULL. + """ return self.pcohptr != NULL def persistence(self, homology_coeff_field=11, min_persistence=0): diff --git a/src/cython/src/cython/mini_simplex_tree.pyx b/src/cython/src/cython/mini_simplex_tree.pyx index c6725226..813316af 100644 --- a/src/cython/src/cython/mini_simplex_tree.pyx +++ b/src/cython/src/cython/mini_simplex_tree.pyx @@ -83,6 +83,16 @@ cdef class MiniSimplexTree: if self.pcohptr != NULL: del self.pcohptr + def __is_defined(self): + """Returns true if MiniSimplexTree pointer is not NULL. + """ + return self.thisptr != NULL + + def __is_persistence_defined(self): + """Returns true if Persistence pointer is not NULL. + """ + return self.pcohptr != NULL + def get_filtration(self): """This function returns the main simplicial complex filtration value. diff --git a/src/cython/src/cython/rips_complex.pyx b/src/cython/src/cython/rips_complex.pyx index 13e82230..4d713304 100644 --- a/src/cython/src/cython/rips_complex.pyx +++ b/src/cython/src/cython/rips_complex.pyx @@ -78,7 +78,7 @@ cdef class RipsComplex: cdef Rips_complex_persistence_interface * pcohptr - def __cinit__(self, points=None, max_dimension=3, + def __cinit__(self, points=[], max_dimension=3, max_edge_length=float('inf')): """RipsComplex constructor. @@ -99,6 +99,16 @@ cdef class RipsComplex: if self.pcohptr != NULL: del self.pcohptr + def __is_defined(self): + """Returns true if RipsComplex pointer is not NULL. + """ + return self.thisptr != NULL + + def __is_persistence_defined(self): + """Returns true if Persistence pointer is not NULL. + """ + return self.pcohptr != NULL + def get_filtration(self): """This function returns the main simplicial complex filtration value. diff --git a/src/cython/src/cython/simplex_tree.pyx b/src/cython/src/cython/simplex_tree.pyx index c5cb7595..c0c783b4 100644 --- a/src/cython/src/cython/simplex_tree.pyx +++ b/src/cython/src/cython/simplex_tree.pyx @@ -83,6 +83,16 @@ cdef class SimplexTree: if self.pcohptr != NULL: del self.pcohptr + def __is_defined(self): + """Returns true if SimplexTree pointer is not NULL. + """ + return self.thisptr != NULL + + def __is_persistence_defined(self): + """Returns true if Persistence pointer is not NULL. + """ + return self.pcohptr != NULL + def get_filtration(self): """This function returns the main simplicial complex filtration value. diff --git a/src/cython/src/cython/witness_complex.pyx b/src/cython/src/cython/witness_complex.pyx index b9f354d5..0f08bdcb 100644 --- a/src/cython/src/cython/witness_complex.pyx +++ b/src/cython/src/cython/witness_complex.pyx @@ -61,8 +61,6 @@ cdef class WitnessComplex: cdef Witness_complex_interface * thisptr - #cdef Witness_complex_persistence_interface * pcohptr - def __cinit__(self, points=None, number_of_landmarks=5): """WitnessComplex constructor. @@ -78,8 +76,11 @@ cdef class WitnessComplex: def __dealloc__(self): if self.thisptr != NULL: del self.thisptr - #if self.pcohptr != NULL: - # del self.pcohptr + + def __is_defined(self): + """Returns true if AlphaComplex pointer is not NULL. + """ + return self.thisptr != NULL def get_filtration(self): """This function returns the main simplicial complex filtration value. diff --git a/src/cython/test/test_alpha_complex.py b/src/cython/test/test_alpha_complex.py index a1e57294..13c6f7e8 100755 --- a/src/cython/test/test_alpha_complex.py +++ b/src/cython/test/test_alpha_complex.py @@ -1,6 +1,4 @@ -import unittest - -import gudhi +from gudhi import AlphaComplex """This file is part of the Gudhi Library. The Gudhi library (Geometric Understanding in Higher Dimensions) is a generic C++ @@ -29,56 +27,60 @@ __copyright__ = "Copyright (C) 2016 INRIA" __license__ = "GPL v3" -class TestAlphaComplex(unittest.TestCase): - - def test_infinite_alpha(self): - point_list = [[0, 0], [1, 0], [0, 1], [1, 1]] - alpha_complex = gudhi.AlphaComplex(points=point_list) - - self.assertEqual(alpha_complex.num_simplices(), 11) - self.assertEqual(alpha_complex.num_vertices(), 4) - - self.assertEqual(alpha_complex.get_filtered_tree(), - [([0], 0.0), ([1], 0.0), ([2], 0.0), ([3], 0.0), - ([0, 1], 0.25), ([0, 2], 0.25), ([1, 3], 0.25), - ([2, 3], 0.25), ([1, 2], 0.5), ([0, 1, 2], 0.5), - ([1, 2, 3], 0.5)]) - self.assertEqual(alpha_complex.get_star_tree([0]), - [([0], 0.0), ([0, 1], 0.25), ([0, 1, 2], 0.5), - ([0, 2], 0.25)]) - self.assertEqual(alpha_complex.get_coface_tree([0], 1), - [([0, 1], 0.25), ([0, 2], 0.25)]) - - self.assertEqual(point_list[0], alpha_complex.get_point(0)) - self.assertEqual(point_list[1], alpha_complex.get_point(1)) - self.assertEqual(point_list[2], alpha_complex.get_point(2)) - self.assertEqual(point_list[3], alpha_complex.get_point(3)) - self.assertEqual([], alpha_complex.get_point(4)) - self.assertEqual([], alpha_complex.get_point(125)) - - def test_filtered_alpha(self): - point_list = [[0, 0], [1, 0], [0, 1], [1, 1]] - filtered_alpha = gudhi.AlphaComplex(points=point_list, - max_alpha_square=0.25) - - self.assertEqual(filtered_alpha.num_simplices(), 8) - self.assertEqual(filtered_alpha.num_vertices(), 4) - - self.assertEqual(point_list[0], filtered_alpha.get_point(0)) - self.assertEqual(point_list[1], filtered_alpha.get_point(1)) - self.assertEqual(point_list[2], filtered_alpha.get_point(2)) - self.assertEqual(point_list[3], filtered_alpha.get_point(3)) - self.assertEqual([], filtered_alpha.get_point(4)) - self.assertEqual([], filtered_alpha.get_point(125)) - - self.assertEqual(filtered_alpha.get_filtered_tree(), - [([0], 0.0), ([1], 0.0), ([2], 0.0), ([3], 0.0), - ([0, 1], 0.25), ([0, 2], 0.25), ([1, 3], 0.25), - ([2, 3], 0.25)]) - self.assertEqual(filtered_alpha.get_star_tree([0]), - [([0], 0.0), ([0, 1], 0.25), ([0, 2], 0.25)]) - self.assertEqual(filtered_alpha.get_coface_tree([0], 1), - [([0, 1], 0.25), ([0, 2], 0.25)]) - -if __name__ == '__main__': - unittest.main() +def test_empty_alpha(): + alpha_complex = AlphaComplex() + assert alpha_complex.__is_defined() == True + assert alpha_complex.__is_persistence_defined() == False + assert alpha_complex.num_simplices() == 0 + assert alpha_complex.num_vertices() == 0 + +def test_infinite_alpha(): + point_list = [[0, 0], [1, 0], [0, 1], [1, 1]] + alpha_complex = AlphaComplex(points=point_list) + assert alpha_complex.__is_defined() == True + assert alpha_complex.__is_persistence_defined() == False + + assert alpha_complex.num_simplices() == 11 + assert alpha_complex.num_vertices() == 4 + + assert alpha_complex.get_filtered_tree() == \ + [([0], 0.0), ([1], 0.0), ([2], 0.0), ([3], 0.0), + ([0, 1], 0.25), ([0, 2], 0.25), ([1, 3], 0.25), + ([2, 3], 0.25), ([1, 2], 0.5), ([0, 1, 2], 0.5), + ([1, 2, 3], 0.5)] + assert alpha_complex.get_star_tree([0]) == \ + [([0], 0.0), ([0, 1], 0.25), ([0, 1, 2], 0.5), + ([0, 2], 0.25)] + assert alpha_complex.get_coface_tree([0], 1) == \ + [([0, 1], 0.25), ([0, 2], 0.25)] + + assert point_list[0] == alpha_complex.get_point(0) + assert point_list[1] == alpha_complex.get_point(1) + assert point_list[2] == alpha_complex.get_point(2) + assert point_list[3] == alpha_complex.get_point(3) + assert alpha_complex.get_point(4) == [] + assert alpha_complex.get_point(125) == [] + +def test_filtered_alpha(): + point_list = [[0, 0], [1, 0], [0, 1], [1, 1]] + filtered_alpha = AlphaComplex(points=point_list, + max_alpha_square=0.25) + + assert filtered_alpha.num_simplices() == 8 + assert filtered_alpha.num_vertices() == 4 + + assert point_list[0] == filtered_alpha.get_point(0) + assert point_list[1] == filtered_alpha.get_point(1) + assert point_list[2] == filtered_alpha.get_point(2) + assert point_list[3] == filtered_alpha.get_point(3) + assert filtered_alpha.get_point(4) == [] + assert filtered_alpha.get_point(125) == [] + + assert filtered_alpha.get_filtered_tree() == \ + [([0], 0.0), ([1], 0.0), ([2], 0.0), ([3], 0.0), + ([0, 1], 0.25), ([0, 2], 0.25), ([1, 3], 0.25), + ([2, 3], 0.25)] + assert filtered_alpha.get_star_tree([0]) == \ + [([0], 0.0), ([0, 1], 0.25), ([0, 2], 0.25)] + assert filtered_alpha.get_coface_tree([0], 1) == \ + [([0, 1], 0.25), ([0, 2], 0.25)] diff --git a/src/cython/test/test_mini_simplex_tree.py b/src/cython/test/test_mini_simplex_tree.py index ec1f5044..e44bfdbc 100755 --- a/src/cython/test/test_mini_simplex_tree.py +++ b/src/cython/test/test_mini_simplex_tree.py @@ -1,6 +1,4 @@ -import unittest - -import gudhi +from gudhi import MiniSimplexTree """This file is part of the Gudhi Library. The Gudhi library (Geometric Understanding in Higher Dimensions) is a generic C++ @@ -29,27 +27,24 @@ __copyright__ = "Copyright (C) 2016 INRIA" __license__ = "GPL v3" -class TestMiniSimplexTree(unittest.TestCase): - - def test_mini(self): - triangle012 = [0, 1, 2] - edge03 = [0, 3] - mini_st = gudhi.MiniSimplexTree() - self.assertTrue(mini_st.insert(triangle012)) - self.assertTrue(mini_st.insert(edge03)) - # FIXME: Remove this line - mini_st.set_dimension(2) - - edge02 = [0, 2] - self.assertTrue(mini_st.find(edge02)) - self.assertEqual(mini_st.get_coface_tree(edge02, 1), - [([0, 1, 2], 0.0)]) - - # remove_maximal_simplex test - self.assertEqual(mini_st.get_coface_tree(triangle012, 1), []) - mini_st.remove_maximal_simplex(triangle012) - self.assertTrue(mini_st.find(edge02)) - self.assertFalse(mini_st.find(triangle012)) - -if __name__ == '__main__': - unittest.main() +def test_mini(): + triangle012 = [0, 1, 2] + edge03 = [0, 3] + mini_st = MiniSimplexTree() + assert mini_st.__is_defined() == True + assert mini_st.__is_persistence_defined() == False + assert mini_st.insert(triangle012) == True + assert mini_st.insert(edge03) == True + # FIXME: Remove this line + mini_st.set_dimension(2) + + edge02 = [0, 2] + assert mini_st.find(edge02) == True + assert mini_st.get_coface_tree(edge02, 1) == \ + [([0, 1, 2], 0.0)] + + # remove_maximal_simplex test + assert mini_st.get_coface_tree(triangle012, 1) == [] + mini_st.remove_maximal_simplex(triangle012) + assert mini_st.find(edge02) == True + assert mini_st.find(triangle012) == False diff --git a/src/cython/test/test_rips_complex.py b/src/cython/test/test_rips_complex.py index ecc676c7..877289cf 100755 --- a/src/cython/test/test_rips_complex.py +++ b/src/cython/test/test_rips_complex.py @@ -1,6 +1,4 @@ -import unittest - -import gudhi +from gudhi import RipsComplex """This file is part of the Gudhi Library. The Gudhi library (Geometric Understanding in Higher Dimensions) is a generic C++ @@ -29,33 +27,39 @@ __copyright__ = "Copyright (C) 2016 INRIA" __license__ = "GPL v3" -class TestRipsComplex(unittest.TestCase): - - def test_rips(self): - point_list = [[0, 0], [1, 0], [0, 1], [1, 1]] - rips_complex = gudhi.RipsComplex(points=point_list, max_dimension=1, - max_edge_length=42) - - self.assertEqual(rips_complex.num_simplices(), 10) - self.assertEqual(rips_complex.num_vertices(), 4) - - self.assertEqual(rips_complex.get_filtered_tree(), - [([0], 0.0), ([1], 0.0), ([2], 0.0), ([3], 0.0), - ([0, 1], 1.0), ([0, 2], 1.0), ([1, 3], 1.0), - ([2, 3], 1.0), ([1, 2], 1.4142135623730951), - ([0, 3], 1.4142135623730951)]) - self.assertEqual(rips_complex.get_star_tree([0]), - [([0], 0.0), ([0, 1], 1.0), ([0, 2], 1.0), - ([0, 3], 1.4142135623730951)]) - self.assertEqual(rips_complex.get_coface_tree([0], 1), - [([0, 1], 1.0), ([0, 2], 1.0), - ([0, 3], 1.4142135623730951)]) - - filtered_rips = gudhi.RipsComplex(points=point_list, max_dimension=1, - max_edge_length=1.0) - - self.assertEqual(filtered_rips.num_simplices(), 8) - self.assertEqual(filtered_rips.num_vertices(), 4) - -if __name__ == '__main__': - unittest.main() +def test_empty_rips(): + rips_complex = RipsComplex() + assert rips_complex.__is_defined() == True + assert rips_complex.__is_persistence_defined() == False + +def test_rips(): + point_list = [[0, 0], [1, 0], [0, 1], [1, 1]] + rips_complex = RipsComplex(points=point_list, max_dimension=1, + max_edge_length=42) + assert rips_complex.__is_defined() == True + assert rips_complex.__is_persistence_defined() == False + + assert rips_complex.num_simplices() == 10 + assert rips_complex.num_vertices() == 4 + + assert rips_complex.get_filtered_tree() == \ + [([0], 0.0), ([1], 0.0), ([2], 0.0), ([3], 0.0), + ([0, 1], 1.0), ([0, 2], 1.0), ([1, 3], 1.0), + ([2, 3], 1.0), ([1, 2], 1.4142135623730951), + ([0, 3], 1.4142135623730951)] + assert rips_complex.get_star_tree([0]) == \ + [([0], 0.0), ([0, 1], 1.0), ([0, 2], 1.0), + ([0, 3], 1.4142135623730951)] + assert rips_complex.get_coface_tree([0], 1) == \ + [([0, 1], 1.0), ([0, 2], 1.0), + ([0, 3], 1.4142135623730951)] + +def test_filtered_rips(): + point_list = [[0, 0], [1, 0], [0, 1], [1, 1]] + filtered_rips = RipsComplex(points=point_list, max_dimension=1, + max_edge_length=1.0) + assert filtered_rips.__is_defined() == True + assert filtered_rips.__is_persistence_defined() == False + + assert filtered_rips.num_simplices() == 8 + assert filtered_rips.num_vertices() == 4 diff --git a/src/cython/test/test_simplex_tree.py b/src/cython/test/test_simplex_tree.py index 7663ed70..0b9899f8 100755 --- a/src/cython/test/test_simplex_tree.py +++ b/src/cython/test/test_simplex_tree.py @@ -1,6 +1,4 @@ -import unittest - -import gudhi +from gudhi import SimplexTree """This file is part of the Gudhi Library. The Gudhi library (Geometric Understanding in Higher Dimensions) is a generic C++ @@ -29,63 +27,72 @@ __copyright__ = "Copyright (C) 2016 INRIA" __license__ = "GPL v3" -class TestSimplexTree(unittest.TestCase): - - def test_insertion(self): - st = gudhi.SimplexTree() - - # insert test - self.assertTrue(st.insert([0, 1])) - self.assertTrue(st.insert([0, 1, 2], filtration=4.0)) - self.assertEqual(st.num_simplices(), 7) - self.assertEqual(st.num_vertices(), 3) - - # find test - self.assertTrue(st.find([0, 1, 2])) - self.assertTrue(st.find([0, 1])) - self.assertTrue(st.find([0, 2])) - self.assertTrue(st.find([0])) - self.assertTrue(st.find([1])) - self.assertTrue(st.find([2])) - self.assertFalse(st.find([3])) - self.assertFalse(st.find([0, 3])) - self.assertFalse(st.find([1, 3])) - self.assertFalse(st.find([2, 3])) - - # filtration test - st.set_filtration(5.0) - st.initialize_filtration() - self.assertEqual(st.get_filtration(), 5.0) - self.assertEqual(st.filtration([0, 1, 2]), 4.0) - self.assertEqual(st.filtration([0, 2]), 4.0) - self.assertEqual(st.filtration([1, 2]), 4.0) - self.assertEqual(st.filtration([2]), 4.0) - self.assertEqual(st.filtration([0, 1]), 0.0) - self.assertEqual(st.filtration([0]), 0.0) - self.assertEqual(st.filtration([1]), 0.0) - - # skeleton_tree test - self.assertEqual(st.get_skeleton_tree(2), - [([0, 1, 2], 4.0), ([0, 1], 0.0), ([0, 2], 4.0), - ([0], 0.0), ([1, 2], 4.0), ([1], 0.0), ([2], 4.0)]) - self.assertEqual(st.get_skeleton_tree(1), - [([0, 1], 0.0), ([0, 2], 4.0), ([0], 0.0), - ([1, 2], 4.0), ([1], 0.0), ([2], 4.0)]) - self.assertEqual(st.get_skeleton_tree(0), - [([0], 0.0), ([1], 0.0), ([2], 4.0)]) - - # remove_maximal_simplex test - self.assertEqual(st.get_coface_tree([0, 1, 2], 1), []) - st.remove_maximal_simplex([0, 1, 2]) - self.assertEqual(st.get_skeleton_tree(2), - [([0, 1], 0.0), ([0, 2], 4.0), ([0], 0.0), - ([1, 2], 4.0), ([1], 0.0), ([2], 4.0)]) - self.assertFalse(st.find([0, 1, 2])) - self.assertTrue(st.find([0, 1])) - self.assertTrue(st.find([0, 2])) - self.assertTrue(st.find([0])) - self.assertTrue(st.find([1])) - self.assertTrue(st.find([2])) - -if __name__ == '__main__': - unittest.main() +def test_insertion(): + st = SimplexTree() + assert st.__is_defined() == True + assert st.__is_persistence_defined() == False + + # insert test + assert st.insert([0, 1]) == True + assert st.insert([0, 1, 2], filtration=4.0) == True + # FIXME: Remove this line + st.set_dimension(2) + assert st.num_simplices() == 7 + assert st.num_vertices() == 3 + + # find test + assert st.find([0, 1, 2]) == True + assert st.find([0, 1]) == True + assert st.find([0, 2]) == True + assert st.find([0]) == True + assert st.find([1]) == True + assert st.find([2]) == True + assert st.find([3]) == False + assert st.find([0, 3]) == False + assert st.find([1, 3]) == False + assert st.find([2, 3]) == False + + # filtration test + st.set_filtration(5.0) + st.initialize_filtration() + assert st.get_filtration() == 5.0 + assert st.filtration([0, 1, 2]) == 4.0 + assert st.filtration([0, 2]) == 4.0 + assert st.filtration([1, 2]) == 4.0 + assert st.filtration([2]) == 4.0 + assert st.filtration([0, 1]) == 0.0 + assert st.filtration([0]) == 0.0 + assert st.filtration([1]) == 0.0 + + # skeleton_tree test + assert st.get_skeleton_tree(2) == \ + [([0, 1, 2], 4.0), ([0, 1], 0.0), ([0, 2], 4.0), + ([0], 0.0), ([1, 2], 4.0), ([1], 0.0), ([2], 4.0)] + assert st.get_skeleton_tree(1) == \ + [([0, 1], 0.0), ([0, 2], 4.0), ([0], 0.0), + ([1, 2], 4.0), ([1], 0.0), ([2], 4.0)] + assert st.get_skeleton_tree(0) == \ + [([0], 0.0), ([1], 0.0), ([2], 4.0)] + + # remove_maximal_simplex test + assert st.get_coface_tree([0, 1, 2], 1) == [] + st.remove_maximal_simplex([0, 1, 2]) + assert st.get_skeleton_tree(2) == \ + [([0, 1], 0.0), ([0, 2], 4.0), ([0], 0.0), + ([1, 2], 4.0), ([1], 0.0), ([2], 4.0)] + assert st.find([0, 1, 2]) == False + assert st.find([0, 1]) == True + assert st.find([0, 2]) == True + assert st.find([0]) == True + assert st.find([1]) == True + assert st.find([2]) == True + + st.initialize_filtration() + assert st.persistence() == [(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] + assert st.persistent_betti_numbers(3.9, 10000.0) == [1, 0] + assert st.persistent_betti_numbers(4.0, 10000.0) == [1, 1] + assert st.persistent_betti_numbers(9999.0, 10000.0) == [1, 1] diff --git a/src/cython/test/test_witness_complex.py b/src/cython/test/test_witness_complex.py index 2891935d..9f4a3523 100755 --- a/src/cython/test/test_witness_complex.py +++ b/src/cython/test/test_witness_complex.py @@ -1,6 +1,4 @@ -import unittest - -import gudhi +from gudhi import WitnessComplex """This file is part of the Gudhi Library. The Gudhi library (Geometric Understanding in Higher Dimensions) is a generic C++ @@ -29,31 +27,29 @@ __copyright__ = "Copyright (C) 2016 INRIA" __license__ = "GPL v3" -class TestWitnessComplex(unittest.TestCase): - - def test_witness_complex(self): - point_list = [[0, 0], [1, 0], [0, 1], [1, 1]] - witness = gudhi.WitnessComplex(points=point_list, - number_of_landmarks=10) - - # FIXME: Remove this line - witness.set_dimension(2) +def test_empty_witness_complex(): + witness = WitnessComplex() + assert witness.__is_defined() == False - self.assertEqual(witness.num_simplices(), 13) - self.assertEqual(witness.num_vertices(), 10) - witness.initialize_filtration() +def test_witness_complex(): + point_list = [[0, 0], [1, 0], [0, 1], [1, 1]] + witness = WitnessComplex(points=point_list, number_of_landmarks=10) + assert witness.__is_defined() == True - self.assertEqual(witness.get_filtered_tree(), - [([0], 0.0), ([1], 0.0), ([2], 0.0), ([0, 2], 0.0), - ([1, 2], 0.0), ([3], 0.0), ([4], 0.0), ([3, 4], 0.0), - ([5], 0.0), ([6], 0.0), ([7], 0.0), ([8], 0.0), - ([9], 0.0)]) + # FIXME: Remove this line + witness.set_dimension(2) - self.assertEqual(witness.get_coface_tree([2], 1), - [([0, 2], 0.0), ([1, 2], 0.0)]) - self.assertEqual(witness.get_star_tree([2]), - [([0, 2], 0.0), ([1, 2], 0.0), ([2], 0.0)]) + assert witness.num_simplices() == 13 + assert witness.num_vertices() == 10 + witness.initialize_filtration() + assert witness.get_filtered_tree() == \ + [([0], 0.0), ([1], 0.0), ([2], 0.0), ([0, 2], 0.0), + ([1, 2], 0.0), ([3], 0.0), ([4], 0.0), ([3, 4], 0.0), + ([5], 0.0), ([6], 0.0), ([7], 0.0), ([8], 0.0), + ([9], 0.0)] -if __name__ == '__main__': - unittest.main() + assert witness.get_coface_tree([2], 1) == \ + [([0, 2], 0.0), ([1, 2], 0.0)] + assert witness.get_star_tree([2]) == \ + [([0, 2], 0.0), ([1, 2], 0.0), ([2], 0.0)] |