Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 8757 was 8757, checked in by gkronber, 12 years ago

#1329 integrated Scheduling branch into trunk

File size: 3.6 KB
Line 
1using System.Collections;
2using System.Collections.Generic;
3using System.Linq;
4using HeuristicLab.Core;
5using HeuristicLab.Data;
6using HeuristicLab.Parameters;
7using HeuristicLab.Problems.DataAnalysis;
8using HeuristicLab_33.Tests;
9using Microsoft.VisualStudio.TestTools.UnitTesting;
10
11namespace HeuristicLab.PluginInfrastructure.Tests {
12  /// <summary>
13  /// Summary description for TypeDiscoveryTest
14  /// </summary>
15  [TestClass]
16  public class TypeDiscoveryTest {
17    public TypeDiscoveryTest() { }
18
19    private TestContext testContextInstance;
20
21    /// <summary>
22    ///Gets or sets the test context which provides
23    ///information about and functionality for the current test run.
24    ///</summary>
25    public TestContext TestContext {
26      get { return testContextInstance; }
27      set { testContextInstance = value; }
28    }
29
30    public static void MyClassInitialize(TestContext testContext) {
31      PluginLoader.Assemblies.Any();
32    }
33
34    [TestMethod]
35    public void IsSubTypeOfTest() {
36      Assert.IsTrue(typeof(int).IsSubTypeOf(typeof(object)));
37      Assert.IsTrue(typeof(IntValue).IsSubTypeOf(typeof(IItem)));
38      Assert.IsTrue(typeof(List<int>).IsSubTypeOf(typeof(object)));
39
40      Assert.IsTrue(typeof(List<int>).IsSubTypeOf(typeof(IList)));
41      Assert.IsTrue(typeof(List<>).IsSubTypeOf(typeof(IList)));
42      Assert.IsFalse(typeof(NamedItemCollection<>).IsSubTypeOf(typeof(ICollection<IItem>)));
43      Assert.IsFalse(typeof(NamedItemCollection<>).IsSubTypeOf(typeof(ICollection<NamedItem>)));
44
45
46      Assert.IsTrue(typeof(List<IItem>).IsSubTypeOf(typeof(IList<IItem>)));
47      Assert.IsFalse(typeof(IList<IntValue>).IsSubTypeOf(typeof(IList<IItem>)));
48      Assert.IsTrue(typeof(List<IItem>).IsSubTypeOf(typeof(IList<IItem>)));
49      Assert.IsFalse(typeof(ItemList<>).IsSubTypeOf(typeof(IList<IItem>)));
50      Assert.IsFalse(typeof(ItemList<>).IsSubTypeOf(typeof(List<IItem>)));
51
52      Assert.IsFalse(typeof(List<int>).IsSubTypeOf(typeof(List<>)));
53      Assert.IsTrue(typeof(List<>).IsSubTypeOf(typeof(IList<>)));
54      Assert.IsTrue(typeof(ItemList<>).IsSubTypeOf(typeof(IList<>)));
55      Assert.IsTrue(typeof(NamedItemCollection<>).IsSubTypeOf(typeof(IItemCollection<>)));
56      Assert.IsFalse(typeof(List<IntValue>).IsSubTypeOf(typeof(IList<>)));
57    }
58
59    [TestMethod]
60    public void BuildTypeTest() {
61      Assert.AreEqual(typeof(List<>).BuildType(typeof(List<>)), typeof(List<>));
62      Assert.AreEqual(typeof(List<int>).BuildType(typeof(List<>)), typeof(List<int>));
63      Assert.AreEqual(typeof(List<>).BuildType(typeof(List<int>)), typeof(List<int>));
64
65      Assert.AreEqual(typeof(ICollection<>).BuildType(typeof(List<>)), typeof(ICollection<>));
66      Assert.AreEqual(typeof(ICollection<int>).BuildType(typeof(List<>)), typeof(ICollection<int>));
67      Assert.AreEqual(typeof(ICollection<>).BuildType(typeof(List<int>)), typeof(ICollection<int>));
68
69      Assert.AreEqual(typeof(ItemCollection<>).BuildType(typeof(ICollection<int>)), null);
70      Assert.AreEqual(typeof(ItemCollection<>).BuildType(typeof(Dictionary<IItem, IItem>)), null);
71      Assert.AreEqual(typeof(ItemCollection<>).BuildType(typeof(ICollection<IItem>)), typeof(ItemCollection<IItem>));
72
73      Assert.AreEqual(typeof(FixedValueParameter<>).BuildType(typeof(ItemCollection<DataAnalysisProblemData>)), null);
74      Assert.AreEqual(typeof(IFixedValueParameter<>).BuildType(typeof(ItemCollection<DoubleValue>)), typeof(IFixedValueParameter<DoubleValue>));
75      Assert.AreEqual(typeof(IFixedValueParameter<>).BuildType(typeof(ItemCollection<IItem>)), typeof(IFixedValueParameter<IItem>));
76    }
77  }
78}
Note: See TracBrowser for help on using the repository browser.