public void GetOutputStructure_CalcComponentExpr_DataStructure(string keyword) { IExpression calcExpr = ModelResolvers.ExprResolver(); IExpression compExpr = ModelResolvers.ExprResolver(); compExpr.ExpressionText = "component"; compExpr.OperatorDefinition = ModelResolvers.OperatorResolver("comp"); calcExpr.OperatorDefinition = ModelResolvers.OperatorResolver("calcExpr"); calcExpr.OperatorDefinition.Keyword = keyword; calcExpr.AddOperand("ds_1", compExpr); ComponentType compType; switch (keyword) { case "identifier": compType = ComponentType.Identifier; break; case "measure": compType = ComponentType.Measure; break; case "attribute": compType = ComponentType.NonViralAttribute; break; case "viral attribute": compType = ComponentType.ViralAttribute; break; default: throw new ArgumentOutOfRangeException("keyword"); } IDataStructure dataStructure = compExpr.OperatorDefinition.GetOutputStructure(compExpr); Assert.True(dataStructure.IsSingleComponent); Assert.Equal(compType, dataStructure.Components[0].ComponentType); }
public void GetOutputStructure_Correct1Superset1SubsetExpr_SupersetModified(params TestExprType[] types) { foreach (string opSymbol in this._operators) { IExpression arithmeticExpr = TestExprFactory.GetExpression(types); arithmeticExpr.OperatorDefinition = ModelResolvers.OperatorResolver(opSymbol); arithmeticExpr.Operands["ds_1"].Structure.Identifiers.Add(new StructureComponent(BasicDataType.Integer, "Id2")); IDataStructure expectedStructure = arithmeticExpr.Operands[$"ds_1"].Structure.GetCopy(); for (int i = 0; i < expectedStructure.Measures.Count; i++) { BasicDataType dataType = arithmeticExpr.Operands[$"ds_2"].Structure.Measures[i].ValueDomain.DataType; if (dataType == BasicDataType.Number) { expectedStructure.Measures[i].ValueDomain = new ValueDomain(dataType); } if (expectedStructure.Measures[i].ValueDomain.DataType == BasicDataType.None) { expectedStructure.Measures[i].ValueDomain = new ValueDomain(BasicDataType.Integer); } } IDataStructure dataStructure = arithmeticExpr.OperatorDefinition.GetOutputStructure(arithmeticExpr); Assert.True(expectedStructure.EqualsObj(dataStructure)); } }
public DsBranchTests() { Mock <IExpressionTextGenerator> exprTextGeneratorMock = new Mock <IExpressionTextGenerator>(); exprTextGeneratorMock.Setup(etg => etg.GenerateRecursively(It.IsAny <IExpression>())) .Callback((IExpression expr) => { expr.ExpressionText = "Generated text"; }); this._exprTextGenerator = exprTextGeneratorMock.Object; Mock <IExpressionFactory> exprFactoryMock = new Mock <IExpressionFactory>(); exprFactoryMock.SetupGet(e => e.OperatorResolver).Returns(ModelResolvers.OperatorResolver); exprFactoryMock.SetupGet(e => e.ExprResolver).Returns(ModelResolvers.ExprResolver); exprFactoryMock.Setup(e => e.GetExpression(It.IsAny <string>(), ExpressionFactoryNameTarget.OperatorSymbol)).Returns((string opSymbol, ExpressionFactoryNameTarget nameTarget) => { IExpression expr = ModelResolvers.ExprResolver(); Mock <IOperatorDefinition> opDefMock = new Mock <IOperatorDefinition>(); opDefMock.SetupGet(opDef => opDef.Symbol).Returns(opSymbol); opDefMock.Setup(opDef => opDef.GetOutputStructure(It.IsAny <IExpression>())).Returns(ModelResolvers.DsResolver()); expr.OperatorDefinition = opDefMock.Object; return(expr); }); this._exprFac = exprFactoryMock.Object; }
public void GetOutputStructure_GroupNScalarsExpr_DataStructure() { IJoinExpression joinExpr = ModelResolvers.JoinExprResolver(this._exprFac.GetExpression("join", ExpressionFactoryNameTarget.OperatorSymbol)); for (int i = 3; i <= 5; i++) // very expensive { TestExprType[][] combinations = Enum.GetValues(typeof(TestExprType)).Cast <TestExprType>().Where(type => (int)type <= 8).GetCombinations(i); foreach (TestExprType[] combination in combinations) { IExpression compCreateExpr = this._exprFac.GetExpression("group", ExpressionFactoryNameTarget.OperatorSymbol); joinExpr.AddOperand("ds_1", compCreateExpr); IDataStructure expectedStructure = ModelResolvers.DsResolver(); for (int k = 2; k <= i; k++) { IExpression idExpr = ModelResolvers.ExprResolver(); idExpr.ExpressionText = $"Id{k}"; idExpr.Structure = ModelResolvers.DsResolver($"Id{k}", ComponentType.Identifier, (BasicDataType)combination[k - 1]); compCreateExpr.AddOperand($"ds_{k}", idExpr); expectedStructure.AddStructure(compCreateExpr.Operands[$"ds_{k}"].Structure); } IDataStructure dataStructure = compCreateExpr.OperatorDefinition.GetOutputStructure(compCreateExpr); Assert.True(expectedStructure.EqualsObj(dataStructure)); } } }
public void GetOutputStructure_NScalarsExpr_DataStructure(string opSymbol) { IJoinExpression joinExpr = ModelResolvers.JoinExprResolver(this._exprFac.GetExpression("join", ExpressionFactoryNameTarget.OperatorSymbol)); for (int i = 3; i <= 5; i++) // very expensive { TestExprType[][] combinations = Enum.GetValues(typeof(TestExprType)).Cast <TestExprType>().Where(type => (int)type <= 8).GetCombinations(i); foreach (TestExprType[] combination in combinations) { IExpression compCreateExpr = TestExprFactory.GetExpression(combination); compCreateExpr.OperatorDefinition = this._exprFac.OperatorResolver(opSymbol); joinExpr.AddOperand("ds_1", compCreateExpr); IDataStructure expectedStructure = compCreateExpr.Operands["ds_1"].Structure.GetCopy(); for (int k = 2; k <= i; k++) { expectedStructure.AddStructure(compCreateExpr.Operands[$"ds_{k}"].Structure); } IDataStructure dataStructure = compCreateExpr.OperatorDefinition.GetOutputStructure(compCreateExpr); Assert.True(expectedStructure.EqualsObj(dataStructure)); } } }
public void GetOutputStructure_WrongArgsExpr_ThrowsException() { TestExprType[][] correctCombs = new TestExprType[][] { new TestExprType[] { TestExprType.String, TestExprType.String }, new TestExprType[] { TestExprType.String, TestExprType.None }, new TestExprType[] { TestExprType.None, TestExprType.String }, new TestExprType[] { TestExprType.None, TestExprType.None }, new TestExprType[] { TestExprType.StringsDataset, TestExprType.String }, new TestExprType[] { TestExprType.StringsDataset, TestExprType.None }, new TestExprType[] { TestExprType.NonesDataset, TestExprType.String }, new TestExprType[] { TestExprType.NonesDataset, TestExprType.None } }; TestExprType[][] combinations = Enum.GetValues(typeof(TestExprType)).Cast <TestExprType>().GetCombinations(2); TestExprType[][] wrongCombs = combinations.Without(correctCombs); foreach (TestExprType[] wrongComb in wrongCombs.Where(wrongComb => (int)wrongComb[0] < 18 && (int)wrongComb[1] < 18)) // No mixed datasets { IExpression stringExpr = TestExprFactory.GetExpression(wrongComb); stringExpr.OperatorDefinition = ModelResolvers.OperatorResolver("match_characters"); if (!stringExpr.Operands["ds_1"].IsScalar) { stringExpr.Operands["ds_1"].Structure.Measures.RemoveAt(1); } if (!stringExpr.Operands["ds_2"].IsScalar) { stringExpr.Operands["ds_2"].Structure.Measures.RemoveAt(1); } // Debug condition example: wrongComb[0] == TestExprType.Integer && wrongComb[1] == TestExprType.Integer Assert.ThrowsAny <VtlOperatorError>(() => { stringExpr.OperatorDefinition.GetOutputStructure(stringExpr); }); } }
public void GetOutputStructure_MultiMeasuresDatasetExpr_ThrowsException() { TestExprType[][] scalars = new TestExprType[][] { new TestExprType[] { TestExprType.Integer }, new TestExprType[] { TestExprType.Number }, new TestExprType[] { TestExprType.String }, new TestExprType[] { TestExprType.Boolean }, new TestExprType[] { TestExprType.Time }, new TestExprType[] { TestExprType.Date }, new TestExprType[] { TestExprType.TimePeriod }, new TestExprType[] { TestExprType.Duration }, new TestExprType[] { TestExprType.None } }; TestExprType[][] types = Enum.GetValues(typeof(TestExprType)).Cast <TestExprType>().GetCombinations(1); TestExprType[][] datasets = types.Without(scalars); foreach (TestExprType[] dataset in datasets) { IExpression isNullExpr = TestExprFactory.GetExpression(dataset); isNullExpr.OperatorDefinition = ModelResolvers.OperatorResolver("isnull"); // Debug condition example: dataset[0] == TestExprType.IntsDataset Assert.ThrowsAny <VtlOperatorError>(() => { isNullExpr.OperatorDefinition.GetOutputStructure(isNullExpr); }); } }
public void Constructor_HasCorrectParentExpression() { IExpression parentExpr = ModelResolvers.ExprResolver(); Expression expr = new Expression(parentExpr); Assert.Equal(parentExpr, expr.ParentExpression); }
public void Build_AggrAnalyticOperatorExpr_Expr() { List <string> opSymbols = new List <string>(AggrFunctionOperator.Symbols); opSymbols.AddRange(AnalyticFunctionOperator.Symbols); foreach (string opSymbol in opSymbols) { ApplyBranch applyBranch = new ApplyBranch(ModelResolvers.ExprResolver, this._exprTextGenerator); Mock <IOperatorDefinition> opDefMock = new Mock <IOperatorDefinition>(); opDefMock.SetupGet(opDef => opDef.Symbol).Returns(opSymbol); opDefMock.Setup(opDef => opDef.GetOutputStructure(It.IsAny <IExpression>())) .Returns((IExpression expr) => { return(ModelResolvers.DsResolver()); }); IExpression expr = TestExprFactory.GetExpression(opSymbol, ExpressionFactoryNameTarget.OperatorSymbol); expr.OperatorDefinition = opDefMock.Object; expr.AddOperand("ds", ModelResolvers.ExprResolver()); expr.AddOperand("group", ModelResolvers.ExprResolver()); expr.AddOperand("having", ModelResolvers.ExprResolver()); expr.AddOperand("over", ModelResolvers.ExprResolver()); IExpression result = applyBranch.Build(expr); Assert.NotNull(result.Structure); Assert.Equal("Generated text", result.ExpressionText); Assert.Equal("Apply", result.ResultName); Assert.Equal("apply", result.ParamSignature); Assert.Equal(expr.OperatorSymbol, result.OperatorSymbol); Assert.Equal(1, result.OperandsCollection.Count); Assert.True(result.Operands.ContainsKey("ds")); } }
public void CurrentJoinExpr_JoinExprAncestor_CorrectExpression() { IJoinExpression joinExpr = ModelResolvers.JoinExprResolver(TestExprFactory.GetExpression("join", ExpressionFactoryNameTarget.OperatorSymbol)); Expression expr = new Expression(joinExpr); Assert.Equal(joinExpr, expr.CurrentJoinExpr); }
public void GetOutputStructure_Group2ScalarsExpr_DataStructure(params TestExprType[] types) { IExpression compCreateExpr = this._exprFac.GetExpression("group", ExpressionFactoryNameTarget.OperatorSymbol); IExpression idExpr1 = ModelResolvers.ExprResolver(); IExpression idExpr2 = ModelResolvers.ExprResolver(); idExpr1.ExpressionText = "Id1"; idExpr2.ExpressionText = "Id2"; idExpr1.Structure = ModelResolvers.DsResolver("Id1", ComponentType.Identifier, (BasicDataType)types[0]); idExpr2.Structure = ModelResolvers.DsResolver("Id2", ComponentType.Identifier, (BasicDataType)types[1]); compCreateExpr.AddOperand("ds_1", idExpr1); compCreateExpr.AddOperand("ds_2", idExpr2); IJoinExpression joinExpr = ModelResolvers.JoinExprResolver(this._exprFac.GetExpression("join", ExpressionFactoryNameTarget.OperatorSymbol)); joinExpr.AddOperand("ds_1", compCreateExpr); IDataStructure expectedStructure = compCreateExpr.Operands["ds_1"].Structure.GetCopy(); expectedStructure.Identifiers.Add(compCreateExpr.Operands["ds_2"].Structure.GetCopy().Identifiers[0]); IDataStructure dataStructure = compCreateExpr.OperatorDefinition.GetOutputStructure(compCreateExpr); Assert.True(expectedStructure.EqualsObj(dataStructure)); }
public void GetOutputStructure_WrongComponentTwoDatasetsJoinExpr_DurationScalarStructure(bool isMemership, TestExprType type) { foreach (string name in DatasetClauseOperator.ClauseNames.Where(name => !name.In("Pivot", "Unpivot", "Subspace"))) { IExpression joinExpr = ModelResolvers.JoinExprResolver(TestExprFactory.GetExpression("join", ExpressionFactoryNameTarget.OperatorSymbol)); IExpression ds1Expr = TestExprFactory.GetExpression("get", ExpressionFactoryNameTarget.OperatorSymbol); IExpression ds2Expr = TestExprFactory.GetExpression("get", ExpressionFactoryNameTarget.OperatorSymbol); IExpression clauseExpr = TestExprFactory.GetExpression(name, ExpressionFactoryNameTarget.ResultName); IExpression periodIndicatorExpr = TestExprFactory.GetExpression("period_indicator", ExpressionFactoryNameTarget.OperatorSymbol); IExpression paramExpr = TestExprFactory.GetExpression(type); if (isMemership) { paramExpr.OperatorDefinition = ModelResolvers.OperatorResolver("#"); } joinExpr.AddOperand("ds", ModelResolvers.ExprResolver()); joinExpr.Operands["ds"].AddOperand("ds_1", ds1Expr); joinExpr.Operands["ds"].AddOperand("ds_2", ds2Expr); joinExpr.AddOperand(name, clauseExpr); clauseExpr.AddOperand("ds_1", periodIndicatorExpr); periodIndicatorExpr.AddOperand("ds_1", paramExpr); ds1Expr.Structure = ModelResolvers.DsResolver(); ds1Expr.Structure.Identifiers.Add(new StructureComponent(BasicDataType.Integer, "Id1")); ds1Expr.Structure.Identifiers.Add(new StructureComponent((BasicDataType)type, "Id2")); ds1Expr.Structure.Measures.Add(new StructureComponent(BasicDataType.String, "Me1")); ds2Expr.Structure = ds1Expr.Structure.GetCopy(); Assert.ThrowsAny <VtlOperatorError>(() => { periodIndicatorExpr.OperatorDefinition.GetOutputStructure(periodIndicatorExpr); }); } }
public void Constructor_JoinExpr_JoinExpr() { IExpression expr = TestExprFactory.GetExpression("join", ExpressionFactoryNameTarget.OperatorSymbol); IExpression refExpr = ModelResolvers.ExprResolver(); ITransformationSchema schema = ModelResolvers.SchemaResolver(); refExpr.AddOperand("ds", expr); expr.ContainingSchema = schema; expr.ReferenceExpression = refExpr; IJoinExpression joinExpr2 = ModelResolvers.JoinExprResolver(expr); joinExpr2.BasicStructure = ModelResolvers.DsResolver(); JoinExpression joinExpr = new JoinExpression(joinExpr2); Assert.Equal(expr.ParentExpression, joinExpr.ParentExpression); Assert.Equal(expr.ContainingSchema, joinExpr.ContainingSchema); Assert.Equal(expr.ExpressionText, joinExpr.ExpressionText); Assert.Equal(expr.LineNumber, joinExpr.LineNumber); Assert.Equal(expr.OperandsCollection, joinExpr.OperandsCollection); Assert.Equal(expr.OperatorDefinition, joinExpr.OperatorDefinition); Assert.Equal(expr.ParamSignature, joinExpr.ParamSignature); Assert.Equal(expr.ReferenceExpression, joinExpr.ReferenceExpression); Assert.Equal(expr.ResultName, joinExpr.ResultName); Assert.Equal(expr.Structure, joinExpr.Structure); Assert.Equal(joinExpr2.BasicStructure, joinExpr.BasicStructure); }
public void GetExpressions_Expressions() { TransformationSchema schema = new TransformationSchema(); IExpression expr1 = ModelResolvers.ExprResolver(); IExpression expr2 = ModelResolvers.ExprResolver(); AssignmentObject assignmentObject1 = new AssignmentObject(schema, expr1, true, new List <string>()); AssignmentObject assignmentObject2 = new AssignmentObject(schema, expr2, true, new List <string>()); schema.AssignmentObjects.Add(assignmentObject1); schema.AssignmentObjects.Add(assignmentObject2); List <IExpression> expected = new List <IExpression>() { expr1, expr2 }; ICollection <IExpression> result = schema.GetExpressions(); Assert.Equal(expected.Count, result.Count); for (int i = 0; i < expected.Count; i++) { Assert.Equal(expected[i], result.ToArray()[i]); } }
public void Build_Expr_Expr(params string[] opSymbols) { DsBranch dsBranch = new DsBranch(this._exprFac, this._exprTextGenerator); IExpression expr = ModelResolvers.ExprResolver(); IExpression expected = ModelResolvers.ExprResolver(); for (int i = 0; i < opSymbols.Length; i++) { IExpression subExpr = this._exprFac.GetExpression(opSymbols[i], ExpressionFactoryNameTarget.OperatorSymbol); // local expFactory expected subExpr.Structure = ModelResolvers.DsResolver(); subExpr.ExpressionText = opSymbols[i]; expr.AddOperand($"ds_{i}", subExpr); if (opSymbols[i].In("get", "ref", "#", "join")) { expected.AddOperand($"ds_{i}", subExpr); } } IExpression result = dsBranch.Build(expr); Assert.Equal(expected.OperandsCollection.Count, result.OperandsCollection.Count); foreach (string opSymbol in opSymbols.Where(opS => opS.In("get", "ref", "#", "join"))) { Assert.True(result.OperandsCollection.Where(op => op.OperatorSymbol == opSymbol).Count() == 1); } }
public void GetOutputStructure_WrongArgExpr1Arg_ThrowsException(string opSymbol) { TestExprType[][] correctCombs = new TestExprType[][] { new TestExprType[] { TestExprType.String }, new TestExprType[] { TestExprType.None }, new TestExprType[] { TestExprType.StringsDataset }, new TestExprType[] { TestExprType.NonesDataset }, new TestExprType[] { TestExprType.MixedNoneStrDataset } }; TestExprType[][] combinations = Enum.GetValues(typeof(TestExprType)).Cast <TestExprType>().GetCombinations(1); TestExprType[][] wrongCombs = combinations.Without(correctCombs.ToArray()); foreach (TestExprType[] wrongComb in wrongCombs.Where(wrongComb => (int)wrongComb[0] < 18)) // No mixed datasets { IExpression stringExpr = TestExprFactory.GetExpression(new TestExprType[] { wrongComb[0] }); stringExpr.OperatorDefinition = ModelResolvers.OperatorResolver(opSymbol); if (opSymbol.In("length", "instr") && stringExpr.Operands["ds_1"].Structure.Measures.Count > 1) { stringExpr.Operands["ds_1"].Structure.Measures.RemoveAt(1); } // Debug condition example: wrongComb[0] == TestExprType.Integer Assert.ThrowsAny <VtlOperatorError>(() => { stringExpr.OperatorDefinition.GetOutputStructure(stringExpr); }); } }
public void GetOutputStructure_CorrectSingleMeasureExpr_DataStructure(params TestExprType[] types) { IExpression nvlExpr = TestExprFactory.GetExpression(types[0], types[1]); nvlExpr.OperatorDefinition = ModelResolvers.OperatorResolver("nvl"); if (nvlExpr.Operands["ds_1"].Structure.Measures.Count > 1) { nvlExpr.Operands["ds_1"].Structure.Measures.RemoveAt(1); } if (nvlExpr.Operands["ds_2"].Structure.Measures.Count > 1) { nvlExpr.Operands["ds_2"].Structure.Measures.RemoveAt(1); } IExpression expected = TestExprFactory.GetExpression(types[2]); if (expected.Structure.Measures.Count > 1) { expected.Structure.Measures.RemoveAt(1); } IDataStructure dataStructure = nvlExpr.OperatorDefinition.GetOutputStructure(nvlExpr); Assert.True(expected.Structure.EqualsObj(dataStructure)); }
public void Build_NotAggrAnalyticOperatorExpr_Expr(string opSymbol) { ApplyBranch applyBranch = new ApplyBranch(ModelResolvers.ExprResolver, this._exprTextGenerator); Mock <IOperatorDefinition> opDefMock = new Mock <IOperatorDefinition>(); opDefMock.SetupGet(opDef => opDef.Symbol).Returns(opSymbol); opDefMock.Setup(opDef => opDef.GetOutputStructure(It.IsAny <IExpression>())) .Returns((IExpression expr) => { return(ModelResolvers.DsResolver()); }); IExpression expr = TestExprFactory.GetExpression(opSymbol, ExpressionFactoryNameTarget.OperatorSymbol); expr.OperatorDefinition = opDefMock.Object; expr.AddOperand("ds", ModelResolvers.ExprResolver()); expr.AddOperand("group", ModelResolvers.ExprResolver()); expr.AddOperand("having", ModelResolvers.ExprResolver()); expr.AddOperand("over", ModelResolvers.ExprResolver()); IExpression result = applyBranch.Build(expr); Assert.NotNull(result.Structure); Assert.Equal("Generated text", result.ExpressionText); Assert.Equal("Apply", result.ResultName); Assert.Equal("apply", result.ParamSignature); Assert.Equal(expr.OperatorSymbol, result.OperatorSymbol); Assert.Equal(expr.OperandsCollection.Count, result.OperandsCollection.Count); for (int i = 0; i < expr.OperandsCollection.Count; i++) { Assert.Equal(expr.OperandsCollection.ToArray()[i].ParamSignature, result.OperandsCollection.ToArray()[i].ParamSignature); } }
public void IsPartOfBranch_Exprs_CorrectResult() { IExpression branchExpr1 = ModelResolvers.ExprResolver(); IExpression branchExpr2 = ModelResolvers.ExprResolver(); IExpression expr1 = ModelResolvers.ExprResolver(); IExpression expr2 = ModelResolvers.ExprResolver(); IExpression expr3 = ModelResolvers.ExprResolver(); JoinExpression joinExpr = new JoinExpression(TestExprFactory.GetExpression("join", ExpressionFactoryNameTarget.OperatorSymbol)); joinExpr.AddOperand("branch_1", branchExpr1); joinExpr.AddOperand("branch_2", branchExpr2); branchExpr1.AddOperand("ds_1", expr1); branchExpr2.AddOperand("ds_1", expr2); Assert.True(joinExpr.IsPartOfBranch("branch_1", branchExpr1)); Assert.True(joinExpr.IsPartOfBranch("branch_1", expr1)); Assert.True(joinExpr.IsPartOfBranch("branch_2", branchExpr2)); Assert.True(joinExpr.IsPartOfBranch("branch_2", expr2)); Assert.False(joinExpr.IsPartOfBranch("branch_2", branchExpr1)); Assert.False(joinExpr.IsPartOfBranch("branch_2", expr1)); Assert.False(joinExpr.IsPartOfBranch("branch_1", branchExpr2)); Assert.False(joinExpr.IsPartOfBranch("branch_1", expr2)); Assert.False(joinExpr.IsPartOfBranch("branch_1", expr3)); Assert.False(joinExpr.IsPartOfBranch("branch_2", expr3)); }
public void GetOutputStructure_WrongArgExpr_ThrowsException() { TestExprType[][] correctCombs = new TestExprType[][] { new TestExprType[] { TestExprType.Boolean }, new TestExprType[] { TestExprType.None }, new TestExprType[] { TestExprType.BoolsDataset }, new TestExprType[] { TestExprType.NonesDataset }, }; TestExprType[][] combinations = Enum.GetValues(typeof(TestExprType)).Cast <TestExprType>().GetCombinations(1); TestExprType[][] wrongCombs = combinations.Without(correctCombs); foreach (TestExprType[] wrongComb in wrongCombs.Where(wrongComb => (int)wrongComb[0] < 18)) // No mixed datasets { IExpression notExpr = TestExprFactory.GetExpression(wrongComb); notExpr.OperatorDefinition = ModelResolvers.OperatorResolver("not"); if (notExpr.Operands["ds_1"].Structure.Measures.Count > 1) { notExpr.Operands["ds_1"].Structure.Measures.RemoveAt(1); } // Debug condition example: wrongComb[0] == TestExprType.Integer Assert.ThrowsAny <VtlOperatorError>(() => { notExpr.OperatorDefinition.GetOutputStructure(notExpr); }); } }
public void GetOutputStructure_CorrectNoParamOneDatasetJoinExpr_DurationScalarStructure() { foreach (string name in DatasetClauseOperator.ClauseNames.Where(name => !name.In("Pivot", "Unpivot", "Subspace"))) { IExpression joinExpr = ModelResolvers.JoinExprResolver(TestExprFactory.GetExpression("join", ExpressionFactoryNameTarget.OperatorSymbol)); IExpression datasetExpr = TestExprFactory.GetExpression("get", ExpressionFactoryNameTarget.OperatorSymbol); IExpression clauseExpr = TestExprFactory.GetExpression(name, ExpressionFactoryNameTarget.ResultName); IExpression periodIndicatorExpr = TestExprFactory.GetExpression("period_indicator", ExpressionFactoryNameTarget.OperatorSymbol); joinExpr.AddOperand("ds", ModelResolvers.ExprResolver()); joinExpr.Operands["ds"].AddOperand("ds_1", datasetExpr); joinExpr.AddOperand(name, clauseExpr); clauseExpr.AddOperand("ds_1", periodIndicatorExpr); datasetExpr.Structure = ModelResolvers.DsResolver(); datasetExpr.Structure.Identifiers.Add(new StructureComponent(BasicDataType.Integer, "Id1")); datasetExpr.Structure.Identifiers.Add(new StructureComponent(BasicDataType.TimePeriod, "Id2")); datasetExpr.Structure.Measures.Add(new StructureComponent(BasicDataType.String, "Me1")); IDataStructure expectedStructure = ModelResolvers.DsResolver("duration_var", ComponentType.Measure, BasicDataType.Duration); IDataStructure dataStructure = periodIndicatorExpr.OperatorDefinition.GetOutputStructure(periodIndicatorExpr); Assert.True(expectedStructure.EqualsObj(dataStructure)); } }
public void GetOutputStructure_WrongArgExpr_ThrowsException() { TestExprType[][] correctCombs = new TestExprType[][] { new TestExprType[] { TestExprType.Integer }, new TestExprType[] { TestExprType.Number }, new TestExprType[] { TestExprType.None }, new TestExprType[] { TestExprType.IntsDataset }, new TestExprType[] { TestExprType.NumbersDataset }, new TestExprType[] { TestExprType.MixedIntNumDataset }, new TestExprType[] { TestExprType.NonesDataset }, new TestExprType[] { TestExprType.MixedNoneIntDataset }, new TestExprType[] { TestExprType.MixedNoneNumDataset } }; TestExprType[][] combinations = Enum.GetValues(typeof(TestExprType)).Cast <TestExprType>().GetCombinations(1); TestExprType[][] wrongCombs = combinations.Without(correctCombs); foreach (string opSymbol in this._operators) { foreach (TestExprType[] wrongComb in wrongCombs) { IExpression unaryArithmeticExpr = TestExprFactory.GetExpression(wrongComb); unaryArithmeticExpr.OperatorDefinition = ModelResolvers.OperatorResolver(opSymbol); // Debug condition example: wrongComb[0] == TestExprType.Integer Assert.ThrowsAny <VtlOperatorError>(() => { unaryArithmeticExpr.OperatorDefinition.GetOutputStructure(unaryArithmeticExpr); }); } } }
public void GetOutputStructure_CorrectDatasetCollectionExpr_BoolScalarStructure() { foreach (string opSymbol in this._operators) { IExpression collectionExpr = ModelResolvers.ExprResolver(); collectionExpr.Structure = ModelResolvers.DsResolver(); collectionExpr.OperatorDefinition = ModelResolvers.OperatorResolver("collection"); collectionExpr.Structure.Measures.Add(new StructureComponent(BasicDataType.Integer)); collectionExpr.Structure.Measures.Add(new StructureComponent(BasicDataType.Number)); collectionExpr.Structure.Measures.Add(new StructureComponent(BasicDataType.None)); IExpression inExpr = ModelResolvers.ExprResolver(); inExpr.AddOperand("ds_1", TestExprFactory.GetExpression(TestExprType.NumbersDataset)); inExpr.AddOperand("ds_2", collectionExpr); inExpr.Operands["ds_1"].Structure.Measures.RemoveAt(1); inExpr.OperatorDefinition = ModelResolvers.OperatorResolver(opSymbol); IExpression expected = TestExprFactory.GetExpression(TestExprType.BoolsDataset); expected.Structure.Measures.RemoveAt(1); IDataStructure dataStructure = inExpr.OperatorDefinition.GetOutputStructure(inExpr); Assert.True(expected.Structure.EqualsObj(dataStructure)); } }
public void GetOutputStructure_MultiMeasuresDatasetNScalarsExpr_ThrowsException(string opSymbol, params TestExprType[] types) { IExpression stringExpr = TestExprFactory.GetExpression(types); stringExpr.OperatorDefinition = ModelResolvers.OperatorResolver(opSymbol); Assert.ThrowsAny <VtlOperatorError>(() => { stringExpr.OperatorDefinition.GetOutputStructure(stringExpr); }); }
public void Structure_IsSingleComponentTrue_IsScalarTrue() { Expression expr = new Expression(); expr.Structure = ModelResolvers.DsResolver("comp", ComponentType.Measure, BasicDataType.Integer); Assert.True(expr.IsScalar); }
public void OperatorDefinition_Set_OperatorSymbolSet(string opSymbol) { Expression expr = new Expression(); expr.OperatorDefinition = ModelResolvers.OperatorResolver(opSymbol); Assert.Equal(opSymbol, expr.OperatorSymbol); }
public void GetOutputStructure_1MultiMeasuresDataset2CorrectScalarsArgsExpr_ThrowsException(params TestExprType[] types) { IExpression betweenExpr = TestExprFactory.GetExpression(types); betweenExpr.OperatorDefinition = ModelResolvers.OperatorResolver("between"); Assert.ThrowsAny <VtlOperatorError>(() => { betweenExpr.OperatorDefinition.GetOutputStructure(betweenExpr); }); }
public void GetOutputStructure_MultiMeasuresDatasetExpr_ThrowsException(TestExprType type) { IExpression notExpr = TestExprFactory.GetExpression(new TestExprType[] { type }); notExpr.OperatorDefinition = ModelResolvers.OperatorResolver("not"); Assert.ThrowsAny <VtlOperatorError>(() => { notExpr.OperatorDefinition.GetOutputStructure(notExpr); }); }
public void GetFirstAncestorExpr_FirstAncestorExpr() { IExpression grandGrandExpr = ModelResolvers.ExprResolver(); IExpression grandExpr = ModelResolvers.ExprResolver(grandGrandExpr); IExpression fatherExpr = ModelResolvers.ExprResolver(grandExpr); Expression expr = new Expression(fatherExpr); Assert.Equal(grandGrandExpr, expr.GetFirstAncestorExpr()); }
public void GetAliasExpression_NoDsBranch_ThrowsException() { JoinExpression joinExpr = new JoinExpression(TestExprFactory.GetExpression("join", ExpressionFactoryNameTarget.OperatorSymbol)); joinExpr.AddOperand("ds_1", ModelResolvers.ExprResolver()); joinExpr.AddOperand("ds_2", ModelResolvers.ExprResolver()); Assert.ThrowsAny <Exception>(() => { joinExpr.GetAliasExpression("ds_1"); }); }