From 3ea44646f04648d1a456a0fb9526035101fc17ea Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Tue, 11 Feb 2020 17:20:24 +0100 Subject: Code review: non-optimal way to test filtration generator --- src/python/test/test_rips_complex.py | 50 +++++++++++++++++------------------- 1 file changed, 24 insertions(+), 26 deletions(-) (limited to 'src/python/test/test_rips_complex.py') 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), -- cgit v1.2.3