< Summary - Syki

Information
Class: Syki.Back.Shared.ListExtensions
Assembly: Back
File(s): /home/runner/work/syki/syki/Back/Shared/Extensions/ListExtensions.cs
Tag: 56_26538939494
Line coverage
52%
Covered lines: 23
Uncovered lines: 21
Coverable lines: 44
Total lines: 110
Line coverage: 52.2%
Branch coverage
52%
Covered branches: 19
Total branches: 36
Branch coverage: 52.7%
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(...)33.33%11650%
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    {
 420        HashSet<int> set = [];
 821        foreach (var self in selfs)
 22        {
 023            if (!set.Add(self)) return false;
 24
 025            if (!others.Contains(self)) return false;
 26        }
 27
 428        return true;
 029    }
 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    {
 1440        if (list is null) return true;
 41
 1442        var set = new HashSet<int>();
 9843        foreach (var x in list)
 44        {
 3845            if (!set.Add(x)) return false;
 46        }
 47
 1248        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>();
 4856        foreach (var x in list)
 57        {
 2258            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    {
 53698        return source.PickRandom(1).Single();
 99    }
 100
 101    public static IEnumerable<T> PickRandom<T>(this IEnumerable<T> source, int count)
 102    {
 536103        return source.Shuffle().Take(count);
 104    }
 105
 106    public static IEnumerable<T> Shuffle<T>(this IEnumerable<T> source)
 107    {
 8308108        return source.OrderBy(x => Guid.CreateVersion7());
 109    }
 110}