source: trunk/sources/HeuristicLab.Tests/HeuristicLab.IGraph/IGraphWrappersMatrixTest.cs @ 14244

Last change on this file since 14244 was 14244, checked in by abeham, 3 years ago

#2651: worked on igraph integration, additional layout algorithms, density, page rank

  • added unit tests
File size: 2.2 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    public void IGraphWrappersMatrixConstructionAndFinalization() {
30      var matrix = new Matrix(3, 2);
31      Assert.AreEqual(3, matrix.Rows);
32      Assert.AreEqual(2, matrix.Columns);
33      Assert.AreEqual(0, matrix[0, 0]);
34      matrix[0, 0] = 4;
35      var other = new Matrix(matrix);
36      Assert.AreEqual(3, other.Rows);
37      Assert.AreEqual(2, other.Columns);
38      Assert.AreEqual(4, other[0, 0]);
39    }
40
41    [TestMethod]
42    public void IGraphWrappersMatrixGetSetTest() {
43      var matrix = new Matrix(3, 2);
44      matrix[0, 0] = matrix[0, 1] = 4;
45      matrix[1, 0] = 3;
46      matrix[1, 1] = 2;
47      matrix[2, 0] = 1.5;
48      matrix[2, 1] = -0.5;
49      Assert.AreEqual(4, matrix[0, 0]);
50      Assert.AreEqual(4, matrix[0, 1]);
51      Assert.AreEqual(3, matrix[1, 0]);
52      Assert.AreEqual(2, matrix[1, 1]);
53      Assert.AreEqual(1.5, matrix[2, 0]);
54      Assert.AreEqual(-0.5, matrix[2, 1]);
55
56      var netmat = matrix.ToMatrix();
57      Assert.AreEqual(3, netmat.GetLength(0));
58      Assert.AreEqual(2, netmat.GetLength(1));
59      for (var i = 0; i < netmat.GetLength(0); i++)
60        for (var j = 0; j < netmat.GetLength(1); j++)
61          Assert.AreEqual(matrix[i, j], netmat[i, j]);
62    }
63  }
64}
Note: See TracBrowser for help on using the repository browser.