Skip to content

Commit

Permalink
Use sp.issparse in tests (#126)
Browse files Browse the repository at this point in the history
Use sp.issparse instead of type check in tests
  • Loading branch information
simonbowly authored Dec 1, 2023
1 parent d1723e8 commit a700b7b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
16 changes: 8 additions & 8 deletions tests/test_bipartite_matching.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def test_empty(self):

matching = maximum_bipartite_matching(adjacency, nodes1, nodes2)

self.assertIsInstance(matching, sp.spmatrix)
self.assertTrue(sp.issparse(matching))
self.assertIsNot(matching, adjacency)
self.assertEqual(matching.nnz, 0)
self.assertEqual(matching.shape, (degree, degree))
Expand All @@ -65,7 +65,7 @@ def test_complete_bipartite(self):

matching = maximum_bipartite_matching(adjacency, nodes1, nodes2)

self.assertIsInstance(matching, sp.spmatrix)
self.assertTrue(sp.issparse(matching))
self.assertIsNot(matching, adjacency)
self.assertEqual(matching.shape, (degree, degree))
self.assert_is_unweighted_matching(matching)
Expand All @@ -85,7 +85,7 @@ def test_simple(self):

matching = maximum_bipartite_matching(adjacency, nodes1, nodes2)

self.assertIsInstance(matching, sp.spmatrix)
self.assertTrue(sp.issparse(matching))
self.assertIsNot(matching, adjacency)
self.assertEqual(matching.shape, (degree, degree))
self.assert_is_unweighted_matching(matching)
Expand All @@ -103,7 +103,7 @@ def test_simple_2(self):

matching = maximum_bipartite_matching(adjacency, nodes1, nodes2)

self.assertIsInstance(matching, sp.spmatrix)
self.assertTrue(sp.issparse(matching))
self.assertIsNot(matching, adjacency)
self.assertEqual(matching.shape, (6, 6))
self.assert_is_unweighted_matching(matching)
Expand All @@ -121,7 +121,7 @@ def test_random(self):

matching = maximum_bipartite_matching(adjacency, nodes1, nodes2)

self.assertIsInstance(matching, sp.spmatrix)
self.assertTrue(sp.issparse(matching))
self.assertIsNot(matching, adjacency)
self.assertEqual(matching.shape, adjacency.shape)
self.assert_is_unweighted_matching(matching)
Expand All @@ -132,7 +132,7 @@ def test_random_csr_matrix(self):

matching = maximum_bipartite_matching(sp.csr_matrix(adjacency), nodes1, nodes2)

self.assertIsInstance(matching, sp.spmatrix)
self.assertTrue(sp.issparse(matching))
self.assertIsNot(matching, adjacency)
self.assertEqual(matching.shape, adjacency.shape)
self.assert_is_unweighted_matching(matching)
Expand All @@ -143,7 +143,7 @@ def test_random_csr_array(self):

matching = maximum_bipartite_matching(sp.csr_array(adjacency), nodes1, nodes2)

self.assertIsInstance(matching, sp.spmatrix)
self.assertTrue(sp.issparse(matching))
self.assertIsNot(matching, adjacency)
self.assertEqual(matching.shape, adjacency.shape)
self.assert_is_unweighted_matching(matching)
Expand All @@ -154,7 +154,7 @@ def test_random_csc_array(self):

matching = maximum_bipartite_matching(sp.csc_array(adjacency), nodes1, nodes2)

self.assertIsInstance(matching, sp.spmatrix)
self.assertTrue(sp.issparse(matching))
self.assertIsNot(matching, adjacency)
self.assertEqual(matching.shape, adjacency.shape)
self.assert_is_unweighted_matching(matching)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_min_cost_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def test_scipy(self):
[0.0, 0.0, 0.0, 0.0, 0.0, 2.0],
]
)
self.assertIsInstance(sol, sp.spmatrix)
self.assertTrue(sp.issparse(sol))
self.assertTrue(check_solution_scipy(sol, [candidate]))

@unittest.skipIf(nx is None, "networkx is not installed")
Expand Down

0 comments on commit a700b7b

Please sign in to comment.