< Summary

Information
Class: Intentum.Core.Batch.BatchIntentModel
Assembly: Intentum.Core
File(s): /home/runner/work/Intentum/Intentum/src/Intentum.Core/Batch/BatchIntentModel.cs
Line coverage
95%
Covered lines: 23
Uncovered lines: 1
Coverable lines: 24
Total lines: 47
Line coverage: 95.8%
Branch coverage
66%
Covered branches: 8
Total branches: 12
Branch coverage: 66.6%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)50%22100%
InferBatch(...)75%44100%
InferBatchAsync()50%4485.71%
>c__DisplayClass3_0/<<InferBatchAsync()100%22100%

File(s)

/home/runner/work/Intentum/Intentum/src/Intentum.Core/Batch/BatchIntentModel.cs

#LineLine coverage
 1using Intentum.Core.Behavior;
 2using Intentum.Core.Contracts;
 3using Intentum.Core.Intents;
 4
 5namespace Intentum.Core.Batch;
 6
 7/// <summary>
 8/// Batch intent model that processes multiple behavior spaces efficiently.
 9/// </summary>
 10public sealed class BatchIntentModel : IBatchIntentModel
 11{
 12    private readonly IIntentModel _innerModel;
 13
 414    public BatchIntentModel(IIntentModel innerModel)
 415    {
 416        _innerModel = innerModel ?? throw new ArgumentNullException(nameof(innerModel));
 417    }
 18
 19    public IReadOnlyList<Intent> InferBatch(IReadOnlyCollection<BehaviorSpace>? behaviorSpaces)
 220    {
 221        if (behaviorSpaces == null || behaviorSpaces.Count == 0)
 122            return [];
 23
 124        return behaviorSpaces
 325            .Select(space => _innerModel.Infer(space))
 126            .ToList();
 227    }
 28
 29    public async Task<IReadOnlyList<Intent>> InferBatchAsync(
 30        IReadOnlyCollection<BehaviorSpace>? behaviorSpaces,
 31        CancellationToken cancellationToken = default)
 232    {
 233        if (behaviorSpaces == null || behaviorSpaces.Count == 0)
 034            return [];
 35
 236        var tasks = behaviorSpaces.Select(async space =>
 537        {
 538            cancellationToken.ThrowIfCancellationRequested();
 339            await Task.Yield(); // Allow async context switching
 340            cancellationToken.ThrowIfCancellationRequested();
 341            return _innerModel.Infer(space);
 542        });
 43
 244        var results = await Task.WhenAll(tasks);
 145        return results.ToList();
 146    }
 47}