Пример #1
0
        public void Generate_IfOperator_CorrectText()
        {
            for (int i = 0; i < 2; i++)
            {
                IExpression expr = this.GetExpr("if");
                expr.Operands.Clear();
                expr.Operands.Add("if", TestExprFactory.GetExpression("If", ExpressionFactoryNameTarget.ResultName));
                expr.Operands.Add("then", TestExprFactory.GetExpression("Then", ExpressionFactoryNameTarget.ResultName));

                string expr1Text = expr.Operands["if"].ExpressionText = "expr1";
                string expr2Text = expr.Operands["then"].ExpressionText = "expr2";

                string expected = $"{expr1Text} {expr2Text}";
                if (i == 1)
                {
                    expr.Operands.Add("else", TestExprFactory.GetExpression("Else", ExpressionFactoryNameTarget.ResultName));
                    string expr3Text = expr.Operands["else"].ExpressionText = "expr3";

                    expected += $" {expr3Text}";
                }

                this._exprTextGenerator.Generate(expr);

                Assert.Equal(expected, expr.ExpressionText);
            }
        }
Пример #2
0
        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); });
            }
        }
Пример #4
0
        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));
            }
        }
Пример #5
0
        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 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 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_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 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));
        }
Пример #10
0
        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));
            }
        }
Пример #11
0
        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 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 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 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));
        }
Пример #16
0
        public void CurrentJoinExpr_JoinExprAncestor_CorrectExpression()
        {
            IJoinExpression joinExpr = ModelResolvers.JoinExprResolver(TestExprFactory.GetExpression("join", ExpressionFactoryNameTarget.OperatorSymbol));
            Expression      expr     = new Expression(joinExpr);

            Assert.Equal(joinExpr, expr.CurrentJoinExpr);
        }
Пример #17
0
        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); });
            }
        }
Пример #18
0
        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); });
        }
Пример #19
0
        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); });
        }
Пример #20
0
        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 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"); });
        }
        public void GetExpression_OperatorSymbol_ExprWithNameAndOpDefinition(string opSymbol)
        {
            IExpression expr = TestExprFactory.GetExpression(opSymbol, ExpressionFactoryNameTarget.OperatorSymbol);

            Assert.Equal(opSymbol == "+" ? "Arithmetic" : "Comparison", expr.ResultName);
            Assert.Null(expr.ExpressionText);
            Assert.Equal(opSymbol, expr.OperatorSymbol);
            Assert.NotNull(expr.OperatorDefinition);
        }
        public void GetExpression_ResultName_ExprWithName(string name)
        {
            IExpression expr = TestExprFactory.GetExpression(name, ExpressionFactoryNameTarget.ResultName);

            Assert.Equal(name, expr.ResultName);
            Assert.Null(expr.ExpressionText);
            Assert.Null(expr.OperatorSymbol);
            Assert.Null(expr.OperatorDefinition);
        }
Пример #24
0
        public void GetOutputStructure_CorrectScalarsExpr_NumberScalarStructure(string opSymbol, params TestExprType[] types)
        {
            IExpression numericExpr = TestExprFactory.GetExpression(types);

            numericExpr.OperatorDefinition = ModelResolvers.OperatorResolver(opSymbol);

            IDataStructure dataStructure = numericExpr.OperatorDefinition.GetOutputStructure(numericExpr);

            Assert.True(TestExprFactory.GetExpression(TestExprType.Number).Structure.EqualsObj(dataStructure));
        }
Пример #25
0
        public void GetOutputStructure_Correct3ScalarsArgsExpr_BoolScalarStructure(params TestExprType[] types)
        {
            IExpression betweenExpr = TestExprFactory.GetExpression(types);

            betweenExpr.OperatorDefinition = ModelResolvers.OperatorResolver("between");

            IDataStructure dataStructure = betweenExpr.OperatorDefinition.GetOutputStructure(betweenExpr);

            Assert.Equal(BasicDataType.Boolean, dataStructure.Components.First().ValueDomain.DataType);
        }
Пример #26
0
        public void GetOutputStructure_CorrectScalarExpr_BoolScalarStructure(TestExprType type)
        {
            IExpression notExpr = TestExprFactory.GetExpression(new TestExprType[] { type });

            notExpr.OperatorDefinition = ModelResolvers.OperatorResolver("not");

            IDataStructure dataStructure = notExpr.OperatorDefinition.GetOutputStructure(notExpr);

            Assert.True(TestExprFactory.GetExpression(TestExprType.Boolean).Structure.EqualsObj(dataStructure));
        }
Пример #27
0
        public void GetOutputStructure_CorrectScalarsExpr_BoolScalarStructure(params TestExprType[] types)
        {
            IExpression stringExpr = TestExprFactory.GetExpression(types);

            stringExpr.OperatorDefinition = ModelResolvers.OperatorResolver("match_characters");

            IDataStructure dataStructure = stringExpr.OperatorDefinition.GetOutputStructure(stringExpr);

            Assert.True(TestExprFactory.GetExpression(TestExprType.Boolean).Structure.EqualsObj(dataStructure));
        }
Пример #28
0
        public void GetOutputStructure_ScalarDatasetExpr_StringsDatasetStructure(string opSymbol, params TestExprType[] types)
        {
            IExpression stringExpr = TestExprFactory.GetExpression(types);

            stringExpr.OperatorDefinition = ModelResolvers.OperatorResolver(opSymbol);

            IDataStructure dataStructure = stringExpr.OperatorDefinition.GetOutputStructure(stringExpr);

            Assert.True(TestExprFactory.GetExpression(TestExprType.StringsDataset).Structure.EqualsObj(dataStructure));
        }
        public void GetOutputStructure_1MultiMeasuresDataset1CorrectScalarArgsExpr_ThrowsException(params TestExprType[] types)
        {
            foreach (string opSymbol in this._operators)
            {
                IExpression equalityExpr = TestExprFactory.GetExpression(types);
                equalityExpr.OperatorDefinition = ModelResolvers.OperatorResolver(opSymbol);

                Assert.ThrowsAny <VtlOperatorError>(() => { equalityExpr.OperatorDefinition.GetOutputStructure(equalityExpr); });
            }
        }
        public void Build_CrossJoinWithUsinngBranch_ThrowsException()
        {
            JoinBuilder joinBuilder = new JoinBuilder(ModelResolvers.JoinExprResolver, this.joinBranches);

            joinBuilder.AddMainExpr(TestExprFactory.GetExpression("join", ExpressionFactoryNameTarget.OperatorSymbol));
            joinBuilder.AddBranch("ds", ModelResolvers.ExprResolver());
            joinBuilder.AddBranch("using", ModelResolvers.ExprResolver());
            joinBuilder.Branches["main"].OperatorDefinition.Keyword = "cross";

            Assert.ThrowsAny <VtlOperatorError>(() => { joinBuilder.Build(); });
        }