Free cookie consent management tool by TermsFeed Policy Generator

source: branches/MemPRAlgorithm/HeuristicLab.Tests/HeuristicLab.IGraph/IGraphWrappersMatrixTest.cs @ 15160

Last change on this file since 15160 was 14257, checked in by abeham, 8 years ago

#2651: removed failing tests from project, still left in Repository (renamed category from igraph to ExtLibs.igraph)

File size: 4.3 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
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
22using HeuristicLab.IGraph.Wrappers;
23using Microsoft.VisualStudio.TestTools.UnitTesting;
24
25namespace HeuristicLab.Tests {
26  [TestClass]
27  public class IGraphWrappersMatrixTest {
28    [TestMethod]
29    [TestCategory("ExtLibs")]
30    [TestCategory("ExtLibs.igraph")]
31    [TestProperty("Time", "short")]
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
43      var mat = new double[,] {
44        { 1, 2, 3 },
45        { 4, 5, 6}
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        }
56    }
57
58    [TestMethod]
59    [TestCategory("ExtLibs")]
60    [TestCategory("ExtLibs.igraph")]
61    [TestProperty("Time", "short")]
62    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]);
75
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]);
82    }
83
84    [TestMethod]
85    [TestCategory("ExtLibs")]
86    [TestCategory("ExtLibs.igraph")]
87    [TestProperty("Time", "short")]
88    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]);
97    }
98
99    [TestMethod]
100    [TestCategory("ExtLibs")]
101    [TestCategory("ExtLibs.igraph")]
102    [TestProperty("Time", "short")]
103    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);
108    }
109
110    [TestMethod]
111    [TestCategory("ExtLibs")]
112    [TestCategory("ExtLibs.igraph")]
113    [TestProperty("Time", "short")]
114    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]);
128    }
129  }
130}
Note: See TracBrowser for help on using the repository browser.