< Summary - Syki

Information
Class: Syki.Back.Shared.ListExtensions
Assembly: Back
File(s): /home/runner/work/syki/syki/Back/Shared/Extensions/ListExtensions.cs
Tag: 97_27801654829
Line coverage
59%
Covered lines: 26
Uncovered lines: 18
Coverable lines: 44
Total lines: 110
Line coverage: 59%
Branch coverage
61%
Covered branches: 22
Total branches: 36
Branch coverage: 61.1%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

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

File(s)

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

#LineLine coverage
 1namespace Syki.Back.Shared;
 2
 3public static class ListExtensions
 4{
 5    public static bool IsSubsetOf(this List<Guid> selfs, List<Guid> others)
 6    {
 4127        HashSet<Guid> set = [];
 12688        foreach (var self in selfs)
 9        {
 42810            if (!set.Add(self)) return false;
 11
 82012            if (!others.Contains(self)) return false;
 13        }
 14
 815        return true;
 40416    }
 17
 18    public static bool IsSubsetOf(this List<int> selfs, List<int> others)
 19    {
 3420        HashSet<int> set = [];
 43821        foreach (var self in selfs)
 22        {
 18623            if (!set.Add(self)) return false;
 24
 18825            if (!others.Contains(self)) return false;
 26        }
 27
 3228        return true;
 229    }
 30
 31    public static bool IsEquivalentTo(this List<Guid> selfs, List<Guid> others)
 32    {
 033        if (selfs.Count != others.Count) return false;
 34
 035        return selfs.IsSubsetOf(others);
 36    }
 37
 38    public static bool IsAllDistinct(this IEnumerable<int> list)
 39    {
 3640        if (list is null) return true;
 41
 3642        var set = new HashSet<int>();
 52243        foreach (var x in list)
 44        {
 22845            if (!set.Add(x)) return false;
 46        }
 47
 3448        return true;
 249    }
 50
 51    public static bool IsAllDistinct(this IEnumerable<string> list)
 52    {
 253        if (list is null) return true;
 54
 255        var set = new HashSet<string>();
 5656        foreach (var x in list)
 57        {
 2658            if (!set.Add(x)) return false;
 59        }
 60
 261        return true;
 062    }
 63
 64    public static List<AgendaDayOut> ToAgendas(this List<EnrollmentClassOut> classes)
 65    {
 066        var agendas = new List<AgendaDayOut>();
 67
 068        foreach (var @class in classes)
 69        {
 070            foreach (var schedule in @class.Schedules)
 71            {
 072                var discipline = new AgendaDisciplineOut { ClassId = @class.Id, Name = @class.Discipline, Start = schedu
 73
 074                var agenda = agendas.FirstOrDefault(a => a.Day == schedule.Day);
 075                if (agenda == null)
 76                {
 077                    agenda = new AgendaDayOut { Day = schedule.Day };
 078                    agenda.Disciplines.Add(discipline);
 079                    agendas.Add(agenda);
 080                    continue;
 81                }
 82
 083                agenda.Disciplines.Add(discipline);
 84            }
 85        }
 86
 087        agendas = agendas.OrderBy(a => a.Day).ToList();
 088        foreach (var agenda in agendas)
 89        {
 090            agenda.Disciplines = agenda.Disciplines.OrderBy(d => d.Start).ToList();
 91        }
 92
 093        return agendas;
 94    }
 95
 96    public static T PickRandom<T>(this IEnumerable<T> source)
 97    {
 58498        return source.PickRandom(1).Single();
 99    }
 100
 101    public static IEnumerable<T> PickRandom<T>(this IEnumerable<T> source, int count)
 102    {
 584103        return source.Shuffle().Take(count);
 104    }
 105
 106    public static IEnumerable<T> Shuffle<T>(this IEnumerable<T> source)
 107    {
 9052108        return source.OrderBy(x => Guid.CreateVersion7());
 109    }
 110}