From 460fec474d74e9bfc3527f460979bef7657dd416 Mon Sep 17 00:00:00 2001 From: Jürgen Knödlseder Date: Thu, 6 Sep 2012 22:10:28 +0200 Subject: [PATCH] Start implementing matrix tests. --- test/test_GLinalg.py | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 78 insertions(+), 4 deletions(-) diff --git a/test/test_GLinalg.py b/test/test_GLinalg.py index 40f941b..0d05313 100755 --- a/test/test_GLinalg.py +++ b/test/test_GLinalg.py @@ -50,16 +50,90 @@ class Test(GPythonTestSuite): self.name("linalg") # Append tests - self.append(self.test, "Linear algebra module dummy test") + self.append(self.test_matrix, "Test GMatrix") + self.append(self.test_sym_matrix, "Test GSymMatrix") + self.append(self.test_sparse_matrix, "Test GSparseMatrix") # Return return - # Test function - def test(self): + # Test GMatrix class + def test_matrix(self): """ - Test function. + Test GMatrix class. """ + # Set matrix size + nrows = 3 + ncols = 5 + + # Allocate matrix + m = GMatrix(nrows,ncols) + + # Fill elements + for i in range(nrows): + for j in range(ncols): + m[i,j] = i+j + + # Check elements + for i in range(nrows): + for j in range(ncols): + ref = i+j + self.test_value(m[i,j],ref,0.0,"Test matrix element access") + + # Return + return + + + # Test GSymMatrix class + def test_sym_matrix(self): + """ + Test GSymMatrix class. + """ + # Set matrix size + nrows = 3 + ncols = 3 + + # Allocate matrix + m = GSymMatrix(nrows,ncols) + + # Fill elements + for i in range(nrows): + for j in range(ncols): + m[i,j] = i+j + + # Check elements + for i in range(nrows): + for j in range(ncols): + ref = i+j + self.test_value(m[i,j],ref,0.0,"Test matrix element access") + + # Return + return + + + # Test GSparseMatrix class + def test_sparse_matrix(self): + """ + Test GSparseMatrix class. + """ + # Set matrix size + nrows = 5 + ncols = 3 + + # Allocate matrix + m = GSparseMatrix(nrows,ncols) + + # Fill elements + for i in range(nrows): + for j in range(ncols): + m[i,j] = i+j + + # Check elements + for i in range(nrows): + for j in range(ncols): + ref = i+j + self.test_value(m[i,j],ref,0.0,"Test matrix element access") + # Return return -- libgit2 0.21.4