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)); }
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))))); }
public void TextType_CanBeConvertedFrom(BaseFunnyType from, bool canBeConverted) { var typeTo = FunnyType.Text; var typeFrom = FunnyType.PrimitiveOf(from); Assert.AreEqual(canBeConverted, typeFrom.CanBeConvertedTo(typeTo)); }
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)); }
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);
// [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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }); }
public void SingleEquations_Parsing_OutputTypesCalculateCorrect(string expr, BaseFunnyType type) => Assert.AreEqual(type, expr.Build().Outputs.Single().Type.BaseType);
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); }
public void ReadType_PrimitiveTypes(string expr, BaseFunnyType expected) => AssertFunnyType(expr, FunnyType.PrimitiveOf(expected));
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); }
public static Type GetClrType(this BaseFunnyType funnyType) => FunToClrTypesMap[(int)funnyType];
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); }
public void IntegersBitwiseInvertTest(string inputTypes, BaseFunnyType expectedOutputType) { var runtime = $"a:{inputTypes}; b:{inputTypes}; c= ~a".Build(); Assert.AreEqual(expectedOutputType, runtime.Outputs.Single().Type.BaseType); }
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); }
//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); }
public void ReadTwinArrayType(string expr, BaseFunnyType elementType) => AssertFunnyType(expr, FunnyType.ArrayOf(FunnyType.ArrayOf(FunnyType.PrimitiveOf(elementType))));