Exemple #1
0
            public LogicExspresion(NameSpace ns, int maxdepth, bool isneedbracers, bool isusingid = false, string table = "") : base(isneedbracers)
            {
                var idvaluechooser = new FrequencyRandomizer();

                if (isusingid)
                {
                    idvaluechooser.Insert(0, 7);//using id
                }

                idvaluechooser.Insert(1, 3);//as value
                if (_generator.NextDouble() * maxdepth <= valuechance * maxdepth)
                {
                    switch (idvaluechooser.GetRandom())
                    {
                    case 0:
                        _exspresion = new CompExspresion(ns, maxdepth - 1, true & isusingid, table).ToString();
                        break;

                    case 1:
                        _exspresion = new CompExspresion(ns, maxdepth - 1, false, table).ToString();
                        break;
                    }
                }
                else
                {
                    var binopchooser = new FrequencyRandomizer();// "and", "or"
                    for (var i = 0; i < _binoperators.Length; i++)
                    {
                        binopchooser.Insert(i, _binoperatorsfr[i]);
                    }
                    var op = binopchooser.GetRandom();
                    switch (idvaluechooser.GetRandom())
                    {
                    case 0:
                    {
                        _exspresion = $"{new LogicExspresion(ns, maxdepth - 1, op > 0, true & isusingid, table)}"
                                      + $"{_binoperators[op]}"
                                      + $"{new LogicExspresion(ns, maxdepth - 1, op > 0, true & isusingid, table)}";
                        break;
                    }

                    case 1:
                        _exspresion = $"{new LogicExspresion(ns, maxdepth - 1, op > 0, false, table)}"
                                      + $"{_binoperators[op]}"
                                      + $"{new LogicExspresion(ns, maxdepth - 1, op > 0, false, table)}";
                        break;
                    }
                    var unopchooser = new FrequencyRandomizer();// "+", "-" , nothing
                    for (var i = 0; i < _unoperators.Length; i++)
                    {
                        unopchooser.Insert(i, _unoperatorsfr[i]);
                    }
                    op = unopchooser.GetRandom();
                    if (op != 2)
                    {
                        _exspresion = $"({_unoperators[unopchooser.GetRandom()]}({_exspresion}))";
                    }
                }
            }
Exemple #2
0
            public CreateColumn(NameSpace ns, string table)
            {
                _columnname = ns.GetRandomName();
                var typechooser = new FrequencyRandomizer();

                typechooser.Insert(0, 3); // int
                typechooser.Insert(1, 3); // double
                typechooser.Insert(2, 4); // char
                var type = ColumnType.Any;

                switch (typechooser.GetRandom())
                {
                case 0:
                {
                    _columntype = "int";
                    type        = ColumnType.Int;
                    break;
                }

                case 1:
                {
                    _columntype = "double";
                    type        = ColumnType.Double;
                    break;
                }

                case 2:
                {
                    _columntype = $"char ({_generator.Next(1256)})";
                    type        = ColumnType.Char;
                    break;
                }
                }
                var constraintchooser = new FrequencyRandomizer();

                constraintchooser.Insert(0, 2); //UNIQUE
                constraintchooser.Insert(1, 2); // PRIMARY KEY
                constraintchooser.Insert(2, 6); // PRIMARY KEY
                switch (typechooser.GetRandom())
                {
                case 0:
                {
                    _constraint = "UNIQUE";
                    break;
                }

                case 1:
                {
                    _constraint = "PRIMARY KEY";
                    break;
                }
                }
                ns.AddTableColumn(table, _columnname, type);
            }
            public StringExspresion(NameSpace ns, int maxdepth, bool isusingid = false, string table = "") : base(false)
            {
                var idvaluechooser = new FrequencyRandomizer();

                if (isusingid)
                {
                    idvaluechooser.Insert(0, 7); //using id
                }
                idvaluechooser.Insert(1, 3);     //as value
                if (_generator.NextDouble() * maxdepth <= valuechance * maxdepth)
                {
                    var value = $"'{NameSpace.RandomString()}'";
                    switch (idvaluechooser.GetRandom())
                    {
                    case 0:
                        _exspresion = ns.GetCharTableColumn(table)?._name;
                        if (_exspresion == null)
                        {
                            _exspresion = value;
                        }
                        break;

                    case 1:
                        _exspresion = value;
                        break;
                    }
                }
                else
                {
                    switch (idvaluechooser.GetRandom())
                    {
                    case 0:
                    {
                        _exspresion = $"{new StringExspresion(ns, maxdepth - 1, true, table)}"
                                      + $"+"
                                      + $"{new StringExspresion(ns, maxdepth - 1, true, table)}";
                        break;
                    }

                    case 1:
                        _exspresion = $"{new StringExspresion(ns, maxdepth - 1, false, table)}"
                                      + $"+"
                                      + $"{new StringExspresion(ns, maxdepth - 1, false, table)}";
                        break;
                    }
                }
            }
