From 437896f0764f7154e5c38e7732275a1101614fe8 Mon Sep 17 00:00:00 2001 From: Devendra Govil Date: Thu, 21 Sep 2023 00:30:28 +0530 Subject: [PATCH 1/4] Resolving Bugs in the neighborhood module --- topoembedx/neighborhood.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/topoembedx/neighborhood.py b/topoembedx/neighborhood.py index 67a3fa2..fee5089 100644 --- a/topoembedx/neighborhood.py +++ b/topoembedx/neighborhood.py @@ -14,7 +14,7 @@ def neighborhood_from_complex( Parameters ---------- - complex : SimplicialComplex or CellComplex or CombinatorialComplex or CombinatorialComplex + complex : SimplicialComplex or CellComplex or CombinatorialComplex The complex to compute the neighborhood for. neighborhood_type : str The type of neighborhood to compute. "adj" for adjacency matrix, "coadj" for coadjacency matrix. @@ -41,8 +41,7 @@ def neighborhood_from_complex( Raises ------ ValueError - If the input `complex` is not a SimplicialComplex, CellComplex, CombinatorialComplex, or - CombinatorialComplex. + If the input `complex` is not a SimplicialComplex, CellComplex or CombinatorialComplex """ if isinstance(complex, SimplicialComplex) or isinstance(complex, CellComplex): if neighborhood_type == "adj": @@ -50,9 +49,7 @@ def neighborhood_from_complex( else: ind, A = complex.coadjacency_matrix(neighborhood_dim["adj"], index=True) - elif isinstance(complex, CombinatorialComplex) or isinstance( - complex, CombinatorialComplex - ): + elif isinstance(complex, CombinatorialComplex): if neighborhood_type == "adj": ind, A = complex.adjacency_matrix( neighborhood_dim["adj"], neighborhood_dim["coadj"], index=True @@ -62,8 +59,8 @@ def neighborhood_from_complex( neighborhood_dim["coadj"], neighborhood_dim["adj"], index=True ) else: - ValueError( - "input complex must be SimplicialComplex,CellComplex,CombinatorialComplex, or CombinatorialComplex " + raise TypeError( + """Input Complex can only be a Simplicial, Cell or Combinatorial Complex.""" ) return ind, A From af087cb403b5cbfd2e233c5617f74bd7c914ba59 Mon Sep 17 00:00:00 2001 From: Devendra Govil Date: Thu, 21 Sep 2023 00:36:12 +0530 Subject: [PATCH 2/4] Adding test cases for neighborhood module --- test/test_neighborhood.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 test/test_neighborhood.py diff --git a/test/test_neighborhood.py b/test/test_neighborhood.py new file mode 100644 index 0000000..11068ac --- /dev/null +++ b/test/test_neighborhood.py @@ -0,0 +1,19 @@ +"""Testing the neighborhood module.""" + +import pytest + +import topoembedx as tex + + +class TestNeighborhood: + """Test the neighborhood module of TopoEmbedX.""" + + def test_value_error(self): + """Testing if right assertion is raised for incorrect type.""" + with pytest.raises(TypeError) as e: + tex.neighborhood.neighborhood_from_complex(1) + + assert ( + str(e.value) + == """Input Complex can only be a Simplicial, Cell or Combinatorial Complex.""" + ) From d0eb96357485497a0c537a76a95e0dd6a3a46db3 Mon Sep 17 00:00:00 2001 From: Devendra Govil Date: Thu, 21 Sep 2023 09:59:35 -0400 Subject: [PATCH 3/4] Adding test cases to test matrix dimensions for neighborhood_from_complex method --- test/test_neighborhood.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test/test_neighborhood.py b/test/test_neighborhood.py index 11068ac..0335551 100644 --- a/test/test_neighborhood.py +++ b/test/test_neighborhood.py @@ -1,6 +1,7 @@ """Testing the neighborhood module.""" import pytest +import toponetx as tnx import topoembedx as tex @@ -17,3 +18,32 @@ def test_value_error(self): str(e.value) == """Input Complex can only be a Simplicial, Cell or Combinatorial Complex.""" ) + + def test_matrix_dimensions_cellcomplex(self): + """Testing the matrix dimensions for the adjacency and coadjacency matrices.""" + # Testing for the case of Cell Complex + cc1 = tnx.classes.CellComplex( + [[0, 1, 2, 3], [1, 2, 3, 4], [1, 3, 4, 5, 6, 7, 8]] + ) + + cc2 = tnx.classes.CellComplex([[0, 1, 2], [1, 2, 3]]) + + ind, A = tex.neighborhood.neighborhood_from_complex(cc1) + assert A.todense().shape == tuple([9, 9]) + assert len(ind) == 9 + + ind, A = tex.neighborhood.neighborhood_from_complex(cc2) + assert A.todense().shape == tuple([4, 4]) + assert len(ind) == 4 + + ind, A = tex.neighborhood.neighborhood_from_complex( + cc1, neighborhood_type="!adj" + ) + assert A.todense().shape == tuple([9, 9]) + assert len(ind) == 9 + + ind, A = tex.neighborhood.neighborhood_from_complex( + cc2, neighborhood_type="!adj" + ) + assert A.todense().shape == tuple([4, 4]) + assert len(ind) == 4 From 111fbe680434c91a879c8b268e15409b07736c97 Mon Sep 17 00:00:00 2001 From: Devendra Govil Date: Thu, 21 Sep 2023 12:58:01 -0400 Subject: [PATCH 4/4] Changing test function names to confer with convention. Resolves #19 --- test/test_neighborhood.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_neighborhood.py b/test/test_neighborhood.py index 0335551..77bd6af 100644 --- a/test/test_neighborhood.py +++ b/test/test_neighborhood.py @@ -9,7 +9,7 @@ class TestNeighborhood: """Test the neighborhood module of TopoEmbedX.""" - def test_value_error(self): + def test_neighborhood_from_complex_raise_error(self): """Testing if right assertion is raised for incorrect type.""" with pytest.raises(TypeError) as e: tex.neighborhood.neighborhood_from_complex(1) @@ -19,7 +19,7 @@ def test_value_error(self): == """Input Complex can only be a Simplicial, Cell or Combinatorial Complex.""" ) - def test_matrix_dimensions_cellcomplex(self): + def test_neighborhood_from_complex_matrix_dimension_cell_complex(self): """Testing the matrix dimensions for the adjacency and coadjacency matrices.""" # Testing for the case of Cell Complex cc1 = tnx.classes.CellComplex(