Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 17547 was 17181, checked in by swagner, 5 years ago

#2875: Merged r17180 from trunk to stable

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