Beispiel #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);
        }
Beispiel #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));
        }
Beispiel #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)));
        }
Beispiel #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)));
        }
Beispiel #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);
            }
        }
Beispiel #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());
        }
Beispiel #7
0
 public Function(MapType type)
 {
     this.type = type;
 }
Beispiel #8
0
 public ConstructorFunction(MapType type)
 {
     this.type = type;
 }