def test_directed(self): # with list index idx1 = [0, -1, 1] idx2 = np.array(idx1) for indices in [idx1, idx2]: A, a = gus.remove_vertices(self.directed, indices, return_removed=True) self.assertIsInstance(a, tuple) self.assertIsInstance(a[0], np.ndarray) self.assertIsInstance(a[1], np.ndarray) assert_equal(A, np.array([[0, 14], [18, 0]])) assert_equal(a[0], np.array([[11, 16], [15, 20], [12, 17]])) assert_equal(a[1], np.array([[3, 4], [23, 24], [8, 9]])) # with integer index idx = 0 A, a = gus.remove_vertices(self.directed, idx, return_removed=True) assert_equal(A, gus.remove_vertices(self.directed, idx)) self.assertIsInstance(a, tuple) self.assertIsInstance(a[0], np.ndarray) self.assertIsInstance(a[1], np.ndarray) assert_equal(A, self.directed[1:, 1:]) assert_equal(a[0], np.array([6, 11, 16, 21])) assert_equal(a[1], np.array([2, 3, 4, 5]))
def test_exceptions(self): # ensure proper errors are thrown when invalid inputs are passed. with pytest.raises(TypeError): gus.remove_vertices(9001, 0) with pytest.raises(ValueError): nonsquare = np.vstack((self.directed, self.directed)) gus.remove_vertices(nonsquare, 0) with pytest.raises(IndexError): indices = np.arange(len(self.directed) + 1) gus.remove_vertices(self.directed, indices) with pytest.raises(IndexError): idx = len(self.directed) + 1 gus.remove_vertices(self.directed, indices)
def test_undirected(self): # with list index indices = [0, -1, 1] for idx in [indices, np.array(indices)]: A, a = gus.remove_vertices(self.undirected, idx, return_removed=True) self.assertIsInstance(a, np.ndarray) assert_equal(A, np.array([[0, 18], [18, 0]])) assert_equal(a, np.array([[11, 16], [23, 24], [12, 17]])) self.assertTrue(gus.is_almost_symmetric(A)) # with integer index indices = 0 A, a = gus.remove_vertices(self.undirected, indices, return_removed=True) assert_equal(A, self.undirected[1:, 1:]) assert_equal(a, np.array([6, 11, 16, 21])) self.assertTrue(gus.is_almost_symmetric(A)) assert_equal( gus.remove_vertices(self.undirected, 0), gus.remove_vertices(self.undirected, [0]), )