< Summary

Information
Class: Pozitron.QuerySpecification.LikeMemoryEvaluator
Assembly: Pozitron.QuerySpecification
File(s): /home/runner/work/QuerySpecification/QuerySpecification/src/QuerySpecification/Evaluators/LikeMemoryEvaluator.cs
Tag: 44_11195777782
Line coverage
100%
Covered lines: 15
Uncovered lines: 0
Coverable lines: 15
Total lines: 42
Line coverage: 100%
Branch coverage
100%
Covered branches: 14
Total branches: 14
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor()100%11100%
.cctor()100%11100%
Evaluate()100%1616100%

File(s)

/home/runner/work/QuerySpecification/QuerySpecification/src/QuerySpecification/Evaluators/LikeMemoryEvaluator.cs

#LineLine coverage
 1namespace Pozitron.QuerySpecification;
 2
 3public class LikeMemoryEvaluator : IInMemoryEvaluator
 4{
 25    private LikeMemoryEvaluator() { }
 16    public static LikeMemoryEvaluator Instance = new();
 7
 8    public IEnumerable<T> Evaluate<T>(IEnumerable<T> source, Specification<T> specification)
 9    {
 10        // There are benchmarks in QuerySpecification.Benchmarks project.
 11        // This implementation was the most efficient one.
 12
 5813        var groups = specification.LikeExpressions.GroupBy(x => x.Group).ToList();
 14
 29615        foreach (var item in source)
 16        {
 11617            var match = true;
 35618            foreach (var group in groups)
 19            {
 7020                var matchOrGroup = false;
 24621                foreach (var like in group)
 22                {
 8023                    if (like.KeySelectorFunc(item)?.Like(like.Pattern) ?? false)
 24                    {
 5425                        matchOrGroup = true;
 5426                        break;
 27                    }
 28                }
 29
 7030                if ((match = match && matchOrGroup) is false)
 31                {
 32                    break;
 33                }
 34            }
 35
 11636            if (match)
 37            {
 10038                yield return item;
 39            }
 40        }
 3241    }
 42}

Methods/Properties

.ctor()
.cctor()
Evaluate()