Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3082_Scaling/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis-3.4/DatasetTest.cs @ 17959

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

#2875: Removed years in copyrights

File size: 3.2 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 System.Collections;
24using System.Collections.Generic;
25using System.Linq;
26using Microsoft.VisualStudio.TestTools.UnitTesting;
27
28namespace HeuristicLab.Problems.DataAnalysis.Tests {
29  [TestClass]
30  public class DatasetTest {
31    private TestContext testContextInstance;
32    /// <summary>
33    ///Gets or sets the test context which provides
34    ///information about and functionality for the current test run.
35    ///</summary>
36    public TestContext TestContext {
37      get { return testContextInstance; }
38      set { testContextInstance = value; }
39    }
40
41    [TestMethod]
42    [TestCategory("Problems.DataAnalysis")]
43    [TestProperty("Time", "short")]
44    public void TestImportRowiseData() {
45      var matrix = new double[,] { { 1, 2, 3 }, { 2, 3, 1 }, { 3, 1, 2 }, { 1, 2, 3 }, { 2, 3, 1 } };
46      var ds = Dataset.FromRowData(new[] { "X1", "X2", "X3" }, matrix);
47      Assert.AreEqual(3, ds.Columns);
48      Assert.AreEqual(5, ds.Rows);
49      Assert.IsTrue(ds.GetDoubleValues("X1").SequenceEqual(new double[] { 1, 2, 3, 1, 2 }));
50
51      var listoflits = new List<List<double>>() {
52        new List<double>() { 1, 2, 3 },
53        new List<double>() { 2, 3, 1 },
54        new List<double>() { 3, 1, 2 },
55        new List<double>() { 1, 2, 3 },
56        new List<double>() { 2, 3, 1 }
57      };
58      ds = Dataset.FromRowData(new[] { "X1", "X2", "X3" }, listoflits);
59      Assert.AreEqual(3, ds.Columns);
60      Assert.AreEqual(5, ds.Rows);
61      Assert.IsTrue(ds.GetDoubleValues("X1").SequenceEqual(new double[] { 1, 2, 3, 1, 2 }));
62
63      var complexData = new List<IList>() {
64        new object[] { 1.0, new DateTime(2019, 1, 1), "a" },
65        new object[] { 2.0, new DateTime(2019, 1, 2), "b" },
66        new object[] { 3.0, new DateTime(2019, 1, 3), "c" },
67        new object[] { 4.0, new DateTime(2019, 1, 4), "d" },
68        new object[] { 5.0, new DateTime(2019, 1, 5), "e" },
69      };
70      ds = Dataset.FromRowData(new[] { "X1", "X2", "X3" }, complexData);
71      Assert.AreEqual(3, ds.Columns);
72      Assert.AreEqual(5, ds.Rows);
73      Assert.IsTrue(ds.GetDoubleValues("X1").SequenceEqual(new double[] { 1, 2, 3, 4, 5 }));
74      Assert.IsTrue(ds.GetDateTimeValues("X2").SequenceEqual(Enumerable.Range(1, 5).Select(d => new DateTime(2019, 1, d))));
75      Assert.IsTrue(ds.GetStringValues("X3").SequenceEqual(new string[] { "a", "b", "c", "d", "e" }));
76    }
77  }
78}
Note: See TracBrowser for help on using the repository browser.