Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.Tests/HeuristicLab.PluginInfraStructure-3.3/TypeExtensionsTest.cs @ 10449

Last change on this file since 10449 was 9885, checked in by mkommend, 11 years ago

#2088: Merged all changesets regarding the unit test restructuring in the stable branch.

File size: 4.1 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 HeuristicLab.Core;
25using HeuristicLab.Data;
26using HeuristicLab.Parameters;
27using HeuristicLab.Problems.DataAnalysis;
28using Microsoft.VisualStudio.TestTools.UnitTesting;
29
30namespace HeuristicLab.PluginInfrastructure.Tests {
31  /// <summary>
32  /// Summary description for TypeDiscoveryTest
33  /// </summary>
34  [TestClass]
35  public class TypeExtensionsTest {
36    [TestMethod]
37    [TestCategory("General")]
38    [TestCategory("Essential")]
39    [TestProperty("Time", "short")]
40    public void IsSubTypeOfTest() {
41      Assert.IsTrue(typeof(int).IsSubTypeOf(typeof(object)));
42      Assert.IsTrue(typeof(IntValue).IsSubTypeOf(typeof(IItem)));
43      Assert.IsTrue(typeof(List<int>).IsSubTypeOf(typeof(object)));
44
45      Assert.IsTrue(typeof(List<int>).IsSubTypeOf(typeof(IList)));
46      Assert.IsTrue(typeof(List<>).IsSubTypeOf(typeof(IList)));
47      Assert.IsFalse(typeof(NamedItemCollection<>).IsSubTypeOf(typeof(ICollection<IItem>)));
48      Assert.IsFalse(typeof(NamedItemCollection<>).IsSubTypeOf(typeof(ICollection<NamedItem>)));
49
50
51      Assert.IsTrue(typeof(List<IItem>).IsSubTypeOf(typeof(IList<IItem>)));
52      Assert.IsFalse(typeof(IList<IntValue>).IsSubTypeOf(typeof(IList<IItem>)));
53      Assert.IsTrue(typeof(List<IItem>).IsSubTypeOf(typeof(IList<IItem>)));
54      Assert.IsFalse(typeof(ItemList<>).IsSubTypeOf(typeof(IList<IItem>)));
55      Assert.IsFalse(typeof(ItemList<>).IsSubTypeOf(typeof(List<IItem>)));
56
57      Assert.IsFalse(typeof(List<int>).IsSubTypeOf(typeof(List<>)));
58      Assert.IsTrue(typeof(List<>).IsSubTypeOf(typeof(IList<>)));
59      Assert.IsTrue(typeof(ItemList<>).IsSubTypeOf(typeof(IList<>)));
60      Assert.IsTrue(typeof(NamedItemCollection<>).IsSubTypeOf(typeof(IItemCollection<>)));
61      Assert.IsFalse(typeof(List<IntValue>).IsSubTypeOf(typeof(IList<>)));
62    }
63
64    [TestMethod]
65    [TestCategory("General")]
66    [TestCategory("Essential")]
67    [TestProperty("Time", "short")]
68    public void BuildTypeTest() {
69      Assert.AreEqual(typeof(List<>).BuildType(typeof(List<>)), typeof(List<>));
70      Assert.AreEqual(typeof(List<int>).BuildType(typeof(List<>)), typeof(List<int>));
71      Assert.AreEqual(typeof(List<>).BuildType(typeof(List<int>)), typeof(List<int>));
72
73      Assert.AreEqual(typeof(ICollection<>).BuildType(typeof(List<>)), typeof(ICollection<>));
74      Assert.AreEqual(typeof(ICollection<int>).BuildType(typeof(List<>)), typeof(ICollection<int>));
75      Assert.AreEqual(typeof(ICollection<>).BuildType(typeof(List<int>)), typeof(ICollection<int>));
76
77      Assert.AreEqual(typeof(ItemCollection<>).BuildType(typeof(ICollection<int>)), null);
78      Assert.AreEqual(typeof(ItemCollection<>).BuildType(typeof(Dictionary<IItem, IItem>)), null);
79      Assert.AreEqual(typeof(ItemCollection<>).BuildType(typeof(ICollection<IItem>)), typeof(ItemCollection<IItem>));
80
81      Assert.AreEqual(typeof(FixedValueParameter<>).BuildType(typeof(ItemCollection<DataAnalysisProblemData>)), null);
82      Assert.AreEqual(typeof(IFixedValueParameter<>).BuildType(typeof(ItemCollection<DoubleValue>)), typeof(IFixedValueParameter<DoubleValue>));
83      Assert.AreEqual(typeof(IFixedValueParameter<>).BuildType(typeof(ItemCollection<IItem>)), typeof(IFixedValueParameter<IItem>));
84    }
85  }
86}
Note: See TracBrowser for help on using the repository browser.