Changeset 15191 for trunk/sources/HeuristicLab.Tests/HeuristicLab.IGraph/IGraphWrappersMatrixTest.cs
- Timestamp:
- 07/11/17 11:19:37 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Tests/HeuristicLab.IGraph/IGraphWrappersMatrixTest.cs
r14277 r15191 31 31 [TestProperty("Time", "short")] 32 32 public void IGraphWrappersMatrixConstructionAndFinalizationTest() { 33 var matrix = new Matrix(3, 2);34 Assert.AreEqual(3, matrix.Rows);35 Assert.AreEqual(2, matrix.Columns);36 Assert.AreEqual(0, matrix[0, 0]);37 matrix[0, 0] = 4;38 var other = new Matrix(matrix);39 Assert.AreEqual(3, other.Rows);40 Assert.AreEqual(2, other.Columns);41 Assert.AreEqual(4, other[0, 0]);42 33 using (var matrix = new Matrix(3, 2)) { 34 Assert.AreEqual(3, matrix.Rows); 35 Assert.AreEqual(2, matrix.Columns); 36 Assert.AreEqual(0, matrix[0, 0]); 37 matrix[0, 0] = 4; 38 var other = new Matrix(matrix); 39 Assert.AreEqual(3, other.Rows); 40 Assert.AreEqual(2, other.Columns); 41 Assert.AreEqual(4, other[0, 0]); 42 } 43 43 var mat = new double[,] { 44 44 { 1, 2, 3 }, 45 45 { 4, 5, 6} 46 46 }; 47 matrix = new Matrix(mat); 48 Assert.AreEqual(2, matrix.Rows); 49 Assert.AreEqual(3, matrix.Columns); 50 var test = matrix.ToMatrix(); 51 for (var i = 0; i < matrix.Rows; i++) 52 for (var j = 0; j < matrix.Columns; j++) { 53 Assert.AreEqual(mat[i, j], matrix[i, j]); 54 Assert.AreEqual(mat[i, j], test[i, j]); 55 } 47 using (var matrix = new Matrix(mat)) { 48 Assert.AreEqual(2, matrix.Rows); 49 Assert.AreEqual(3, matrix.Columns); 50 var test = matrix.ToMatrix(); 51 for (var i = 0; i < matrix.Rows; i++) 52 for (var j = 0; j < matrix.Columns; j++) { 53 Assert.AreEqual(mat[i, j], matrix[i, j]); 54 Assert.AreEqual(mat[i, j], test[i, j]); 55 } 56 } 56 57 } 57 58 … … 61 62 [TestProperty("Time", "short")] 62 63 public void IGraphWrappersMatrixGetSetTest() { 63 var matrix = new Matrix(3, 2);64 matrix[0, 0] = matrix[0, 1] = 4;65 matrix[1, 0] = 3;66 matrix[1, 1] = 2;67 matrix[2, 0] = 1.5;68 matrix[2, 1] = -0.5;69 Assert.AreEqual(4, matrix[0, 0]);70 Assert.AreEqual(4, matrix[0, 1]);71 Assert.AreEqual(3, matrix[1, 0]);72 Assert.AreEqual(2, matrix[1, 1]);73 Assert.AreEqual(1.5, matrix[2, 0]);74 Assert.AreEqual(-0.5, matrix[2, 1]);64 using (var matrix = new Matrix(3, 2)) { 65 matrix[0, 0] = matrix[0, 1] = 4; 66 matrix[1, 0] = 3; 67 matrix[1, 1] = 2; 68 matrix[2, 0] = 1.5; 69 matrix[2, 1] = -0.5; 70 Assert.AreEqual(4, matrix[0, 0]); 71 Assert.AreEqual(4, matrix[0, 1]); 72 Assert.AreEqual(3, matrix[1, 0]); 73 Assert.AreEqual(2, matrix[1, 1]); 74 Assert.AreEqual(1.5, matrix[2, 0]); 75 Assert.AreEqual(-0.5, matrix[2, 1]); 75 76 76 var netmat = matrix.ToMatrix(); 77 Assert.AreEqual(3, netmat.GetLength(0)); 78 Assert.AreEqual(2, netmat.GetLength(1)); 79 for (var i = 0; i < netmat.GetLength(0); i++) 80 for (var j = 0; j < netmat.GetLength(1); j++) 81 Assert.AreEqual(matrix[i, j], netmat[i, j]); 77 var netmat = matrix.ToMatrix(); 78 Assert.AreEqual(3, netmat.GetLength(0)); 79 Assert.AreEqual(2, netmat.GetLength(1)); 80 for (var i = 0; i < netmat.GetLength(0); i++) 81 for (var j = 0; j < netmat.GetLength(1); j++) 82 Assert.AreEqual(matrix[i, j], netmat[i, j]); 83 } 82 84 } 83 85 … … 87 89 [TestProperty("Time", "short")] 88 90 public void IGraphWrappersMatrixFillTest() { 89 var matrix = new Matrix(3, 2); 90 matrix.Fill(2.6); 91 Assert.AreEqual(2.6, matrix[0, 0]); 92 Assert.AreEqual(2.6, matrix[0, 1]); 93 Assert.AreEqual(2.6, matrix[1, 0]); 94 Assert.AreEqual(2.6, matrix[1, 1]); 95 Assert.AreEqual(2.6, matrix[2, 0]); 96 Assert.AreEqual(2.6, matrix[2, 1]); 91 using (var matrix = new Matrix(3, 2)) { 92 matrix.Fill(2.6); 93 Assert.AreEqual(2.6, matrix[0, 0]); 94 Assert.AreEqual(2.6, matrix[0, 1]); 95 Assert.AreEqual(2.6, matrix[1, 0]); 96 Assert.AreEqual(2.6, matrix[1, 1]); 97 Assert.AreEqual(2.6, matrix[2, 0]); 98 Assert.AreEqual(2.6, matrix[2, 1]); 99 } 97 100 } 98 101 … … 102 105 [TestProperty("Time", "short")] 103 106 public void IGraphWrappersMatrixTransposeTest() { 104 var matrix = new Matrix(3, 2); 105 matrix.Transpose(); 106 Assert.AreEqual(2, matrix.Rows); 107 Assert.AreEqual(3, matrix.Columns); 107 using (var matrix = new Matrix(3, 2)) { 108 matrix.Transpose(); 109 Assert.AreEqual(2, matrix.Rows); 110 Assert.AreEqual(3, matrix.Columns); 111 } 108 112 } 109 113 … … 113 117 [TestProperty("Time", "short")] 114 118 public void IGraphWrappersMatrixScaleTest() { 115 var matrix = new Matrix(3, 2); 116 matrix[0, 0] = matrix[0, 1] = 4; 117 matrix[1, 0] = 3; 118 matrix[1, 1] = 2; 119 matrix[2, 0] = 1.5; 120 matrix[2, 1] = -0.5; 121 matrix.Scale(2); 122 Assert.AreEqual(8, matrix[0, 0]); 123 Assert.AreEqual(8, matrix[0, 1]); 124 Assert.AreEqual(6, matrix[1, 0]); 125 Assert.AreEqual(4, matrix[1, 1]); 126 Assert.AreEqual(3, matrix[2, 0]); 127 Assert.AreEqual(-1, matrix[2, 1]); 119 using (var matrix = new Matrix(3, 2)) { 120 matrix[0, 0] = matrix[0, 1] = 4; 121 matrix[1, 0] = 3; 122 matrix[1, 1] = 2; 123 matrix[2, 0] = 1.5; 124 matrix[2, 1] = -0.5; 125 matrix.Scale(2); 126 Assert.AreEqual(8, matrix[0, 0]); 127 Assert.AreEqual(8, matrix[0, 1]); 128 Assert.AreEqual(6, matrix[1, 0]); 129 Assert.AreEqual(4, matrix[1, 1]); 130 Assert.AreEqual(3, matrix[2, 0]); 131 Assert.AreEqual(-1, matrix[2, 1]); 132 } 128 133 } 129 134 }
Note: See TracChangeset
for help on using the changeset viewer.