示例#1
0
        public void FromArrayOfInt32ToPrimitive_CanBeConvertedReturnsFalse(BaseFunnyType to, bool canBeConverted)
        {
            var typeFrom = FunnyType.ArrayOf(FunnyType.PrimitiveOf(BaseFunnyType.Int32));
            var typeTo   = FunnyType.PrimitiveOf(to);

            Assert.AreEqual(canBeConverted, typeFrom.CanBeConvertedTo(typeTo));
        }
示例#2
0
        public void OutputEqualsInputArray(string type, object expected, BaseFunnyType arrayType)
        {
            var res = $"x:{type}\r  y = x".Calc("x", expected);

            res.AssertReturns(expected);
            res.AssertResultIs(("y", GetClrType(FunnyType.ArrayOf(FunnyType.PrimitiveOf(arrayType)))));
        }
示例#3
0
        public void TextType_CanBeConvertedFrom(BaseFunnyType from, bool canBeConverted)
        {
            var typeTo   = FunnyType.Text;
            var typeFrom = FunnyType.PrimitiveOf(from);

            Assert.AreEqual(canBeConverted, typeFrom.CanBeConvertedTo(typeTo));
        }
示例#4
0
        public void ArrayTypes_CanBeConverted(BaseFunnyType from, BaseFunnyType to, bool canBeConverted)
        {
            var typeFrom = FunnyType.ArrayOf(FunnyType.PrimitiveOf(from));
            var typeTo   = FunnyType.ArrayOf(FunnyType.PrimitiveOf(to));

            Assert.AreEqual(canBeConverted, typeFrom.CanBeConvertedTo(typeTo));
        }
示例#5
0
 public void OutputVarablesListIsCorrect(string expr, string output, BaseFunnyType type) =>
 CollectionAssert.AreEquivalent(
     new[] { new VarInfo(
                 isOutput: true,
                 type: FunnyType.PrimitiveOf(type),
                 name: output,
                 isStrictTyped: false) },
     expr.Build().Outputs);
示例#6
0
        //  [TestCase("y = 'hi '.strConcat(u) #text", BaseVarType.Text)]
        public void Single_Equation_OutputTypeTest(string expression, BaseFunnyType primitiveType)
        {
            var runtime = expression.Build();

            Assert.AreEqual(1, runtime.Outputs.Length);
            var output = runtime.Outputs[0];

            Assert.AreEqual(primitiveType, output.Type.BaseType);
        }
示例#7
0
        public void ConvertPrimitiveType(object primitiveValue, BaseFunnyType expectedTypeName)
        {
            var clrType   = primitiveValue.GetType();
            var converter = FunnyTypeConverters.GetOutputConverter(clrType);

            Assert.AreEqual(expectedTypeName, converter.FunnyType.BaseType);
            var convertedValue = converter.ToClrObject(primitiveValue);

            Assert.AreEqual(primitiveValue, convertedValue);
        }
示例#8
0
        public void ConvertPrimitiveTypeArrays(object primitiveValue, BaseFunnyType expectedTypeName)
        {
            var clrType   = primitiveValue.GetType();
            var converter = FunnyTypeConverters.GetInputConverter(clrType);

            Assert.AreEqual(FunnyType.ArrayOf(FunnyType.PrimitiveOf(expectedTypeName)), converter.FunnyType);
            var convertedValue = converter.ToFunObject(primitiveValue);

            Assert.AreEqual(primitiveValue, convertedValue);
        }
示例#9
0
        public void TwinEquations_Runtime_OutputTypesCalculateCorrect(string expr, BaseFunnyType ytype, BaseFunnyType ztype)
        {
            var res = expr.Calc();
            var y   = res.Get("y");

            Assert.AreEqual(y.GetType(), FunnyTypeConverters.GetOutputConverter(FunnyType.PrimitiveOf(ytype)).ClrType);
            var z = res.Get("z");

            Assert.AreEqual(z.GetType(), FunnyTypeConverters.GetOutputConverter(FunnyType.PrimitiveOf(ztype)).ClrType);
        }
示例#10
0
        public void ConvertPrimitiveTypeArrays(object primitiveValue, BaseFunnyType expectedTypeName)
        {
            var clrType   = primitiveValue.GetType();
            var converter = FunnyTypeConverters.GetOutputConverter(clrType);

            Assert.AreEqual(FunnyType.ArrayOf(FunnyType.PrimitiveOf(expectedTypeName)), converter.FunnyType);
            var convertedValue = converter.ToClrObject(
                new ImmutableFunArray(primitiveValue as Array, FunnyType.PrimitiveOf(expectedTypeName)));

            Assert.AreEqual(primitiveValue, convertedValue);
        }