Exemple #4
0
            public ArifmExspresion(NameSpace ns, int maxdepth, bool isint, bool isneedbracers, bool isusingid = false, string table = "") : base(isneedbracers)
            {
                var chooser = new FrequencyRandomizer();

                if (isusingid)
                {
                    chooser.Insert(0, 7);                       //using id
                }
                chooser.Insert(1, 3);                           //as value
                isint = isint || _generator.NextDouble() < 0.3; // Double -> Int
                var value = isint ? _generator.Next(255555).ToString() : (_generator.Next(255555 / 10 * 7) * _generator.NextDouble()).ToString();
                var op    = 0;

                if (_generator.NextDouble() * maxdepth <= valuechance * maxdepth)
                {
                    switch (chooser.GetRandom())
                    {
                    case 0:
                        _exspresion = isint ? ns.GetIntTableColumn(table)?._name : ns.GetDoubleTableColumn(table)?._name;
                        if (_exspresion == null)
                        {
                            _exspresion = value;
                        }
                        break;

                    case 1:
                        _exspresion = value;
                        break;
                    }
                }
                else
                {
                    var binopchooser = new FrequencyRandomizer();// "+", "-" , "*" , "/" , "%"
                    for (var i = 0; i < _binoperators.Length; i++)
                    {
                        binopchooser.Insert(i, _binoperatorsfr[i]);
                    }
                    if (!isint)
                    {
                        binopchooser.Remove(4);
                        binopchooser.Remove(5);
                    }
                    else
                    {
                        binopchooser.Remove(3);
                    }
                    op = binopchooser.GetRandom();
                    switch (chooser.GetRandom())
                    {
                    case 0:
                    {
                        _exspresion = $"{new ArifmExspresion(ns, maxdepth - 1, isint, op > 1, true, table)}"
                                      + $"{_binoperators[op]}"
                                      + $"{new ArifmExspresion(ns, maxdepth - 1, isint, op > 1, true, table)}";
                        break;
                    }

                    case 1:
                        _exspresion = $"{new ArifmExspresion(ns, maxdepth - 1, isint, op > 1, false, table)}"
                                      + $"{_binoperators[op]}"
                                      + $"{new ArifmExspresion(ns, maxdepth - 1, isint, op > 1, false, table)}";
                        break;
                    }
                }
                var unopchooser = new FrequencyRandomizer();// "+", "-" , nothing

                for (var i = 0; i < _unoperators.Length; i++)
                {
                    unopchooser.Insert(i, _unoperatorsfr[i]);
                }
                op = unopchooser.GetRandom();
                if (op != 2)
                {
                    _exspresion = $"({_unoperators[unopchooser.GetRandom()]}({_exspresion}))";
                }
                _exspresion = _exspresion.Replace(',', '.');
            }
            public CompExspresion(NameSpace ns, int maxdepth, bool isusingid = false, string table = "") : base(true)
            {
                var compchooser = new FrequencyRandomizer();

                compchooser.Insert(0, 7 * 2); // int int
                compchooser.Insert(1, 7 * 2); // int double
                compchooser.Insert(2, 1);     // int string
                compchooser.Insert(3, 7 * 2); // double double
                compchooser.Insert(4, 7 * 2); // double int
                compchooser.Insert(5, 1);     // double string
                compchooser.Insert(6, 1);     // string string
                compchooser.Insert(7, 1);     // string int
                compchooser.Insert(8, 1);     // string double
                var opchooser = new FrequencyRandomizer();

                for (var i = 0; i < _operators.Length; i++)
                {
                    opchooser.Insert(i, _operatorsfr[i]);
                }
                var _left  = ColumnType.Any;
                var _right = ColumnType.Any;

                switch (compchooser.GetRandom())
                {
                case 0:
                    _left  = ColumnType.Int;
                    _right = ColumnType.Int;
                    break;

                case 1:
                    _left  = ColumnType.Int;
                    _right = ColumnType.Double;
                    break;

                case 2:
                    _left  = ColumnType.Int;
                    _right = ColumnType.Char;
                    break;

                case 3:
                    _left  = ColumnType.Double;
                    _right = ColumnType.Double;
                    break;

                case 4:
                    _left  = ColumnType.Double;
                    _right = ColumnType.Int;
                    break;

                case 5:
                    _left  = ColumnType.Double;
                    _right = ColumnType.Char;
                    break;

                case 6:
                    _left  = ColumnType.Char;
                    _right = ColumnType.Char;
                    break;

                case 7:
                    _left  = ColumnType.Char;
                    _right = ColumnType.Int;
                    break;

                case 8:
                    _left  = ColumnType.Char;
                    _right = ColumnType.Double;
                    break;
                }
                _exspresion = $"({new ExspressionNode(ns, maxdepth-1, _left, isusingid, table)})" +
                              $"{_operators[opchooser.GetRandom()]}" +
                              $"({new ExspressionNode(ns, maxdepth-1, _right, isusingid, table)})";
            }