source: branches/symbreg-factors-2650/HeuristicLab.Tests/HeuristicLab.IGraph/IGraphLayoutTest.cs @ 14276

Last change on this file since 14276 was 14276, checked in by gkronber, 5 years ago

#2650: merged r14244 from trunk to branch

File size: 3.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 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    public void TestFruchtermanReingold() {
32      var graph = new Graph(5, new[] {
33        Tuple.Create(0, 1),
34        Tuple.Create(0, 2),
35        Tuple.Create(1, 2),
36        Tuple.Create(2, 3),
37        Tuple.Create(2, 4),
38        Tuple.Create(3, 4),
39      });
40      Assert.AreEqual(5, graph.Vertices);
41      try {
42        using (var matrix = graph.LayoutWithFruchtermanReingold()) {
43          Assert.AreEqual(5, matrix.Rows);
44          Assert.AreEqual(2, matrix.Columns);
45        }
46      } catch { Assert.Fail("Layouting with fruchterman-reingold using default parameters failed."); }
47
48      try {
49        using (var matrix = new Matrix(1, 1)) {
50          graph.LayoutWithFruchtermanReingold(50, 2, matrix);
51        }
52        Assert.Fail("Layouting with fruchterman-reingold using too little pre-initialized coordinates failed.");
53      } catch (ArgumentException) { }
54
55      try {
56        using (var matrix = new Matrix(7, 3)) {
57          graph.LayoutWithFruchtermanReingold(50, 2, matrix);
58          Assert.Fail("Layouting with fruchterman-reingold using too many pre-initialized coordinates failed.");
59        }
60      } catch (ArgumentException) { }
61
62      try {
63        using (var matrix = new Matrix(5, 2)) {
64          matrix[0, 0] = matrix[0, 1] = 1;
65          matrix[1, 0] = matrix[1, 1] = 2;
66          matrix[2, 0] = matrix[2, 1] = 3;
67          matrix[3, 0] = matrix[3, 1] = 4;
68          matrix[4, 0] = matrix[4, 1] = 5;
69          graph.LayoutWithFruchtermanReingold(50, 2, matrix);
70          Assert.AreEqual(5, matrix.Rows);
71          Assert.AreEqual(2, matrix.Columns);
72          Assert.IsFalse(
73               matrix[0, 0].IsAlmost(1) && matrix[0, 1].IsAlmost(1)
74            && matrix[1, 0].IsAlmost(2) && matrix[1, 1].IsAlmost(2)
75            && matrix[2, 0].IsAlmost(2) && matrix[2, 1].IsAlmost(2)
76            && matrix[3, 0].IsAlmost(2) && matrix[3, 1].IsAlmost(2)
77            && matrix[4, 0].IsAlmost(2) && matrix[4, 1].IsAlmost(2));
78        }
79      } catch { Assert.Fail("Layouting with fruchterman-reingold using pre-initialized coordinates failed."); }
80    }
81  }
82}
Note: See TracBrowser for help on using the repository browser.