Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3140_NumberSymbol/HeuristicLab.Tests/HeuristicLab.IGraph/IGraphLayoutTest.cs @ 18123

Last change on this file since 18123 was 17180, checked in by swagner, 5 years ago

#2875: Removed years in copyrights

File size: 3.4 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 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 System;
23using HeuristicLab.Common;
24using HeuristicLab.IGraph.Wrappers;
25using Microsoft.VisualStudio.TestTools.UnitTesting;
26
27namespace HeuristicLab.Tests {
28  [TestClass]
29  public class IGraphLayoutTest {
30    [TestMethod]
31    [TestCategory("ExtLibs")]
32    [TestCategory("ExtLibs.igraph")]
33    [TestProperty("Time", "short")]
34    public void IGraphWrappersLayoutFruchtermanReingoldTest() {
35      using (var graph = new Graph(5, new[] {
36        Tuple.Create(0, 1),
37        Tuple.Create(0, 2),
38        Tuple.Create(1, 2),
39        Tuple.Create(2, 3),
40        Tuple.Create(2, 4),
41        Tuple.Create(3, 4),
42      })) {
43        Assert.AreEqual(5, graph.Vertices);
44        try {
45          using (var matrix = graph.LayoutWithFruchtermanReingold()) {
46            Assert.AreEqual(5, matrix.Rows);
47            Assert.AreEqual(2, matrix.Columns);
48          }
49        } catch { Assert.Fail("Layouting with fruchterman-reingold using default parameters failed."); }
50
51        try {
52          using (var matrix = new Matrix(1, 1)) {
53            graph.LayoutWithFruchtermanReingold(50, 2, matrix);
54          }
55          Assert.Fail("Layouting with fruchterman-reingold using too little pre-initialized coordinates failed.");
56        } catch (ArgumentException) { }
57
58        try {
59          using (var matrix = new Matrix(7, 3)) {
60            graph.LayoutWithFruchtermanReingold(50, 2, matrix);
61            Assert.Fail("Layouting with fruchterman-reingold using too many pre-initialized coordinates failed.");
62          }
63        } catch (ArgumentException) { }
64
65        try {
66          using (var matrix = new Matrix(5, 2)) {
67            matrix[0, 0] = matrix[0, 1] = 1;
68            matrix[1, 0] = matrix[1, 1] = 2;
69            matrix[2, 0] = matrix[2, 1] = 3;
70            matrix[3, 0] = matrix[3, 1] = 4;
71            matrix[4, 0] = matrix[4, 1] = 5;
72            graph.LayoutWithFruchtermanReingold(50, 2, matrix);
73            Assert.AreEqual(5, matrix.Rows);
74            Assert.AreEqual(2, matrix.Columns);
75            Assert.IsFalse(
76                 matrix[0, 0].IsAlmost(1) && matrix[0, 1].IsAlmost(1)
77              && matrix[1, 0].IsAlmost(2) && matrix[1, 1].IsAlmost(2)
78              && matrix[2, 0].IsAlmost(2) && matrix[2, 1].IsAlmost(2)
79              && matrix[3, 0].IsAlmost(2) && matrix[3, 1].IsAlmost(2)
80              && matrix[4, 0].IsAlmost(2) && matrix[4, 1].IsAlmost(2));
81          }
82        } catch { Assert.Fail("Layouting with fruchterman-reingold using pre-initialized coordinates failed."); }
83      }
84    }
85  }
86}
Note: See TracBrowser for help on using the repository browser.