< Summary - Syki

Information
Class: Syki.Shared.ListExtensions
Assembly: Shared
File(s): /home/runner/work/syki/syki/Shared/Extensions/ListExtensions.cs
Tag: 36_19195353031
Line coverage
89%
Covered lines: 34
Uncovered lines: 4
Coverable lines: 38
Total lines: 97
Line coverage: 89.4%
Branch coverage
80%
Covered branches: 24
Total branches: 30
Branch coverage: 80%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
IsSubsetOf(...)100%66100%
IsEquivalentTo(...)0%620%
IsAllDistinct(...)66.66%6683.33%
IsAllDistinct(...)66.66%6683.33%
ToAgendas(...)100%88100%
PickRandom(...)100%11100%
PickRandom(...)100%11100%
Shuffle(...)100%22100%

File(s)

/home/runner/work/syki/syki/Shared/Extensions/ListExtensions.cs

#LineLine coverage
 1namespace Syki.Shared;
 2
 3public static class ListExtensions
 4{
 5    public static bool IsSubsetOf(this List<Guid> selfs, List<Guid> others)
 6    {
 11667        HashSet<Guid> set = [];
 117568        foreach (var self in selfs)
 9        {
 492610            if (!set.Add(self)) return false;
 11
 532412            if (!others.Contains(self)) return false;
 13        }
 14
 75015        return true;
 41616    }
 17
 18    public static bool IsEquivalentTo(this List<Guid> selfs, List<Guid> others)
 19    {
 020        if (selfs.Count != others.Count) return false;
 21
 022        return selfs.IsSubsetOf(others);
 23    }
 24
 25    public static bool IsAllDistinct(this IEnumerable<int> list)
 26    {
 227        if (list is null) return true;
 28
 229        var set = new HashSet<int>();
 8030        foreach (var x in list)
 31        {
 3832            if (!set.Add(x)) return false;
 33        }
 34
 235        return true;
 036    }
 37
 38    public static bool IsAllDistinct(this IEnumerable<string> list)
 39    {
 240        if (list is null) return true;
 41
 242        var set = new HashSet<string>();
 8043        foreach (var x in list)
 44        {
 3845            if (!set.Add(x)) return false;
 46        }
 47
 248        return true;
 049    }
 50
 51    public static List<AgendaDayOut> ToAgendas(this List<EnrollmentClassOut> classes)
 52    {
 1253        var agendas = new List<AgendaDayOut>();
 54
 7655        foreach (var @class in classes)
 56        {
 11657            foreach (var schedule in @class.Schedules)
 58            {
 3259                var discipline = new AgendaDisciplineOut { ClassId = @class.Id, Name = @class.Discipline, Start = schedu
 60
 7261                var agenda = agendas.FirstOrDefault(a => a.Day == schedule.Day);
 3262                if (agenda == null)
 63                {
 2464                    agenda = new AgendaDayOut { Day = schedule.Day };
 2465                    agenda.Disciplines.Add(discipline);
 2466                    agendas.Add(agenda);
 2467                    continue;
 68                }
 69
 870                agenda.Disciplines.Add(discipline);
 71            }
 72        }
 73
 2874        agendas = agendas.OrderBy(a => a.Day).ToList();
 7275        foreach (var agenda in agendas)
 76        {
 3877            agenda.Disciplines = agenda.Disciplines.OrderBy(d => d.Start).ToList();
 78        }
 79
 1280        return agendas;
 81    }
 82
 83    public static T PickRandom<T>(this IEnumerable<T> source)
 84    {
 65885        return source.PickRandom(1).Single();
 86    }
 87
 88    public static IEnumerable<T> PickRandom<T>(this IEnumerable<T> source, int count)
 89    {
 67090        return source.Shuffle().Take(count);
 91    }
 92
 93    public static IEnumerable<T> Shuffle<T>(this IEnumerable<T> source)
 94    {
 282294095        return source.OrderBy(x => Guid.CreateVersion7());
 96    }
 97}