def test_add_1(self): mat = [[0, 0, 1], [1, 0, 0], [0, 0, 0]] n = len(mat) csr1 = CSR(mat) csr2 = CSR(mat) csr3 = csr1.add(csr1, csr2) self.assertEquals(mat[0][0] * 2, csr3.get(0, 0)) self.assertEquals(mat[0][1] * 2, csr3.get(0, 1)) self.assertEquals(mat[0][2] * 2, csr3.get(0, 2))
def test_add_2(self): mat = [[0, 0, 1], [1, 0, 0], [0, 0, 0]] mat2 = [[0, 0, 0], [0, 1, 0], [0, 1, 1]] n = len(mat) csr1 = CSR(mat) csr2 = CSR(mat2) csr3 = csr1.add(csr1, csr2) for i in range(3): for j in range(3): print(i, j, mat[i][j] + mat2[i][j], csr3.get(i, j)) self.assertEquals(mat[i][j] + mat2[i][j], csr3.get(i, j))
def test_add(self): mat = [[0, 0, 1], [1, 0, 0], [0, 1, 0]] n = len(mat) csr1 = CSR(mat) csr2 = CSR(mat) csr3 = csr1.add(csr1, csr2)