Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Tests/HeuristicLab.PluginInfraStructure-3.3/TypeDiscoveryTest.cs @ 9764

Last change on this file since 9764 was 9764, checked in by abeham, 9 years ago

#2088: Renamed namespaces (removed _33 and _34 postfixes)

File size: 4.4 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2013 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.Collections;
23using System.Collections.Generic;
24using System.Linq;
25using HeuristicLab.Core;
26using HeuristicLab.Data;
27using HeuristicLab.Parameters;
28using HeuristicLab.Problems.DataAnalysis;
29using HeuristicLab.Tests;
30using Microsoft.VisualStudio.TestTools.UnitTesting;
31
32namespace HeuristicLab.PluginInfrastructure.Tests {
33  /// <summary>
34  /// Summary description for TypeDiscoveryTest
35  /// </summary>
36  [TestClass]
37  public class TypeDiscoveryTest {
38    public TypeDiscoveryTest() { }
39
40    private TestContext testContextInstance;
41
42    /// <summary>
43    ///Gets or sets the test context which provides
44    ///information about and functionality for the current test run.
45    ///</summary>
46    public TestContext TestContext {
47      get { return testContextInstance; }
48      set { testContextInstance = value; }
49    }
50
51    public static void MyClassInitialize(TestContext testContext) {
52      PluginLoader.Assemblies.Any();
53    }
54
55    [TestMethod]
56    public void IsSubTypeOfTest() {
57      Assert.IsTrue(typeof(int).IsSubTypeOf(typeof(object)));
58      Assert.IsTrue(typeof(IntValue).IsSubTypeOf(typeof(IItem)));
59      Assert.IsTrue(typeof(List<int>).IsSubTypeOf(typeof(object)));
60
61      Assert.IsTrue(typeof(List<int>).IsSubTypeOf(typeof(IList)));
62      Assert.IsTrue(typeof(List<>).IsSubTypeOf(typeof(IList)));
63      Assert.IsFalse(typeof(NamedItemCollection<>).IsSubTypeOf(typeof(ICollection<IItem>)));
64      Assert.IsFalse(typeof(NamedItemCollection<>).IsSubTypeOf(typeof(ICollection<NamedItem>)));
65
66
67      Assert.IsTrue(typeof(List<IItem>).IsSubTypeOf(typeof(IList<IItem>)));
68      Assert.IsFalse(typeof(IList<IntValue>).IsSubTypeOf(typeof(IList<IItem>)));
69      Assert.IsTrue(typeof(List<IItem>).IsSubTypeOf(typeof(IList<IItem>)));
70      Assert.IsFalse(typeof(ItemList<>).IsSubTypeOf(typeof(IList<IItem>)));
71      Assert.IsFalse(typeof(ItemList<>).IsSubTypeOf(typeof(List<IItem>)));
72
73      Assert.IsFalse(typeof(List<int>).IsSubTypeOf(typeof(List<>)));
74      Assert.IsTrue(typeof(List<>).IsSubTypeOf(typeof(IList<>)));
75      Assert.IsTrue(typeof(ItemList<>).IsSubTypeOf(typeof(IList<>)));
76      Assert.IsTrue(typeof(NamedItemCollection<>).IsSubTypeOf(typeof(IItemCollection<>)));
77      Assert.IsFalse(typeof(List<IntValue>).IsSubTypeOf(typeof(IList<>)));
78    }
79
80    [TestMethod]
81    public void BuildTypeTest() {
82      Assert.AreEqual(typeof(List<>).BuildType(typeof(List<>)), typeof(List<>));
83      Assert.AreEqual(typeof(List<int>).BuildType(typeof(List<>)), typeof(List<int>));
84      Assert.AreEqual(typeof(List<>).BuildType(typeof(List<int>)), typeof(List<int>));
85
86      Assert.AreEqual(typeof(ICollection<>).BuildType(typeof(List<>)), typeof(ICollection<>));
87      Assert.AreEqual(typeof(ICollection<int>).BuildType(typeof(List<>)), typeof(ICollection<int>));
88      Assert.AreEqual(typeof(ICollection<>).BuildType(typeof(List<int>)), typeof(ICollection<int>));
89
90      Assert.AreEqual(typeof(ItemCollection<>).BuildType(typeof(ICollection<int>)), null);
91      Assert.AreEqual(typeof(ItemCollection<>).BuildType(typeof(Dictionary<IItem, IItem>)), null);
92      Assert.AreEqual(typeof(ItemCollection<>).BuildType(typeof(ICollection<IItem>)), typeof(ItemCollection<IItem>));
93
94      Assert.AreEqual(typeof(FixedValueParameter<>).BuildType(typeof(ItemCollection<DataAnalysisProblemData>)), null);
95      Assert.AreEqual(typeof(IFixedValueParameter<>).BuildType(typeof(ItemCollection<DoubleValue>)), typeof(IFixedValueParameter<DoubleValue>));
96      Assert.AreEqual(typeof(IFixedValueParameter<>).BuildType(typeof(ItemCollection<IItem>)), typeof(IFixedValueParameter<IItem>));
97    }
98  }
99}
Note: See TracBrowser for help on using the repository browser.