Commit 460fec474d74e9bfc3527f460979bef7657dd416
1 parent
0d054474
Start implementing matrix tests.
Showing
1 changed file
with
78 additions
and
4 deletions
test/test_GLinalg.py
| ... | ... | @@ -50,16 +50,90 @@ class Test(GPythonTestSuite): |
| 50 | 50 | self.name("linalg") |
| 51 | 51 | |
| 52 | 52 | # Append tests |
| 53 | - self.append(self.test, "Linear algebra module dummy test") | |
| 53 | + self.append(self.test_matrix, "Test GMatrix") | |
| 54 | + self.append(self.test_sym_matrix, "Test GSymMatrix") | |
| 55 | + self.append(self.test_sparse_matrix, "Test GSparseMatrix") | |
| 54 | 56 | |
| 55 | 57 | # Return |
| 56 | 58 | return |
| 57 | 59 | |
| 58 | 60 | |
| 59 | - # Test function | |
| 60 | - def test(self): | |
| 61 | + # Test GMatrix class | |
| 62 | + def test_matrix(self): | |
| 61 | 63 | """ |
| 62 | - Test function. | |
| 64 | + Test GMatrix class. | |
| 63 | 65 | """ |
| 66 | + # Set matrix size | |
| 67 | + nrows = 3 | |
| 68 | + ncols = 5 | |
| 69 | + | |
| 70 | + # Allocate matrix | |
| 71 | + m = GMatrix(nrows,ncols) | |
| 72 | + | |
| 73 | + # Fill elements | |
| 74 | + for i in range(nrows): | |
| 75 | + for j in range(ncols): | |
| 76 | + m[i,j] = i+j | |
| 77 | + | |
| 78 | + # Check elements | |
| 79 | + for i in range(nrows): | |
| 80 | + for j in range(ncols): | |
| 81 | + ref = i+j | |
| 82 | + self.test_value(m[i,j],ref,0.0,"Test matrix element access") | |
| 83 | + | |
| 84 | + # Return | |
| 85 | + return | |
| 86 | + | |
| 87 | + | |
| 88 | + # Test GSymMatrix class | |
| 89 | + def test_sym_matrix(self): | |
| 90 | + """ | |
| 91 | + Test GSymMatrix class. | |
| 92 | + """ | |
| 93 | + # Set matrix size | |
| 94 | + nrows = 3 | |
| 95 | + ncols = 3 | |
| 96 | + | |
| 97 | + # Allocate matrix | |
| 98 | + m = GSymMatrix(nrows,ncols) | |
| 99 | + | |
| 100 | + # Fill elements | |
| 101 | + for i in range(nrows): | |
| 102 | + for j in range(ncols): | |
| 103 | + m[i,j] = i+j | |
| 104 | + | |
| 105 | + # Check elements | |
| 106 | + for i in range(nrows): | |
| 107 | + for j in range(ncols): | |
| 108 | + ref = i+j | |
| 109 | + self.test_value(m[i,j],ref,0.0,"Test matrix element access") | |
| 110 | + | |
| 111 | + # Return | |
| 112 | + return | |
| 113 | + | |
| 114 | + | |
| 115 | + # Test GSparseMatrix class | |
| 116 | + def test_sparse_matrix(self): | |
| 117 | + """ | |
| 118 | + Test GSparseMatrix class. | |
| 119 | + """ | |
| 120 | + # Set matrix size | |
| 121 | + nrows = 5 | |
| 122 | + ncols = 3 | |
| 123 | + | |
| 124 | + # Allocate matrix | |
| 125 | + m = GSparseMatrix(nrows,ncols) | |
| 126 | + | |
| 127 | + # Fill elements | |
| 128 | + for i in range(nrows): | |
| 129 | + for j in range(ncols): | |
| 130 | + m[i,j] = i+j | |
| 131 | + | |
| 132 | + # Check elements | |
| 133 | + for i in range(nrows): | |
| 134 | + for j in range(ncols): | |
| 135 | + ref = i+j | |
| 136 | + self.test_value(m[i,j],ref,0.0,"Test matrix element access") | |
| 137 | + | |
| 64 | 138 | # Return |
| 65 | 139 | return | ... | ... |