示例#11
0
        public void GetRnd_ArgAreIncostistent_ReturnsNull(
            BaseFunnyType returnType, BaseFunnyType firstArg, BaseFunnyType secondArg)
        {
            var rpt      = new GetRandomElementFuncDefinition();
            var function = rpt.CreateConcreteOrNull(
                FunnyType.PrimitiveOf(returnType),
                FunnyType.PrimitiveOf(firstArg),
                FunnyType.PrimitiveOf(secondArg));

            Assert.IsNull(function);
        }
示例#12
0
        public void ConvertPrimitives(object from, object expected, BaseFunnyType typeFrom, BaseFunnyType typeTo)
        {
            Assert.IsTrue(VarTypeConverter.CanBeConverted(
                              @from: FunnyType.PrimitiveOf(typeFrom),
                              to: FunnyType.PrimitiveOf(typeTo)));
            var converter = VarTypeConverter.GetConverterOrNull(
                FunnyType.PrimitiveOf(typeFrom),
                FunnyType.PrimitiveOf(typeTo));
            var converted = converter(from);

            Assert.AreEqual(converted, expected);
        }
示例#13
0
        public void GetRnd_GenericEqualsOutputType(
            BaseFunnyType returnType, BaseFunnyType firstArg, BaseFunnyType secondArg)
        {
            var rpt      = new GetRandomElementFuncDefinition();
            var function = rpt.CreateConcreteOrNull(
                FunnyType.PrimitiveOf(returnType),
                FunnyType.PrimitiveOf(firstArg),
                FunnyType.PrimitiveOf(secondArg));
            var generic = FunnyType.PrimitiveOf(returnType);

            Assert.IsNotNull(function);
            Assert.Multiple(() =>
            {
                Assert.AreEqual(generic, function.ReturnType);
                CollectionAssert.AreEquivalent(new[] { generic, generic }, function.ArgTypes);
            });
        }
示例#14
0
 public void SingleEquations_Parsing_OutputTypesCalculateCorrect(string expr, BaseFunnyType type) =>
 Assert.AreEqual(type, expr.Build().Outputs.Single().Type.BaseType);
示例#15
0
 public void ToConstant_NumberConstant_ParsesWell(string value, object expectedVal, BaseFunnyType expectedType)
 {
     var(obj, type) = TokenHelper.ToConstant(value);
     Assert.AreEqual(expectedVal, obj);
     Assert.AreEqual(expectedType, type.BaseType);
 }
示例#16
0
 public void ReadType_PrimitiveTypes(string expr, BaseFunnyType expected) =>
 AssertFunnyType(expr, FunnyType.PrimitiveOf(expected));
示例#17
0
        public void OutputType_checkInputTest(string expression, string variable, BaseFunnyType expectedType)
        {
            var runtime = expression.Build();

            Assert.AreEqual(expectedType, runtime.Inputs.Single(o => o.Name == variable).Type.BaseType);
        }
示例#18
0
文件: TypeHelper.cs 项目: tmteam/NFun
 public static Type GetClrType(this BaseFunnyType funnyType) => FunToClrTypesMap[(int)funnyType];
示例#19
0
        public void RemainsOfTwoIntegersTest(string inputTypes, BaseFunnyType expectedOutputType)
        {
            var runtime = $"a:{inputTypes}; b:{inputTypes}; y = a .rema(b)".Build();

            Assert.AreEqual(expectedOutputType, runtime.Outputs.Single(o => o.Name == "y").Type.BaseType);
        }
示例#20
0
        public void IntegersBitwiseInvertTest(string inputTypes, BaseFunnyType expectedOutputType)
        {
            var runtime = $"a:{inputTypes}; b:{inputTypes}; c= ~a".Build();

            Assert.AreEqual(expectedOutputType, runtime.Outputs.Single().Type.BaseType);
        }
示例#21
0
        public void IntegersBitwiseOperatorTest(string inputTypes, string function, BaseFunnyType expectedOutputType)
        {
            var runtime = $"a:{inputTypes}; b:{inputTypes}; c=a{function}b;".Build();

            Assert.AreEqual(expectedOutputType, runtime.Outputs.Single().Type.BaseType);
        }
示例#22
0
        //todo
        //[TestCase(
        //    @"div12(x) = 2600/x
        //    supsum(n) = [1..n].map(div12).sum()
        //    y = [1..20].map(supsum).sum().round()", BaseVarType.Int32)]
        public void SingleEquation_Runtime_OutputTypeCalculatesCorrect(string expr, BaseFunnyType type)
        {
            var clrtype = FunnyTypeConverters.GetOutputConverter(FunnyType.PrimitiveOf(type)).ClrType;

            expr.Calc().AssertResultIs(clrtype);
        }
示例#23
0
 public void ReadTwinArrayType(string expr, BaseFunnyType elementType) =>
 AssertFunnyType(expr, FunnyType.ArrayOf(FunnyType.ArrayOf(FunnyType.PrimitiveOf(elementType))));