Example #1
0
        protected override void RenderAbstractFunction(AbstractFunction function)
        {
            var visibility = function.AccessModifier.ToString().ToLower();
            var rt         = RenderAbstractDataType(function.ReturnType);
            var args       = string.Join(", ", function.Arguments.Select(a => RenderAbstractVariableDefinition(a)));
            var method     = GetHttpMethod(function.Node.Method);
            var fname      = function.Name.ToProperCase().ToPascalCase();
            var prefix     = _activeConfig.Prefix;
            var url        = function.Node.Url;

            WriteIndented($"{visibility} {rt} {fname}({args})");
            WriteIndented("{");
            _indentLevel++;
            WriteIndented(
                _rendererExtension.RenderAbstractFunction(
                    url,
                    prefix,
                    rt,
                    method,
                    function.Node.Args.Select(a => a.Name).ToList()
                    )
                );
            _indentLevel--;
            WriteIndented("}");
        }
Example #2
0
 public static void ClearStaticFields()
 {
     function           = null;
     FoodSourceList     = null;
     GlobalBestPosition = null;
     GlobalBestFitness  = 0;
 }
        /// <summary>
        /// Remove some basic line that SR doesn't need.
        /// </summary>
        /// <param name="instance">The function.</param>
        public static List <string> RemoveBannedFunction(AbstractFunction instance)
        {
            List <string> new_lines = new List <string>();
            bool          skip      = true;

            foreach (string line in instance.Lines ?? Enumerable.Empty <string>())
            {
                if (skip)
                {
                    skip = false; new_lines.Add(line); continue;
                }
                bool delete = false;

                if (BannedFunction.List.Any(l => line.Contains(l, StringComparison.InvariantCultureIgnoreCase)))
                {
                    delete = true;
                }

                if (delete)
                {
                    new_lines.Add("//AUTO " + line);
                }
                else
                {
                    new_lines.Add(line);
                }
            }
            return(new_lines);
        }
        public InterpretedClosure(Env env, AbstractFunction fun, Value qThis)
        {
            super(fun.getName(), qThis);

            _fun = fun;

            Arg [] args = fun.getClosureUseArgs();
            if (args != null && args.length > 0)
            {
                _args = new Value[args.length];

                for (int i = 0; i < args.length; i++)
                {
                    Arg arg = args[i];

                    if (arg.isReference())
                    {
                        _args[i] = env.getRef(arg.getName());
                    }
                    else
                    {
                        _args[i] = env.getValue(arg.getName());
                    }
                }
            }
            else
            {
                _args = null;
            }
        }
Example #5
0
        private void btnExecuteTest_Click(object sender, EventArgs e)
        {
            ofdFile.InitialDirectory = _testSutieFilesDir;

            if (ofdFile.ShowDialog() == DialogResult.OK)
            {
                var testSuite   = GetTestSuiteInfoFromTestSuiteFile(ofdFile.FileName);
                var testSummery = testSuite.TestSummery;

                var assertions = testSuite.TestCases.SelectMany(c => c.Assertions).ToList();
                _function = AbstractFunction.CreateInstance(testSuite.FunctionName);
                GenerateUnitTestFile(testSuite);

                foreach (var assertion in assertions)
                {
                    assertion.ActualOutput = _function.OriginalFunction(assertion.InputValues.ToArray());
                    assertion.Result       = assertion.ActualOutput == assertion.ExpectedOutput ? "Passed" : "Failed";
                }

                testSummery.Executed = assertions.Count;
                testSummery.Passed   = assertions.Count(a => a.Result == "Passed");
                testSummery.Failed   = assertions.Count(a => a.Result == "Failed");

                GenerateTestSuiteFile(testSuite);
            }
        }
Example #6
0
        public void close()
        {
            QuercusClass cls = _wrapper.getQuercusClass();

            if (cls != null)
            {
                StringValue funName;

                if (_env.isUnicodeSemantics())
                {
                    funName = STREAM_CLOSE_U;
                }
                else
                {
                    funName = STREAM_CLOSE;
                }

                AbstractFunction fun = cls.findFunction(funName);

                if (fun == null)
                {
                    //_env.warning(L.l("{0}::{1} @is not implemented", cls.getName(), funName));

                    return;
                }

                _wrapper.callMethod(_env, funName);
            }
        }
Example #7
0
        private void LoadParameters()
        {
            _gaParameters.ChromosomeQuantity             = Convert.ToInt32(txtChromosomeQuantity.Text);
            _gaParameters.ChromosomeLengthForOneSubValue = Convert.ToInt32(txtChromosomeLength.Text);
            _gaParameters.RetainRate         = Convert.ToDouble(txtRetainRate.Text) / 100;
            _gaParameters.MutationRate       = Convert.ToDouble(txtMutationRate.Text) / 100;
            _gaParameters.SelectionRate      = Convert.ToDouble(txtSelectionRate.Text) / 100;
            _gaParameters.GenerationQuantity = Convert.ToInt32(txtGenerationQuantity.Text);
            _gaParameters.SelectionType      = (Population.SelectionType)Enum.Parse(typeof(Population.SelectionType),
                                                                                    cmbStrategy.SelectedValue.ToString());
            //读取文本框中所有的期望路径
            _targetPaths = GetTargetPaths();
            //被测函数
            _function = AbstractFunction.CreateInstance(cmbFunction.SelectedValue.ToString());
            //被测函数适应度计算方法
            _function.FitnessCaculationType = (AbstractFunction.FitnessType)Enum.Parse(
                typeof(AbstractFunction.FitnessType),
                cmbFitnessCaculationType.SelectedValue.ToString());
            //被测函数参数列表(_paras 中的项目由 AddFunctionPara() 或 LoadSettings() 添加)

            _paras = GetParas();

            _function.Paras = _paras;
            //设定被测函数用于匹配的路径为第一条路径
            _function.TargetPath = _targetPaths[0];
        }
        /**
         * Evaluates the expression.
         *
         * @param env the calling environment.
         *
         * @return the expression value.
         */
        public Value eval(Env env)
        {
            QuercusClass cl = env.findClass(_className);

            if (cl == null)
            {
                throw env.createErrorException(L.l("{0} @is an unknown class",
                                                   _className));
            }

            StringValue nameV = _nameV;

            AbstractFunction fun = cl.getFunction(nameV);

            Value [] values = evalArgs(env, _args);

            Value qThis = env.getThis();

            env.pushCall(this, qThis, values);

            try {
                env.checkTimeout();

                return(cl.callMethod(env, qThis, nameV, nameV.hashCode(), values));
            } finally {
                env.popCall();
            }
        }
Example #9
0
        /// <summary>
        /// Remove all teleports delay.
        /// </summary>
        /// <param name="instance">The function.</param>
        public static List <string> RemoveTeleportsDelay(AbstractFunction instance)
        {
            if (BannedMainFunction.List.Any(l => instance.Name.Contains(l, StringComparison.InvariantCultureIgnoreCase)) ||
                instance.Lines.Any(l => l.Contains("level.activ", StringComparison.InvariantCultureIgnoreCase)))
            {
                return(instance.Lines);
            }

            List <string> new_lines = new List <string>();
            bool          waittill  = false;

            foreach (string line in instance.Lines ?? Enumerable.Empty <string>())
            {
                if (line.Contains("waittill"))
                {
                    waittill = true;
                }
                if (waittill && line.Contains("wait ", StringComparison.InvariantCultureIgnoreCase) ||
                    line.Contains("wait(", StringComparison.InvariantCultureIgnoreCase))
                {
                    new_lines.Add("//AUTO " + line);
                }
                else
                {
                    new_lines.Add(line);
                }
            }
            return(new_lines);
        }
Example #10
0
        public void SetFunction(string name, AbstractFunction function)
        {
            _expressionCache.Clear();
            var interpreter = GetInterpreter();

            interpreter.SetFunction(name, function);
        }
        protected ReflectionParameter(String clsName,
                                      AbstractFunction fun,
                                      Arg arg)
        {
            this(fun, arg);

            _clsName = clsName;
        }
Example #12
0
 public Layer(int inputsNumber, int numberOfNeurons, AbstractFunction activationFunction)
 {
     neurons = new List <Neuron>();
     for (int i = 0; i < numberOfNeurons; i++)
     {
         neurons.Add(new Neuron(inputsNumber + 1, activationFunction));
     }
 }
Example #13
0
        public static void ClearStaticFields()
        {
            GlobalBest    = 0;
            PositionGBest = null;

            function     = null;
            constriction = null;
        }
Example #14
0
 public void UpdateAttractiveness(FireflyParticle a)
 {
     if (a.PersonalBestFitness < this.PersonalBestFitness)
     {
         double distance    = AbstractFunction.EuclidianDistance(a.PersonalBestPosition, this.Position);
         double exponential = Math.Pow(Math.E, -LuciferinProductionCoefficient * distance);
         Attractiveness = AttractivenessFactor * exponential;
     }
 }
        public AbstractFunction getFunction(Env env)
        {
            if (_fun == null)
            {
                _fun = env.getFunction(_funName);
            }

            return(_fun);
        }
        private AbstractMailrelayReply TestCall(AbstractFunction functionToCall)
        {
            AbstractMailrelayReply reply = _mailrelayConnection.Send(functionToCall);

            Console.Out.WriteLine(functionToCall.ToGet());
            Console.Out.WriteLine(reply.ToJson());

            return(reply);
        }
Example #17
0
 // Copy the weights of a given neuron
 public Neuron(Neuron neuronToClone)
 {
     this.weights            = new List <double>();
     this.activationFunction = neuronToClone.getActivationFunction();
     for (int i = 0; i < neuronToClone.getWeights().Count; i++)
     {
         this.weights.Add(neuronToClone.getWeights()[i]);
     }
 }
Example #18
0
        public void cleanup(Env env)
        {
            QuercusClass     qClass = getQuercusClass();
            AbstractFunction fun    = qClass.getDestructor();

            if (fun != null)
            {
                fun.callMethod(env, qClass, this);
            }
        }
        public override bool isValid(Env env)
        {
            if (_fun != null)
            {
                return(true);
            }

            _fun = env.findFunction(_funName);

            return(_fun != null);
        }
Example #20
0
        // Return an array containing the Values to be
        // passed in to this function.

        public Value [] evalArguments(Env env)
        {
            AbstractFunction fun = env.findFunction(_name);

            if (fun == null)
            {
                return(null);
            }

            return(fun.evalArguments(env, this, _args));
        }
Example #21
0
        public override Arg [] getArgs(Env env)
        {
            AbstractFunction fun = _quercusClass.getInvoke();

            if (fun == null)
            {
                return(null);
            }

            return(fun.getArgs(env));
        }
Example #22
0
        private void AssertToGet(AbstractFunction function, string expectedEncoded)
        {
            string apiKey             = "testApiKey";
            string expectedUrlEncoded = $"{expectedEncoded}&apiKey={apiKey}";

            function.apiKey = apiKey;

            string output = function.ToGet();

            Assert.AreEqual(expectedUrlEncoded, output);
        }
        protected void init()
        {
            _isInit = true;

            AbstractFunction fun = _classDef.getFunction(_methodName);

            if (fun != null && fun.isPrivate())
            {
                _fun = fun;
            }
        }
        /**
         * Evaluates the function.
         */
        public Value call(Env env, Value [] args)
        {
            if (_globalId > 0)
            {
                AbstractFunction fun = env._fun[_globalId];
                env._fun[_id] = fun;

                return(fun.call(env, args));
            }

            return(env.error(L.l("'{0}' @is an unknown function.", _name)));
        }
Example #25
0
        public FireflyParticle(EFunction functionType)
        {
            Alpha = 1.0d;

            Position = new double[Parameters.DIMENSION_AMOUNT];

            if (function == null)
            {
                FireflyParticle.functionType = functionType;
                function = AbstractFunction.InstanceFunction(functionType);
            }
        }
Example #26
0
        public Bee(EFunction functionType, EBee beeType)
        {
            Position     = new double[Parameters.DIMENSION_AMOUNT];
            this.beeType = beeType;

            if (function == null)
            {
                FoodSourceList   = new List <FoodSource>();
                Bee.functionType = functionType;
                function         = AbstractFunction.InstanceFunction(functionType);
            }
        }
Example #27
0
        public AbstractPSOParticle(EFunction functionType, EConstrictionFactor constrictionType)
        {
            Position = new double[Parameters.DIMENSION_AMOUNT];
            Velocity = new double[Parameters.DIMENSION_AMOUNT];

            if (function == null || constriction == null)
            {
                AbstractPSOParticle.functionType     = functionType;
                AbstractPSOParticle.constrictionType = constrictionType;
                function     = AbstractFunction.InstanceFunction(functionType);
                constriction = AbstractConstrictionFactor.InstanceFunction(constrictionType);
            }
        }
        public AbstractMailrelayReply Send(AbstractFunction functionToSend)
        {
            if (replies.Count == 0)
            {
                throw new Exception($"reply queue was empty when sending {HttpUtility.UrlDecode(functionToSend.ToGet())}");
            }

            sendFunctions.Add(functionToSend);

            AbstractMailrelayReply reply = replies.Dequeue();

            return(reply);
        }
Example #29
0
        public ReflectionMethod getConstructor()
        {
            AbstractFunction cons = _cls.getConstructor();

            if (cons != null)
            {
                return(new ReflectionMethod(_name, cons));
            }
            else
            {
                return(null);
            }
        }
Example #30
0
        /**
         * Finds a function.
         */
        public AbstractFunction findFunction(StringValue name)
        {
            AbstractFunction fun = _funMap.get(name);

            if (fun != null)
            {
                return(fun);
            }

            fun = _funMapLowerCase.get(name.toLowerCase(Locale.ENGLISH));

            return(fun);
        }