[14244] | 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 |
|
---|
| 22 | using System;
|
---|
| 23 | using HeuristicLab.Common;
|
---|
| 24 | using HeuristicLab.IGraph.Wrappers;
|
---|
| 25 | using Microsoft.VisualStudio.TestTools.UnitTesting;
|
---|
| 26 |
|
---|
| 27 | namespace HeuristicLab.Tests {
|
---|
| 28 | [TestClass]
|
---|
| 29 | public class IGraphLayoutTest {
|
---|
| 30 | [TestMethod]
|
---|
[14245] | 31 | [TestCategory("ExtLibs")]
|
---|
[14257] | 32 | [TestCategory("ExtLibs.igraph")]
|
---|
[14245] | 33 | [TestProperty("Time", "short")]
|
---|
[14247] | 34 | public void IGraphWrappersLayoutFruchtermanReingoldTest() {
|
---|
[14244] | 35 | 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 | }
|
---|