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))); }
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; }
public void ToStringIsCorrectForCancelledResult() { var result = RuntimeResult.CreateCancelledResult(TimeSpan.FromMilliseconds(42)); Assert.Equal( FormattableString.Invariant($"Cancelled after {TimeSpan.FromMilliseconds(42):G}"), result.ToString()); }
public void GetMetricRepresentationReturnsSecondsForSuccessfulRun() { var parSorter = new SortByRuntime(factorPar: 7); var result = new RuntimeResult(TimeSpan.FromSeconds(1234.78)); Assert.Equal( 1234.78, parSorter.GetMetricRepresentation(result)); }
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); }
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); } }
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()); }
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)); }
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); }
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); }
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); }
/// <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); }
public void IsCancelledIsFalseByDefault() { var result = new RuntimeResult(TimeSpan.FromMilliseconds(42)); Assert.False(result.IsCancelled, "Result is supposedly cancelled directly after construction."); }
public void RuntimeIsSetCorrectly() { var result = new RuntimeResult(TimeSpan.FromMilliseconds(42)); Assert.Equal(42, result.Runtime.TotalMilliseconds); }
/// <inheritdoc /> public double GetMetricRepresentation(RuntimeResult result) { var factor = result.IsCancelled ? this._factorPar : 1; return(factor * result.Runtime.TotalSeconds); }