コード例 #1
0
        public RuntimeResult InitializeBaseClass(Context ctx, Interpreter interpreter)
        {
            if (BaseClass != null)
            {
                ClassValue classValue = ((ClassValue)BaseClass).Clone();
                if (classValue.BaseClass != null)
                {
                    RuntimeResult baseResult = classValue.InitializeBaseClass(ctx, interpreter);
                    if (baseResult.HasError)
                    {
                        return(baseResult);
                    }

                    Context newContext = new Context(BaseName, baseResult.Value.Context);
                    classValue.SetPositionAndContext(Position, newContext);
                    newContext.AddSymbol("this", classValue);
                    newContext.AddSymbol("base", baseResult.Value);
                    return(interpreter.Visit(classValue.Body, newContext));
                }
                else
                {
                    Context newContext = new Context(BaseName, ctx);
                    classValue.SetPositionAndContext(Position, newContext);
                    newContext.AddSymbol("this", classValue);
                    return(interpreter.Visit(classValue.Body, newContext));
                }
            }
            return(new RuntimeResult(new RuntimeError(Position, "Base class '" + BaseName + "' not found!", ctx)));
        }
コード例 #2
0
        public async Task UserJoinedAsync(SocketGuildUser user)
        {
            _ = Task.Run(async() =>
            {
                RuntimeResult result = await VerifyAsync(user);

                // Send error if can open DM
                if (!result.IsSuccess)
                {
                    try
                    {
                        await user.SendMessageAsync(embed: new ErrorEmbed(result).Build());
                    }
                    catch (HttpException e)
                    {
                        switch (e.DiscordCode)
                        {
                        case 50007:
                            return;

                        default:
                            break;
                        }
                        throw;
                    }
                }
            });
            await Task.CompletedTask;
        }
コード例 #3
0
        public void ToStringIsCorrectForCancelledResult()
        {
            var result = RuntimeResult.CreateCancelledResult(TimeSpan.FromMilliseconds(42));

            Assert.Equal(
                FormattableString.Invariant($"Cancelled after {TimeSpan.FromMilliseconds(42):G}"),
                result.ToString());
        }
コード例 #4
0
        public void GetMetricRepresentationReturnsSecondsForSuccessfulRun()
        {
            var parSorter = new SortByRuntime(factorPar: 7);
            var result    = new RuntimeResult(TimeSpan.FromSeconds(1234.78));

            Assert.Equal(
                1234.78,
                parSorter.GetMetricRepresentation(result));
        }
コード例 #5
0
        public void TryToGetResultFromStringArrayWorksForRuntimeResults()
        {
            var runtimeResult          = new RuntimeResult(TimeSpan.FromSeconds(30));
            var targetAlgorithmFactory =
                new DummyTargetAlgorithmFactory <DummyTargetAlgorithm <TestInstance, RuntimeResult>, TestInstance, RuntimeResult>() as
                ITargetAlgorithmFactory <DummyTargetAlgorithm <TestInstance, RuntimeResult>, TestInstance, RuntimeResult>;

            targetAlgorithmFactory.TryToGetResultFromStringArray(runtimeResult.ToStringArray(), out var result).ShouldBeTrue();
            result.TargetAlgorithmStatus.ShouldBe(runtimeResult.TargetAlgorithmStatus);
            result.IsCancelled.ShouldBe(runtimeResult.IsCancelled);
            result.Runtime.ShouldBe(runtimeResult.Runtime);
        }
コード例 #6
0
 private static void WriteResult(RuntimeResult result)
 {
     Console.WriteLine("Result: " + result.Outcome);
     foreach (var n in result.Context.Notifications.Default.Notices)
     {
         // On fact concept, each notice has properties related to the invalid field
         var fact   = n.Properties["fact"];
         var member = n.Properties["member"];
         // If property definition in the Fact was an array
         // this would have had the index of the invalid item
         // var index = n.Properties["index "];
         Console.WriteLine("{0}: {1} ({2}.{3})", n.Type, n.Message, fact, member);
     }
 }
コード例 #7
0
        public override string ToString()
        {
            Value method = Context.GetSymbol("-str-");

            if (method == null)
            {
                return("<class-" + Name + ">");
            }
            RuntimeResult result = OperatorOverload("-str-");

            if (result.HasError)
            {
                return(result.Error.ToString());
            }
            return(result.Value.ToString());
        }
コード例 #8
0
        public override int GetElementCount()
        {
            RuntimeResult result = OperatorOverload("$len$");

            if (result.HasError)
            {
                Console.WriteLine(result.Error);
                return(0);
            }
            if (result.Value.Type != ValueType.INTEGER)
            {
                Console.WriteLine("RuntimeError: $len$ method should return an integer not " + result.Value.Type.ToString().ToLower());
                return(0);
            }
            return(Convert.ToInt32(result.Value.Data));
        }
