• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

zorbathut / dec / 11709205202

06 Nov 2024 05:57PM UTC coverage: 90.198% (-0.4%) from 90.637%
11709205202

push

github

zorbathut
Added the ability to reference class objects contained within Decs.

4748 of 5264 relevant lines covered (90.2%)

194623.74 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

84.85
/src/UtilCollection.cs
1
using System;
2
using System.Collections.Generic;
3

4
namespace Dec
5
{
6
    internal static class UtilCollection
7
    {
8
        internal static V TryGetValue<T, V>(this Dictionary<T, V> dict, T key)
9
        {
1,771,039✔
10
            if (key == null)
1,771,039✔
11
            {
5✔
12
                return default(V);
5✔
13
            }
14

15
            dict.TryGetValue(key, out V holder);
1,771,034✔
16
            return holder;
1,771,034✔
17
        }
1,771,039✔
18

19
        internal static string ToCommaString(this IEnumerable<string> list)
20
        {
35✔
21
            string result = "";
35✔
22
            bool first = true;
35✔
23
            foreach (var str in list)
245✔
24
            {
70✔
25
                if (!first)
70✔
26
                {
35✔
27
                    result += ", ";
35✔
28
                }
35✔
29
                first = false;
70✔
30

31
                result += str;
70✔
32
            }
70✔
33
            return result;
35✔
34
        }
35✔
35

36
        internal static T SingleOrDefaultChecked<T>(this IEnumerable<T> elements)
37
        {
873,110✔
38
            T result = default(T);
873,110✔
39
            bool first = true;
873,110✔
40

41
            foreach (var element in elements)
4,361,110✔
42
            {
870,895✔
43
                if (first)
870,895✔
44
                {
870,885✔
45
                    result = element;
870,885✔
46
                    first = false;
870,885✔
47
                }
870,885✔
48
                else
49
                {
10✔
50
                    // maybe we need a better error message here.
51
                    Dbg.Err("Multiple items found when only one is expected");
10✔
52

53
                    // no point in continuing
54
                    break;
10✔
55
                }
56
            }
870,885✔
57

58
            return result;
873,110✔
59
        }
873,110✔
60

61
        internal static IEnumerable<T> Concat<T>(this IEnumerable<T> enumerable, T element)
62
        {
2,646✔
63
            foreach (var e in enumerable)
9,738✔
64
            {
900✔
65
                yield return e;
900✔
66
            }
900✔
67

68
            yield return element;
2,646✔
69
        }
2,646✔
70

71
        internal static int FirstIndexOf<T>(this IEnumerable<T> enumerable, Func<T, bool> func)
72
        {
700✔
73
            int index = 0;
700✔
74
            var enumerator = enumerable.GetEnumerator();
700✔
75

76
            while (enumerator.MoveNext())
2,000✔
77
            {
1,920✔
78
                if (func(enumerator.Current))
1,920✔
79
                {
620✔
80
                    return index;
620✔
81
                }
82

83
                ++index;
1,300✔
84
            }
1,300✔
85

86
            return -1;
80✔
87
        }
700✔
88

89
        internal static IEnumerable<T> FindDuplicates<T>(this IEnumerable<T> source)
90
        {
×
91
            var seen = new HashSet<T>();
×
92
            var duplicates = new HashSet<T>();
×
93

94
            foreach (var item in source)
×
95
            {
×
96
                if (!seen.Add(item))
×
97
                    duplicates.Add(item);
×
98
            }
×
99

100
            return duplicates;
×
101
        }
×
102
    }
103
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc