[14276] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[17180] | 3 | * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[14276] | 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using HeuristicLab.IGraph.Wrappers;
|
---|
| 23 | using Microsoft.VisualStudio.TestTools.UnitTesting;
|
---|
| 24 |
|
---|
| 25 | namespace HeuristicLab.Tests {
|
---|
| 26 | [TestClass]
|
---|
| 27 | public class IGraphWrappersMatrixTest {
|
---|
| 28 | [TestMethod]
|
---|
[14277] | 29 | [TestCategory("ExtLibs")]
|
---|
| 30 | [TestCategory("ExtLibs.igraph")]
|
---|
| 31 | [TestProperty("Time", "short")]
|
---|
| 32 | public void IGraphWrappersMatrixConstructionAndFinalizationTest() {
|
---|
[15191] | 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 | }
|
---|
[14277] | 43 | var mat = new double[,] {
|
---|
| 44 | { 1, 2, 3 },
|
---|
| 45 | { 4, 5, 6}
|
---|
| 46 | };
|
---|
[15191] | 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 | }
|
---|
[14276] | 57 | }
|
---|
| 58 |
|
---|
| 59 | [TestMethod]
|
---|
[14277] | 60 | [TestCategory("ExtLibs")]
|
---|
| 61 | [TestCategory("ExtLibs.igraph")]
|
---|
| 62 | [TestProperty("Time", "short")]
|
---|
[14276] | 63 | public void IGraphWrappersMatrixGetSetTest() {
|
---|
[15191] | 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]);
|
---|
[14276] | 76 |
|
---|
[15191] | 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 | }
|
---|
[14276] | 84 | }
|
---|
[14277] | 85 |
|
---|
| 86 | [TestMethod]
|
---|
| 87 | [TestCategory("ExtLibs")]
|
---|
| 88 | [TestCategory("ExtLibs.igraph")]
|
---|
| 89 | [TestProperty("Time", "short")]
|
---|
| 90 | public void IGraphWrappersMatrixFillTest() {
|
---|
[15191] | 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 | }
|
---|
[14277] | 100 | }
|
---|
| 101 |
|
---|
| 102 | [TestMethod]
|
---|
| 103 | [TestCategory("ExtLibs")]
|
---|
| 104 | [TestCategory("ExtLibs.igraph")]
|
---|
| 105 | [TestProperty("Time", "short")]
|
---|
| 106 | public void IGraphWrappersMatrixTransposeTest() {
|
---|
[15191] | 107 | using (var matrix = new Matrix(3, 2)) {
|
---|
| 108 | matrix.Transpose();
|
---|
| 109 | Assert.AreEqual(2, matrix.Rows);
|
---|
| 110 | Assert.AreEqual(3, matrix.Columns);
|
---|
| 111 | }
|
---|
[14277] | 112 | }
|
---|
| 113 |
|
---|
| 114 | [TestMethod]
|
---|
| 115 | [TestCategory("ExtLibs")]
|
---|
| 116 | [TestCategory("ExtLibs.igraph")]
|
---|
| 117 | [TestProperty("Time", "short")]
|
---|
| 118 | public void IGraphWrappersMatrixScaleTest() {
|
---|
[15191] | 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 | }
|
---|
[14277] | 133 | }
|
---|
[14276] | 134 | }
|
---|
| 135 | }
|
---|