< Summary

Information
Class: Intentum.Simulation.IntentScenarioRunner
Assembly: Intentum.Simulation
File(s): /home/runner/work/Intentum/Intentum/src/Intentum.Simulation/IntentScenarioRunner.cs
Line coverage
100%
Covered lines: 29
Uncovered lines: 0
Coverable lines: 29
Total lines: 54
Line coverage: 100%
Branch coverage
95%
Covered branches: 19
Total branches: 20
Branch coverage: 95%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)50%22100%
RunAsync()100%44100%
BuildSpace(...)100%1414100%

File(s)

/home/runner/work/Intentum/Intentum/src/Intentum.Simulation/IntentScenarioRunner.cs

#LineLine coverage
 1using System.Diagnostics;
 2using Intentum.Core.Behavior;
 3using Intentum.Core.Contracts;
 4using Intentum.Runtime.Engine;
 5using Intentum.Runtime.Policy;
 6
 7namespace Intentum.Simulation;
 8
 9/// <summary>
 10/// Runs behavior scenarios through intent model and policy using BehaviorSpaceSimulator.
 11/// </summary>
 512public sealed class IntentScenarioRunner(IBehaviorSpaceSimulator simulator) : IScenarioRunner
 13{
 514    private readonly IBehaviorSpaceSimulator _simulator = simulator ?? throw new ArgumentNullException(nameof(simulator)
 15
 16    /// <inheritdoc />
 17    public async Task<IReadOnlyList<ScenarioRunResult>> RunAsync(
 18        IReadOnlyList<BehaviorScenario>? scenarios,
 19        IIntentModel model,
 20        IntentPolicy policy,
 21        CancellationToken cancellationToken = default)
 422    {
 423        var results = new List<ScenarioRunResult>();
 1924        foreach (var scenario in scenarios ?? [])
 425        {
 426            cancellationToken.ThrowIfCancellationRequested();
 27
 428            var space = BuildSpace(scenario);
 329            var sw = Stopwatch.StartNew();
 330            var intent = model.Infer(space);
 331            var decision = IntentPolicyEngine.Evaluate(intent, policy);
 332            sw.Stop();
 33
 334            results.Add(new ScenarioRunResult(
 335                scenario.Id,
 336                intent,
 337                decision,
 338                sw.Elapsed.TotalMilliseconds));
 339        }
 340        return await Task.FromResult(results).ConfigureAwait(false);
 341    }
 42
 43    private BehaviorSpace BuildSpace(BehaviorScenario scenario)
 444    {
 445        if (scenario.Sequence is { Count: > 0 })
 246        {
 447            var seq = scenario.Sequence.Select(t => (t.Actor, t.Action)).ToList();
 248            return _simulator.FromSequence(seq);
 49        }
 250        if (scenario is { Actors: { Count: > 0 }, Actions.Count: > 0 })
 151            return _simulator.GenerateRandom(scenario.Actors, scenario.Actions, scenario.EventCount, scenario.RandomSeed
 152        throw new ArgumentException($"Scenario {scenario.Id}: provide Sequence or (Actors + Actions).", nameof(scenario)
 353    }
 54}