summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorROUVREAU Vincent <vincent.rouvreau@inria.fr>2020-02-11 17:20:24 +0100
committerROUVREAU Vincent <vincent.rouvreau@inria.fr>2020-02-11 17:20:24 +0100
commit3ea44646f04648d1a456a0fb9526035101fc17ea (patch)
treeae517187fd90c6f878538748b4b1f550bf1e5790
parent3253abd27129595f7fcd2be4c2285a93aea98690 (diff)
Code review: non-optimal way to test filtration generator
-rwxr-xr-xsrc/python/test/test_alpha_complex.py49
-rwxr-xr-xsrc/python/test/test_euclidean_witness_complex.py45
-rwxr-xr-xsrc/python/test/test_rips_complex.py50
-rwxr-xr-xsrc/python/test/test_simplex_tree.py88
-rwxr-xr-xsrc/python/test/test_tangential_complex.py17
5 files changed, 117 insertions, 132 deletions
diff --git a/src/python/test/test_alpha_complex.py b/src/python/test/test_alpha_complex.py
index ceead919..77121302 100755
--- a/src/python/test/test_alpha_complex.py
+++ b/src/python/test/test_alpha_complex.py
@@ -40,20 +40,19 @@ def test_infinite_alpha():
assert simplex_tree.num_simplices() == 11
assert simplex_tree.num_vertices() == 4
- 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 list(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),
+ ]
assert simplex_tree.get_star([0]) == [
([0], 0.0),
@@ -107,18 +106,16 @@ def test_filtered_alpha():
else:
assert False
- 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 list(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),
+ ]
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 16ff1ef4..47196a2a 100755
--- a/src/python/test/test_euclidean_witness_complex.py
+++ b/src/python/test/test_euclidean_witness_complex.py
@@ -41,16 +41,15 @@ def test_witness_complex():
assert landmarks[1] == euclidean_witness_complex.get_point(1)
assert landmarks[2] == euclidean_witness_complex.get_point(2)
- 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)
+ assert list(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),
+ ]
def test_empty_euclidean_strong_witness_complex():
@@ -80,24 +79,18 @@ 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)
- 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)
+ assert list(simplex_tree.get_filtration()) == [([0], 0.0), ([1], 0.0), ([2], 0.0)]
simplex_tree = euclidean_strong_witness_complex.create_simplex_tree(
max_alpha_square=100.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)
+ assert list(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),
+ ]
diff --git a/src/python/test/test_rips_complex.py b/src/python/test/test_rips_complex.py
index bd31c47c..f5c086cb 100755
--- a/src/python/test/test_rips_complex.py
+++ b/src/python/test/test_rips_complex.py
@@ -33,19 +33,18 @@ def test_rips_from_points():
assert simplex_tree.num_simplices() == 10
assert simplex_tree.num_vertices() == 4
- 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 list(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),
+ ]
assert simplex_tree.get_star([0]) == [
([0], 0.0),
@@ -98,19 +97,18 @@ def test_rips_from_distance_matrix():
assert simplex_tree.num_simplices() == 10
assert simplex_tree.num_vertices() == 4
- 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 list(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),
+ ]
assert simplex_tree.get_star([0]) == [
([0], 0.0),
diff --git a/src/python/test/test_simplex_tree.py b/src/python/test/test_simplex_tree.py
index 0f3db7ac..fa42f2ac 100755
--- a/src/python/test/test_simplex_tree.py
+++ b/src/python/test/test_simplex_tree.py
@@ -128,57 +128,55 @@ def test_expansion():
assert st.num_vertices() == 7
assert st.num_simplices() == 17
- 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)
+ assert list(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),
+ ]
st.expansion(3)
assert st.num_vertices() == 7
assert st.num_simplices() == 22
st.initialize_filtration()
- 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)
+ assert list(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),
+ ]
def test_automatic_dimension():
diff --git a/src/python/test/test_tangential_complex.py b/src/python/test/test_tangential_complex.py
index 90e2c75b..fc500c45 100755
--- a/src/python/test/test_tangential_complex.py
+++ b/src/python/test/test_tangential_complex.py
@@ -38,15 +38,14 @@ def test_tangential():
assert st.num_simplices() == 6
assert st.num_vertices() == 4
- 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 list(st.get_filtration()) == [
+ ([0], 0.0),
+ ([1], 0.0),
+ ([2], 0.0),
+ ([0, 2], 0.0),
+ ([3], 0.0),
+ ([1, 3], 0.0),
+ ]
assert st.get_cofaces([0], 1) == [([0, 2], 0.0)]