summaryrefslogtreecommitdiff
path: root/src/python/test
diff options
context:
space:
mode:
authorROUVREAU Vincent <vincent.rouvreau@inria.fr>2020-01-28 11:05:39 +0100
committerROUVREAU Vincent <vincent.rouvreau@inria.fr>2020-01-28 11:05:39 +0100
commitef2c5b53e88321f07ad93496f00dde16dc20f018 (patch)
tree0a7c4d1d7f69a691259e98ceed1439421fb14f3e /src/python/test
parent0b77fdd5d9bd057103cb23020089a6628c1f14e6 (diff)
Code review: rename get_simplex_filtration with get_simplex_and_filtration. Remove exception raise. Fix failed tests. Reword documentation
Diffstat (limited to 'src/python/test')
-rwxr-xr-xsrc/python/test/test_alpha_complex.py50
-rwxr-xr-xsrc/python/test/test_euclidean_witness_complex.py46
-rwxr-xr-xsrc/python/test/test_rips_complex.py53
-rwxr-xr-xsrc/python/test/test_simplex_tree.py90
-rwxr-xr-xsrc/python/test/test_tangential_complex.py19
5 files changed, 141 insertions, 117 deletions
diff --git a/src/python/test/test_alpha_complex.py b/src/python/test/test_alpha_complex.py
index 3761fe16..ceead919 100755
--- a/src/python/test/test_alpha_complex.py
+++ b/src/python/test/test_alpha_complex.py
@@ -40,19 +40,21 @@ def test_infinite_alpha():
assert simplex_tree.num_simplices() == 11
assert simplex_tree.num_vertices() == 4
- assert simplex_tree.get_filtration() == [
- ([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),
- ]
+ filtration_generator = simplex_tree.get_filtration()
+ assert(next(filtration_generator) == ([0], 0.0))
+ assert(next(filtration_generator) == ([1], 0.0))
+ assert(next(filtration_generator) == ([2], 0.0))
+ assert(next(filtration_generator) == ([3], 0.0))
+ assert(next(filtration_generator) == ([0, 1], 0.25))
+ assert(next(filtration_generator) == ([0, 2], 0.25))
+ assert(next(filtration_generator) == ([1, 3], 0.25))
+ assert(next(filtration_generator) == ([2, 3], 0.25))
+ assert(next(filtration_generator) == ([1, 2], 0.5))
+ assert(next(filtration_generator) == ([0, 1, 2], 0.5))
+ assert(next(filtration_generator) == ([1, 2, 3], 0.5))
+ with pytest.raises(StopIteration):
+ next(filtration_generator)
+
assert simplex_tree.get_star([0]) == [
([0], 0.0),
([0, 1], 0.25),
@@ -105,16 +107,18 @@ def test_filtered_alpha():
else:
assert False
- assert simplex_tree.get_filtration() == [
- ([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),
- ]
+ filtration_generator = simplex_tree.get_filtration()
+ assert(next(filtration_generator) == ([0], 0.0))
+ assert(next(filtration_generator) == ([1], 0.0))
+ assert(next(filtration_generator) == ([2], 0.0))
+ assert(next(filtration_generator) == ([3], 0.0))
+ assert(next(filtration_generator) == ([0, 1], 0.25))
+ assert(next(filtration_generator) == ([0, 2], 0.25))
+ assert(next(filtration_generator) == ([1, 3], 0.25))
+ assert(next(filtration_generator) == ([2, 3], 0.25))
+ with pytest.raises(StopIteration):
+ next(filtration_generator)
+
assert simplex_tree.get_star([0]) == [([0], 0.0), ([0, 1], 0.25), ([0, 2], 0.25)]
assert simplex_tree.get_cofaces([0], 1) == [([0, 1], 0.25), ([0, 2], 0.25)]
diff --git a/src/python/test/test_euclidean_witness_complex.py b/src/python/test/test_euclidean_witness_complex.py
index c18d2484..16ff1ef4 100755
--- a/src/python/test/test_euclidean_witness_complex.py
+++ b/src/python/test/test_euclidean_witness_complex.py
@@ -9,6 +9,7 @@
"""
import gudhi
+import pytest
__author__ = "Vincent Rouvreau"
__copyright__ = "Copyright (C) 2016 Inria"
@@ -40,15 +41,16 @@ def test_witness_complex():
assert landmarks[1] == euclidean_witness_complex.get_point(1)
assert landmarks[2] == euclidean_witness_complex.get_point(2)
- assert simplex_tree.get_filtration() == [
- ([0], 0.0),
- ([1], 0.0),
- ([0, 1], 0.0),
- ([2], 0.0),
- ([0, 2], 0.0),
- ([1, 2], 0.0),
- ([0, 1, 2], 0.0),
- ]
+ filtration_generator = simplex_tree.get_filtration()
+ assert(next(filtration_generator) == ([0], 0.0))
+ assert(next(filtration_generator) == ([1], 0.0))
+ assert(next(filtration_generator) == ([0, 1], 0.0))
+ assert(next(filtration_generator) == ([2], 0.0))
+ assert(next(filtration_generator) == ([0, 2], 0.0))
+ assert(next(filtration_generator) == ([1, 2], 0.0))
+ assert(next(filtration_generator) == ([0, 1, 2], 0.0))
+ with pytest.raises(StopIteration):
+ next(filtration_generator)
def test_empty_euclidean_strong_witness_complex():
@@ -78,18 +80,24 @@ def test_strong_witness_complex():
assert landmarks[1] == euclidean_strong_witness_complex.get_point(1)
assert landmarks[2] == euclidean_strong_witness_complex.get_point(2)
- assert simplex_tree.get_filtration() == [([0], 0.0), ([1], 0.0), ([2], 0.0)]
+ filtration_generator = simplex_tree.get_filtration()
+ assert(next(filtration_generator) == ([0], 0.0))
+ assert(next(filtration_generator) == ([1], 0.0))
+ assert(next(filtration_generator) == ([2], 0.0))
+ with pytest.raises(StopIteration):
+ next(filtration_generator)
simplex_tree = euclidean_strong_witness_complex.create_simplex_tree(
max_alpha_square=100.0
)
- assert simplex_tree.get_filtration() == [
- ([0], 0.0),
- ([1], 0.0),
- ([2], 0.0),
- ([1, 2], 15.0),
- ([0, 2], 34.0),
- ([0, 1], 37.0),
- ([0, 1, 2], 37.0),
- ]
+ filtration_generator = simplex_tree.get_filtration()
+ assert(next(filtration_generator) == ([0], 0.0))
+ assert(next(filtration_generator) == ([1], 0.0))
+ assert(next(filtration_generator) == ([2], 0.0))
+ assert(next(filtration_generator) == ([1, 2], 15.0))
+ assert(next(filtration_generator) == ([0, 2], 34.0))
+ assert(next(filtration_generator) == ([0, 1], 37.0))
+ assert(next(filtration_generator) == ([0, 1, 2], 37.0))
+ with pytest.raises(StopIteration):
+ next(filtration_generator)
diff --git a/src/python/test/test_rips_complex.py b/src/python/test/test_rips_complex.py
index b02a68e1..bd31c47c 100755
--- a/src/python/test/test_rips_complex.py
+++ b/src/python/test/test_rips_complex.py
@@ -10,6 +10,7 @@
from gudhi import RipsComplex
from math import sqrt
+import pytest
__author__ = "Vincent Rouvreau"
__copyright__ = "Copyright (C) 2016 Inria"
@@ -32,18 +33,20 @@ def test_rips_from_points():
assert simplex_tree.num_simplices() == 10
assert simplex_tree.num_vertices() == 4
- assert simplex_tree.get_filtration() == [
- ([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),
- ]
+ filtration_generator = simplex_tree.get_filtration()
+ assert(next(filtration_generator) == ([0], 0.0))
+ assert(next(filtration_generator) == ([1], 0.0))
+ assert(next(filtration_generator) == ([2], 0.0))
+ assert(next(filtration_generator) == ([3], 0.0))
+ assert(next(filtration_generator) == ([0, 1], 1.0))
+ assert(next(filtration_generator) == ([0, 2], 1.0))
+ assert(next(filtration_generator) == ([1, 3], 1.0))
+ assert(next(filtration_generator) == ([2, 3], 1.0))
+ assert(next(filtration_generator) == ([1, 2], 1.4142135623730951))
+ assert(next(filtration_generator) == ([0, 3], 1.4142135623730951))
+ with pytest.raises(StopIteration):
+ next(filtration_generator)
+
assert simplex_tree.get_star([0]) == [
([0], 0.0),
([0, 1], 1.0),
@@ -95,18 +98,20 @@ def test_rips_from_distance_matrix():
assert simplex_tree.num_simplices() == 10
assert simplex_tree.num_vertices() == 4
- assert simplex_tree.get_filtration() == [
- ([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),
- ]
+ filtration_generator = simplex_tree.get_filtration()
+ assert(next(filtration_generator) == ([0], 0.0))
+ assert(next(filtration_generator) == ([1], 0.0))
+ assert(next(filtration_generator) == ([2], 0.0))
+ assert(next(filtration_generator) == ([3], 0.0))
+ assert(next(filtration_generator) == ([0, 1], 1.0))
+ assert(next(filtration_generator) == ([0, 2], 1.0))
+ assert(next(filtration_generator) == ([1, 3], 1.0))
+ assert(next(filtration_generator) == ([2, 3], 1.0))
+ assert(next(filtration_generator) == ([1, 2], 1.4142135623730951))
+ assert(next(filtration_generator) == ([0, 3], 1.4142135623730951))
+ with pytest.raises(StopIteration):
+ next(filtration_generator)
+
assert simplex_tree.get_star([0]) == [
([0], 0.0),
([0, 1], 1.0),
diff --git a/src/python/test/test_simplex_tree.py b/src/python/test/test_simplex_tree.py
index 1822c43b..0f3db7ac 100755
--- a/src/python/test/test_simplex_tree.py
+++ b/src/python/test/test_simplex_tree.py
@@ -9,6 +9,7 @@
"""
from gudhi import SimplexTree
+import pytest
__author__ = "Vincent Rouvreau"
__copyright__ = "Copyright (C) 2016 Inria"
@@ -126,55 +127,58 @@ def test_expansion():
assert st.num_vertices() == 7
assert st.num_simplices() == 17
- assert st.get_filtration() == [
- ([2], 0.1),
- ([3], 0.1),
- ([2, 3], 0.1),
- ([0], 0.2),
- ([0, 2], 0.2),
- ([1], 0.3),
- ([0, 1], 0.3),
- ([1, 3], 0.4),
- ([1, 2], 0.5),
- ([5], 0.6),
- ([6], 0.6),
- ([5, 6], 0.6),
- ([4], 0.7),
- ([2, 4], 0.7),
- ([0, 3], 0.8),
- ([4, 6], 0.9),
- ([3, 6], 1.0),
- ]
+
+ filtration_generator = st.get_filtration()
+ assert(next(filtration_generator) == ([2], 0.1))
+ assert(next(filtration_generator) == ([3], 0.1))
+ assert(next(filtration_generator) == ([2, 3], 0.1))
+ assert(next(filtration_generator) == ([0], 0.2))
+ assert(next(filtration_generator) == ([0, 2], 0.2))
+ assert(next(filtration_generator) == ([1], 0.3))
+ assert(next(filtration_generator) == ([0, 1], 0.3))
+ assert(next(filtration_generator) == ([1, 3], 0.4))
+ assert(next(filtration_generator) == ([1, 2], 0.5))
+ assert(next(filtration_generator) == ([5], 0.6))
+ assert(next(filtration_generator) == ([6], 0.6))
+ assert(next(filtration_generator) == ([5, 6], 0.6))
+ assert(next(filtration_generator) == ([4], 0.7))
+ assert(next(filtration_generator) == ([2, 4], 0.7))
+ assert(next(filtration_generator) == ([0, 3], 0.8))
+ assert(next(filtration_generator) == ([4, 6], 0.9))
+ assert(next(filtration_generator) == ([3, 6], 1.0))
+ with pytest.raises(StopIteration):
+ next(filtration_generator)
st.expansion(3)
assert st.num_vertices() == 7
assert st.num_simplices() == 22
st.initialize_filtration()
- assert st.get_filtration() == [
- ([2], 0.1),
- ([3], 0.1),
- ([2, 3], 0.1),
- ([0], 0.2),
- ([0, 2], 0.2),
- ([1], 0.3),
- ([0, 1], 0.3),
- ([1, 3], 0.4),
- ([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),
- ]
+ filtration_generator = st.get_filtration()
+ assert(next(filtration_generator) == ([2], 0.1))
+ assert(next(filtration_generator) == ([3], 0.1))
+ assert(next(filtration_generator) == ([2, 3], 0.1))
+ assert(next(filtration_generator) == ([0], 0.2))
+ assert(next(filtration_generator) == ([0, 2], 0.2))
+ assert(next(filtration_generator) == ([1], 0.3))
+ assert(next(filtration_generator) == ([0, 1], 0.3))
+ assert(next(filtration_generator) == ([1, 3], 0.4))
+ assert(next(filtration_generator) == ([1, 2], 0.5))
+ assert(next(filtration_generator) == ([0, 1, 2], 0.5))
+ assert(next(filtration_generator) == ([1, 2, 3], 0.5))
+ assert(next(filtration_generator) == ([5], 0.6))
+ assert(next(filtration_generator) == ([6], 0.6))
+ assert(next(filtration_generator) == ([5, 6], 0.6))
+ assert(next(filtration_generator) == ([4], 0.7))
+ assert(next(filtration_generator) == ([2, 4], 0.7))
+ assert(next(filtration_generator) == ([0, 3], 0.8))
+ assert(next(filtration_generator) == ([0, 1, 3], 0.8))
+ assert(next(filtration_generator) == ([0, 2, 3], 0.8))
+ assert(next(filtration_generator) == ([0, 1, 2, 3], 0.8))
+ assert(next(filtration_generator) == ([4, 6], 0.9))
+ assert(next(filtration_generator) == ([3, 6], 1.0))
+ with pytest.raises(StopIteration):
+ next(filtration_generator)
def test_automatic_dimension():
diff --git a/src/python/test/test_tangential_complex.py b/src/python/test/test_tangential_complex.py
index e650e99c..90e2c75b 100755
--- a/src/python/test/test_tangential_complex.py
+++ b/src/python/test/test_tangential_complex.py
@@ -9,6 +9,7 @@
"""
from gudhi import TangentialComplex, SimplexTree
+import pytest
__author__ = "Vincent Rouvreau"
__copyright__ = "Copyright (C) 2016 Inria"
@@ -37,14 +38,16 @@ def test_tangential():
assert st.num_simplices() == 6
assert st.num_vertices() == 4
- assert st.get_filtration() == [
- ([0], 0.0),
- ([1], 0.0),
- ([2], 0.0),
- ([0, 2], 0.0),
- ([3], 0.0),
- ([1, 3], 0.0),
- ]
+ filtration_generator = st.get_filtration()
+ assert(next(filtration_generator) == ([0], 0.0))
+ assert(next(filtration_generator) == ([1], 0.0))
+ assert(next(filtration_generator) == ([2], 0.0))
+ assert(next(filtration_generator) == ([0, 2], 0.0))
+ assert(next(filtration_generator) == ([3], 0.0))
+ assert(next(filtration_generator) == ([1, 3], 0.0))
+ with pytest.raises(StopIteration):
+ next(filtration_generator)
+
assert st.get_cofaces([0], 1) == [([0, 2], 0.0)]
assert point_list[0] == tc.get_point(0)