示例#1
0
        public void CreateMapTypeIntegerToInteger()
        {
            var type = new MapType(IntegerType.Instance, IntegerType.Instance);

            Assert.AreSame(IntegerType.Instance, type.FromType);
            Assert.AreSame(IntegerType.Instance, type.ToType);
        }
示例#2
0
        public void MatchFunction()
        {
            var type = new MapType(IntegerType.Instance, IntegerType.Instance);
            var func = new Function(type);
            var func2 = new Function(type);

            Assert.IsTrue(func.Match(func, null));
            Assert.IsFalse(func.Match(null, null));
            Assert.IsFalse(func.Match(func2, null));
        }
示例#3
0
        public void ApplyExpression()
        {
            var type = new MapType(IntegerType.Instance, IntegerType.Instance);
            var func = new Function(type);

            Assert.AreSame(func, func.Reduce());
            Assert.AreSame(type, func.Type);

            func.Map(new IntegerExpression(1), new IntegerExpression(2));

            Assert.AreEqual(new IntegerExpression(2), func.Apply(new IntegerExpression(1)));
        }
示例#4
0
        public void Match()
        {
            var type = new MapType(IntegerType.Instance, DoubleType.Instance);

            Assert.IsFalse(type.Match(null));
            Assert.IsFalse(type.Match(IntegerType.Instance));
            Assert.IsFalse(type.Match(DoubleType.Instance));

            Assert.IsFalse(type.Match(new MapType(DoubleType.Instance, DoubleType.Instance)));
            Assert.IsFalse(type.Match(new MapType(IntegerType.Instance, IntegerType.Instance)));

            Assert.IsTrue(type.Match(new MapType(IntegerType.Instance, DoubleType.Instance)));
        }
示例#5
0
        public void MapInvalidToExpression()
        {
            var type = new MapType(IntegerType.Instance, IntegerType.Instance);
            var func = new Function(type);

            try
            {
                func.Map(new IntegerExpression(1), new DoubleExpression(1.2));
                Assert.Fail();
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(InvalidOperationException));
                Assert.AreEqual("Non compatible type", ex.Message);
            }
        }
示例#6
0
        public void Equality()
        {
            var type1 = new MapType(IntegerType.Instance, IntegerType.Instance);
            var type2 = new MapType(IntegerType.Instance, DoubleType.Instance);
            var type3 = new MapType(IntegerType.Instance, IntegerType.Instance);

            Assert.IsFalse(type1.Equals(null));
            Assert.IsFalse(type1.Equals(42));
            Assert.IsFalse(type1.Equals("foo"));

            Assert.IsFalse(type1.Equals(type2));
            Assert.IsFalse(type2.Equals(type1));

            Assert.IsTrue(type1.Equals(type1));
            Assert.IsTrue(type1.Equals(type3));
            Assert.IsTrue(type3.Equals(type1));
            Assert.AreEqual(type1.GetHashCode(), type3.GetHashCode());
        }
示例#7
0
文件: Function.cs 项目: ajlopez/Husky
 public Function(MapType type)
 {
     this.type = type;
 }
示例#8
0
 public ConstructorFunction(MapType type)
 {
     this.type = type;
 }