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 FromPrimitiveToArray_CanBeConvertedReturnsFalse() { var typeFrom = FunnyType.PrimitiveOf(BaseFunnyType.Int32); var typeTo = FunnyType.ArrayOf(FunnyType.PrimitiveOf(BaseFunnyType.Int32)); Assert.IsFalse(typeFrom.CanBeConvertedTo(typeTo)); }
public void TwoFunTypesWithDifferentOutputs_Equals_ReturnsFalse() { var typeA = FunnyType.Fun(FunnyType.Int32, FunnyType.Text); var typeB = FunnyType.Fun(FunnyType.Bool, FunnyType.Text); Assert.IsFalse(typeA == typeB); }
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 TwoStructTypesWithSingleMemberAreEqual() { var t1 = FunnyType.StructOf("name", FunnyType.Text); var t2 = FunnyType.StructOf("name", FunnyType.Text); Assert.AreEqual(t1, t2); }
public void EmptyStructTypeAndSingleMemeberTypesAreNotEqual() { var t1 = FunnyType.StructOf("name", FunnyType.Text); var t2 = FunnyType.StructOf(); Assert.AreNotEqual(t1, t2); }
public void TwoEqualGenerics_Equals_ReturnsTrue() { var typeA = FunnyType.Generic(1); var typeB = FunnyType.Generic(1); Assert.AreEqual(typeA, typeB); }
public void TwoNotEqualArrayTypes_Equals_ReturnsFalse() { var typeA = FunnyType.ArrayOf(FunnyType.Int32); var typeB = FunnyType.ArrayOf(FunnyType.Real); Assert.IsFalse(typeA == typeB); }
public static FunnyType ReadType(this TokFlow flow) { var cur = flow.Current; var readType = ToFunnyType(cur); flow.MoveNext(); var lastPosition = cur.Finish; while (flow.IsCurrent(TokType.ArrOBr)) { if (flow.Current.Start != lastPosition) { throw FunParseException.ErrorStubToDo("unexpected space before []"); } flow.MoveNext(); lastPosition = flow.Current.Finish; if (!flow.MoveIf(TokType.ArrCBr)) { throw ErrorFactory.ArrTypeCbrMissed(new Interval(cur.Start, flow.Current.Start)); } readType = FunnyType.ArrayOf(readType); } return(readType); }
public void AssertFunnyType(string expr, FunnyType expected) { var flow = Tokenizer.ToFlow(expr); var actual = flow.ReadType(); Assert.AreEqual(expected, actual); }
public SliceGenericFunctionDefinition() : base(CoreFunNames.SliceName, FunnyType.ArrayOf(FunnyType.Generic(0)), FunnyType.ArrayOf(FunnyType.Generic(0)), FunnyType.Int32, FunnyType.Int32) { }
public MapFunction() : base("map", FunnyType.ArrayOf(FunnyType.Generic(1)), FunnyType.ArrayOf(FunnyType.Generic(0)), FunnyType.Fun(FunnyType.Generic(1), FunnyType.Generic(0))) { }
public SetGenericFunctionDefinition() : base("set", FunnyType.ArrayOf(FunnyType.Generic(0)), FunnyType.ArrayOf(FunnyType.Generic(0)), FunnyType.Int32, FunnyType.Generic(0)) { }
private Func <object, object> CreateBinarizerOrNull(FunnyType from) { switch (from.BaseType) { case BaseFunnyType.Char: return(o => ToBoolArray(new[] { (byte)(char)o })); case BaseFunnyType.Bool: return(o => new ImmutableFunArray(new [] { (bool)o })); case BaseFunnyType.UInt8: return(o => ToBoolArray(new[] { (byte)o })); case BaseFunnyType.UInt16: return(o => ToBoolArray(BitConverter.GetBytes((ushort)o))); case BaseFunnyType.UInt32: return(o => ToBoolArray(BitConverter.GetBytes((uint)o))); case BaseFunnyType.UInt64: return(o => ToBoolArray(BitConverter.GetBytes((long)o))); case BaseFunnyType.Int16: return(o => ToBoolArray(BitConverter.GetBytes((short)o))); case BaseFunnyType.Int32: return(o => ToBoolArray(BitConverter.GetBytes((int)o))); case BaseFunnyType.Int64: return(o => ToBoolArray(BitConverter.GetBytes((long)o))); case BaseFunnyType.Real: return(o => ToBoolArray(BitConverter.GetBytes((double)o))); } if (from.IsText) { return(o => ToBoolArray(Encoding.Unicode.GetBytes(((IFunArray)o).ToText()))); } return(null); }
public void TwoDifferentGenerics_Equals_ReturnsFalse() { var typeA = FunnyType.Generic(1); var typeB = FunnyType.Generic(2); Assert.AreNotEqual(typeA, typeB); }
public void TwoEqualArrayTypes_Equals_ReturnsTrue() { var typeA = FunnyType.ArrayOf(FunnyType.Int32); var typeB = FunnyType.ArrayOf(FunnyType.Int32); Assert.IsTrue(typeA == typeB); }
public void ArrayAndPrimitiveTypes_Equals_ReturnsFalse() { var typeA = FunnyType.ArrayOf(FunnyType.Int32); var typeB = FunnyType.Int32; Assert.IsFalse(typeA == typeB); }
public void TwoStructTypesWithNoMembersAreEqual() { var empty1 = FunnyType.StructOf(); var empty2 = FunnyType.StructOf(); Assert.AreEqual(empty1, empty2); }
public void TwoEqualPrimitiveTypes_Equals_ReturnsTrue() { var typeA = FunnyType.PrimitiveOf(BaseFunnyType.Int32); var typeB = FunnyType.PrimitiveOf(BaseFunnyType.Int32); Assert.IsTrue(typeA == typeB); }
public void TwoStructTypesWithSingleMemberOfDifferentNamesAreNotEqual() { var t1 = FunnyType.StructOf("name", FunnyType.Text); var t2 = FunnyType.StructOf("nick", FunnyType.Text); Assert.AreNotEqual(t1, t2); }
public void TwoNotEqualPrimitiveTypes_Equals_ReturnsFalse() { var typeA = FunnyType.PrimitiveOf(BaseFunnyType.Real); var typeB = FunnyType.PrimitiveOf(BaseFunnyType.Int32); Assert.IsFalse(typeA == typeB); }
public void TwoEqualFunTypes_Equals_ReturnsTrue() { var typeA = FunnyType.Fun(FunnyType.Bool, FunnyType.Int32); var typeB = FunnyType.Fun(FunnyType.Bool, FunnyType.Int32); Assert.IsTrue(typeA == typeB); }
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 TwoComplexHiOrderEqualFunTypes_Equals_ReturnsTrue() { var typeA = FunnyType.Fun( returnType: FunnyType.ArrayOf(FunnyType.Fun(FunnyType.Int32, FunnyType.Text)), inputTypes: new [] { FunnyType.ArrayOf(FunnyType.Anything), FunnyType.Fun( returnType: FunnyType.ArrayOf(FunnyType.Real), inputTypes: FunnyType.Fun( returnType: FunnyType.Fun( returnType: FunnyType.ArrayOf(FunnyType.Bool), inputTypes: FunnyType.Bool), inputTypes: FunnyType.Text)) }); var typeB = FunnyType.Fun( returnType: FunnyType.ArrayOf(FunnyType.Fun(FunnyType.Int32, FunnyType.Text)), inputTypes: new [] { FunnyType.ArrayOf(FunnyType.Anything), FunnyType.Fun( returnType: FunnyType.ArrayOf(FunnyType.Real), inputTypes: FunnyType.Fun( returnType: FunnyType.Fun( returnType: FunnyType.ArrayOf(FunnyType.Bool), inputTypes: FunnyType.Bool), inputTypes: FunnyType.Text)) }); Assert.IsTrue(typeA == typeB); }
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 SingleMultiDimVariable_OutputEqualsTwoInputs() { var x = new int[3][]; x[0] = new[] { 1, 2 }; x[1] = new[] { 3, 4 }; x[2] = new[] { 5 }; var expectedType = FunnyType.ArrayOf(FunnyType.ArrayOf(FunnyType.Int32)); var expectedOutput = new int[6][]; expectedOutput[0] = new[] { 1, 2 }; expectedOutput[1] = new[] { 3, 4 }; expectedOutput[2] = new[] { 5 }; expectedOutput[3] = new[] { 1, 2 }; expectedOutput[4] = new[] { 3, 4 }; expectedOutput[5] = new[] { 5 }; var expression = "x:int[][]\r y= x.concat(x)"; var res = expression.Calc("x", x).Get("y"); Assert.IsInstanceOf <int[][]>(res); AssertMultiDimentionalEquals(res as int[][], expectedOutput); }
public static GenericUserFunction Create( TypeInferenceResults typeInferenceResults, UserFunctionDefinitionSyntaxNode syntaxNode, IFunctionDictionary dictionary) { var ticGenerics = typeInferenceResults.Generics; var langConstrains = new GenericConstrains[ticGenerics.Length]; for (int i = 0; i < ticGenerics.Length; i++) { var ticConstrains = ticGenerics[i]; langConstrains[i] = GenericConstrains.FromTicConstrains(ticConstrains); } var ticFunName = syntaxNode.Id + "'" + syntaxNode.Args.Count; var ticSignature = (StateFun)typeInferenceResults.GetVariableType(ticFunName); var signatureConverter = TicTypesConverter.GenericSignatureConverter(ticGenerics); var argTypes = new FunnyType[ticSignature.ArgNodes.Length]; for (var i = 0; i < ticSignature.ArgNodes.Length; i++) { argTypes[i] = signatureConverter.Convert(ticSignature.ArgNodes[i].State); } var retType = signatureConverter.Convert(ticSignature.ReturnType); #if DEBUG TraceLog.WriteLine($"CREATE GENERIC FUN {syntaxNode.Id}({string.Join(",",argTypes)}):{retType}"); TraceLog.WriteLine($" ...where {string.Join(", ", langConstrains)}"); #endif var function = new GenericUserFunction(typeInferenceResults, syntaxNode, dictionary, langConstrains, retType, argTypes); return(function); }
public BitShiftRightFunction() : base(CoreFunNames.BitShiftRight, GenericConstrains.Integers3264, FunnyType.Generic(0), FunnyType.Generic(0), FunnyType.UInt8) { }
public StructInitExpressionNode(string[] fieldNames, IExpressionNode[] elements, Interval interval, FunnyType type) { Type = type; _fieldNames = fieldNames; _elements = elements; Interval = interval; }
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);