Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ProblemRefactoring/HeuristicLab.Tests/HeuristicLab.PluginInfraStructure-3.3/TypeExtensionsTest.cs @ 13422

Last change on this file since 13422 was 13422, checked in by mkommend, 8 years ago

#2521: Adapted type discovery and type selector to allow the creation of generic programmable problems.

File size: 4.1 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2015 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).IsAssignableTo(typeof(object)));
39      Assert.IsTrue(typeof(IntValue).IsAssignableTo(typeof(IItem)));
40      Assert.IsTrue(typeof(List<int>).IsAssignableTo(typeof(object)));
41
42      Assert.IsTrue(typeof(List<int>).IsAssignableTo(typeof(IList)));
43      Assert.IsTrue(typeof(List<>).IsAssignableTo(typeof(IList)));
44      Assert.IsFalse(typeof(NamedItemCollection<>).IsAssignableTo(typeof(ICollection<IItem>)));
45      Assert.IsFalse(typeof(NamedItemCollection<>).IsAssignableTo(typeof(ICollection<NamedItem>)));
46
47      //new tests     
48
49
50      Assert.IsTrue(typeof(List<IItem>).IsAssignableTo(typeof(IList<IItem>)));
51      Assert.IsFalse(typeof(IList<IntValue>).IsAssignableTo(typeof(IList<IItem>)));
52      Assert.IsTrue(typeof(List<IItem>).IsAssignableTo(typeof(IList<IItem>)));
53      Assert.IsFalse(typeof(ItemList<>).IsAssignableTo(typeof(IList<IItem>)));
54      Assert.IsFalse(typeof(ItemList<>).IsAssignableTo(typeof(List<IItem>)));
55
56      Assert.IsTrue(typeof(List<int>).IsAssignableTo(typeof(List<>)));
57      Assert.IsTrue(typeof(List<>).IsAssignableTo(typeof(IList<>)));
58      Assert.IsTrue(typeof(ItemList<>).IsAssignableTo(typeof(IList<>)));
59      Assert.IsTrue(typeof(NamedItemCollection<>).IsAssignableTo(typeof(IItemCollection<>)));
60      Assert.IsTrue(typeof(List<IntValue>).IsAssignableTo(typeof(IList<>)));
61    }
62
63    [TestMethod]
64    [TestCategory("General")]
65    [TestCategory("Essential")]
66    [TestProperty("Time", "short")]
67    public void BuildTypeTest() {
68      Assert.AreEqual(typeof(List<>).BuildType(typeof(List<>)), typeof(List<>));
69      Assert.AreEqual(typeof(List<int>).BuildType(typeof(List<>)), typeof(List<int>));
70      Assert.AreEqual(typeof(List<>).BuildType(typeof(List<int>)), typeof(List<int>));
71
72      Assert.AreEqual(typeof(ICollection<>).BuildType(typeof(List<>)), typeof(ICollection<>));
73      Assert.AreEqual(typeof(ICollection<int>).BuildType(typeof(List<>)), typeof(ICollection<int>));
74      Assert.AreEqual(typeof(ICollection<>).BuildType(typeof(List<int>)), typeof(ICollection<int>));
75
76      Assert.AreEqual(typeof(ItemCollection<>).BuildType(typeof(ICollection<int>)), null);
77      Assert.AreEqual(typeof(ItemCollection<>).BuildType(typeof(Dictionary<IItem, IItem>)), null);
78      Assert.AreEqual(typeof(ItemCollection<>).BuildType(typeof(ICollection<IItem>)), typeof(ItemCollection<IItem>));
79
80      Assert.AreEqual(typeof(FixedValueParameter<>).BuildType(typeof(ItemCollection<DataAnalysisProblemData>)), null);
81      Assert.AreEqual(typeof(IFixedValueParameter<>).BuildType(typeof(ItemCollection<DoubleValue>)), typeof(IFixedValueParameter<DoubleValue>));
82      Assert.AreEqual(typeof(IFixedValueParameter<>).BuildType(typeof(ItemCollection<IItem>)), typeof(IFixedValueParameter<IItem>));
83    }
84  }
85}
Note: See TracBrowser for help on using the repository browser.