コード例 #9
0
        public override bool GetAsBoolean()
        {
            RuntimeResult result = OperatorOverload("$bool$");

            if (result.HasError)
            {
                Console.WriteLine(result.Error);
                return(false);
            }
            if (result.Value.Type != ValueType.INTEGER)
            {
                Console.WriteLine("RuntimeError: $bool$ method should return a boolean or an integer not " + result.Value.Type.ToString().ToLower());
                return(false);
            }
            return(Convert.ToInt32(result.Value.Data) == 0 ? false : true);
        }
コード例 #10
0
        private bool doCompile()
        {
            if (compiledObject != null)
            {
                //no need to re-compile
                return(true);
            }

            string        code       = hiddenPrefix + lblCodePrefix.Text + txtCode.Text + lblCodeSuffix.Text + hiddenSuffix;
            List <string> references = new List <string>();

            string     appPath = Assembly.GetExecutingAssembly().CodeBase;
            UriBuilder uri     = new UriBuilder(appPath);
            string     path    = Uri.UnescapeDataString(uri.Path);

            path = Path.GetDirectoryName(path);

            references.Add(Path.Combine(path, "GeneticMarket.Base.dll"));
            references.Add(Path.Combine(path, "GeneticMarket.Common.dll"));
            references.Add(Path.Combine(path, "GeneticMarket.Logic.dll"));
            references.Add(Path.Combine(path, "GeneticMarket.BackEnd.dll"));
            references.Add(Path.Combine(path, "GeneticMarket.Core.dll"));



            RuntimeResult rr = RuntimeHelper.CompileCode(code, references);

            if (rr.Success == false)
            {
                MessageBox.Show(rr.ErrorMessage);
                return(false);
            }

            if (rr.CreatedObject == null)
            {
                MessageBox.Show("Error creating object");
                return(false);
            }

            compiledObject = rr.CreatedObject as IStrategyRefiner;

            return(true);
        }
コード例 #11
0
        public void ChangingValuesInCopyDoesNotChangeValuesInOriginal()
        {
            var original = TunerDataRecordTest.TunerDataRecord;
            var copy     = original.Copy();

            const double NewGrayBoxConfidence = 0.7;
            var          newFinalResult       = new RuntimeResult(TimeSpan.FromSeconds(15));

            copy.GrayBoxConfidence = NewGrayBoxConfidence;
            copy.FinalResult       = newFinalResult;

            original.GrayBoxConfidence.ShouldBe(TunerDataRecordTest.TunerDataRecord.GrayBoxConfidence);
            original.FinalResult.TargetAlgorithmStatus.ShouldBe(TunerDataRecordTest.TunerDataRecord.FinalResult.TargetAlgorithmStatus);
            original.FinalResult.IsCancelled.ShouldBe(TunerDataRecordTest.TunerDataRecord.FinalResult.IsCancelled);
            original.FinalResult.Runtime.ShouldBe(TunerDataRecordTest.TunerDataRecord.FinalResult.Runtime);

            copy.GrayBoxConfidence.ShouldBe(NewGrayBoxConfidence);
            copy.FinalResult.TargetAlgorithmStatus.ShouldBe(newFinalResult.TargetAlgorithmStatus);
            copy.FinalResult.IsCancelled.ShouldBe(newFinalResult.IsCancelled);
            copy.FinalResult.Runtime.ShouldBe(newFinalResult.Runtime);
        }
コード例 #12
0
        /// <summary>
        /// Creates genome stats for testing.
        /// </summary>
        /// <param name="genome">The genome.</param>
        /// <param name="instances">The instances.</param>
        /// <param name="indexToRuntime">The function to generate a runtime by <paramref name="instances"/> index.</param>
        /// <param name="numInstancesToUse">The number of instances to add to the stats from the given list.</param>
        /// <returns>The genome stats.</returns>
        private GenomeStats <TestInstance, RuntimeResult> CreateStats(
            ImmutableGenome genome,
            IReadOnlyList <TestInstance> instances,
            Func <int, TimeSpan> indexToRuntime,
            int?numInstancesToUse = null)
        {
            if (numInstancesToUse == null || numInstancesToUse > instances.Count)
            {
                numInstancesToUse = instances.Count;
            }

            var stats = new GenomeStats <TestInstance, RuntimeResult>(genome, Enumerable.Empty <TestInstance>(), instances);

            for (var i = 0; i < numInstancesToUse; i++)
            {
                var result = new RuntimeResult(indexToRuntime(i));
                stats.FinishInstance(instances[i], result);
            }

            return(stats);
        }
コード例 #13
0
        public void IsCancelledIsFalseByDefault()
        {
            var result = new RuntimeResult(TimeSpan.FromMilliseconds(42));

            Assert.False(result.IsCancelled, "Result is supposedly cancelled directly after construction.");
        }
コード例 #14
0
        public void RuntimeIsSetCorrectly()
        {
            var result = new RuntimeResult(TimeSpan.FromMilliseconds(42));

            Assert.Equal(42, result.Runtime.TotalMilliseconds);
        }
コード例 #15
0
        /// <inheritdoc />
        public double GetMetricRepresentation(RuntimeResult result)
        {
            var factor = result.IsCancelled ? this._factorPar : 1;

            return(factor * result.Runtime.TotalSeconds);
        }