Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2701_MemPRAlgorithm/HeuristicLab.Tests/HeuristicLab.IGraph/IGraphWrappersVectorTest.cs @ 16310

Last change on this file since 16310 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.1 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.Linq;
23using HeuristicLab.IGraph.Wrappers;
24using Microsoft.VisualStudio.TestTools.UnitTesting;
25
26namespace HeuristicLab.Tests {
27  [TestClass]
28  public class IGraphWrappersVectorTest {
29    [TestMethod]
30    [TestCategory("ExtLibs")]
31    [TestCategory("ExtLibs.igraph")]
32    [TestProperty("Time", "short")]
33    public void IGraphWrappersVectorConstructionAndFinalizationTest() {
34      var vector = new Vector(7);
35      Assert.AreEqual(7, vector.Length);
36      Assert.AreEqual(0, vector[0]);
37      vector[0] = 4;
38      var other = new Vector(vector);
39      Assert.AreEqual(7, other.Length);
40      Assert.AreEqual(4, other[0]);
41
42      var myvec = new double[] { 1, 2, 3 };
43      vector = new Vector(myvec);
44      Assert.AreEqual(3, vector.Length);
45      Assert.AreEqual(myvec[0], vector[0]);
46      Assert.AreEqual(myvec[1], vector[1]);
47      Assert.AreEqual(myvec[2], vector[2]);
48    }
49
50    [TestMethod]
51    [TestCategory("ExtLibs")]
52    [TestCategory("ExtLibs.igraph")]
53    [TestProperty("Time", "short")]
54    public void IGraphWrappersVectorGetSetTest() {
55      var vector = new Vector(5);
56      vector[0] = vector[1] = 4;
57      vector[2] = 3;
58      vector[3] = 1.5;
59      vector[4] = -0.5;
60      Assert.AreEqual(4, vector[0]);
61      Assert.AreEqual(4, vector[1]);
62      Assert.AreEqual(3, vector[2]);
63      Assert.AreEqual(1.5, vector[3]);
64      Assert.AreEqual(-0.5, vector[4]);
65
66      var netmat = vector.ToArray();
67      Assert.AreEqual(5, netmat.Length);
68      for (var i = 0; i < netmat.Length; i++)
69        Assert.AreEqual(vector[i], netmat[i]);
70    }
71
72    [TestMethod]
73    [TestCategory("ExtLibs")]
74    [TestCategory("ExtLibs.igraph")]
75    [TestProperty("Time", "short")]
76    public void IGraphWrappersVectorFillTest() {
77      var vector = new Vector(5);
78      vector.Fill(2.3);
79      Assert.IsTrue(new[] { 2.3, 2.3, 2.3, 2.3, 2.3 }.SequenceEqual(vector.ToArray()));
80    }
81
82    [TestMethod]
83    [TestCategory("ExtLibs")]
84    [TestCategory("ExtLibs.igraph")]
85    [TestProperty("Time", "short")]
86    public void IGraphWrappersVectorReverseTest() {
87      var vector = new Vector(5);
88      vector[0] = vector[1] = 4;
89      vector[2] = 3;
90      vector[3] = 1.5;
91      vector[4] = -0.5;
92      vector.Reverse();
93      Assert.IsTrue(new[] { -0.5, 1.5, 3, 4, 4 }.SequenceEqual(vector.ToArray()));
94    }
95
96    [TestMethod]
97    [TestCategory("ExtLibs")]
98    [TestCategory("ExtLibs.igraph")]
99    [TestProperty("Time", "short")]
100    public void IGraphWrappersVectorShuffleTest() {
101      var vector = new Vector(5);
102      vector[0] = vector[1] = 4;
103      vector[2] = 3;
104      vector[3] = 1.5;
105      vector[4] = -0.5;
106      vector.Shuffle();
107      Assert.IsFalse(new[] { -0.5, 1.5, 3, 4, 4 }.SequenceEqual(vector.ToArray()));
108      Assert.IsFalse(new[] { 4, 4, 3, 1.5, -0.5 }.SequenceEqual(vector.ToArray()));
109    }
110
111    [TestMethod]
112    [TestCategory("ExtLibs")]
113    [TestCategory("ExtLibs.igraph")]
114    [TestProperty("Time", "short")]
115    public void IGraphWrappersVectorScaleTest() {
116      var vector = new Vector(5);
117      vector[0] = vector[1] = 4;
118      vector[2] = 3;
119      vector[3] = 1.5;
120      vector[4] = -0.5;
121      vector.Scale(2);
122      Assert.IsTrue(new double[] { 8, 8, 6, 3, -1 }.SequenceEqual(vector.ToArray()));
123    }
124  }
125}
Note: See TracBrowser for help on using the repository browser.