Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Tests/HeuristicLab.PluginInfraStructure-3.3/TypeExtensionsTest.cs @ 9782

Last change on this file since 9782 was 9782, checked in by abeham, 11 years ago

#2088: Added test attributes to further tests

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