#region License Information
/* HeuristicLab
* Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using System.Collections;
using System.Collections.Generic;
using HeuristicLab.Core;
using HeuristicLab.Data;
using HeuristicLab.Parameters;
using HeuristicLab.Problems.DataAnalysis;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace HeuristicLab.PluginInfrastructure.Tests {
///
/// Summary description for TypeDiscoveryTest
///
[TestClass]
public class TypeExtensionsTest {
[TestMethod]
[TestCategory("General")]
[TestCategory("Essential")]
[TestProperty("Time", "short")]
public void IsSubTypeOfTest() {
Assert.IsTrue(typeof(int).IsSubTypeOf(typeof(object)));
Assert.IsTrue(typeof(IntValue).IsSubTypeOf(typeof(IItem)));
Assert.IsTrue(typeof(List).IsSubTypeOf(typeof(object)));
Assert.IsTrue(typeof(List).IsSubTypeOf(typeof(IList)));
Assert.IsTrue(typeof(List<>).IsSubTypeOf(typeof(IList)));
Assert.IsFalse(typeof(NamedItemCollection<>).IsSubTypeOf(typeof(ICollection)));
Assert.IsFalse(typeof(NamedItemCollection<>).IsSubTypeOf(typeof(ICollection)));
Assert.IsTrue(typeof(List).IsSubTypeOf(typeof(IList)));
Assert.IsFalse(typeof(IList).IsSubTypeOf(typeof(IList)));
Assert.IsTrue(typeof(List).IsSubTypeOf(typeof(IList)));
Assert.IsFalse(typeof(ItemList<>).IsSubTypeOf(typeof(IList)));
Assert.IsFalse(typeof(ItemList<>).IsSubTypeOf(typeof(List)));
Assert.IsFalse(typeof(List).IsSubTypeOf(typeof(List<>)));
Assert.IsTrue(typeof(List<>).IsSubTypeOf(typeof(IList<>)));
Assert.IsTrue(typeof(ItemList<>).IsSubTypeOf(typeof(IList<>)));
Assert.IsTrue(typeof(NamedItemCollection<>).IsSubTypeOf(typeof(IItemCollection<>)));
Assert.IsFalse(typeof(List).IsSubTypeOf(typeof(IList<>)));
}
[TestMethod]
[TestCategory("General")]
[TestCategory("Essential")]
[TestProperty("Time", "short")]
public void BuildTypeTest() {
Assert.AreEqual(typeof(List<>).BuildType(typeof(List<>)), typeof(List<>));
Assert.AreEqual(typeof(List).BuildType(typeof(List<>)), typeof(List));
Assert.AreEqual(typeof(List<>).BuildType(typeof(List)), typeof(List));
Assert.AreEqual(typeof(ICollection<>).BuildType(typeof(List<>)), typeof(ICollection<>));
Assert.AreEqual(typeof(ICollection).BuildType(typeof(List<>)), typeof(ICollection));
Assert.AreEqual(typeof(ICollection<>).BuildType(typeof(List)), typeof(ICollection));
Assert.AreEqual(typeof(ItemCollection<>).BuildType(typeof(ICollection)), null);
Assert.AreEqual(typeof(ItemCollection<>).BuildType(typeof(Dictionary)), null);
Assert.AreEqual(typeof(ItemCollection<>).BuildType(typeof(ICollection)), typeof(ItemCollection));
Assert.AreEqual(typeof(FixedValueParameter<>).BuildType(typeof(ItemCollection)), null);
Assert.AreEqual(typeof(IFixedValueParameter<>).BuildType(typeof(ItemCollection)), typeof(IFixedValueParameter));
Assert.AreEqual(typeof(IFixedValueParameter<>).BuildType(typeof(ItemCollection)), typeof(IFixedValueParameter));
}
}
}