Skip to content

Commit e0f63dd

Browse files
Code coverage tweaks.
1 parent 9ee8f9e commit e0f63dd

22 files changed

Lines changed: 102 additions & 74 deletions

benchmarking/Benchmarks/CollectionParallelBenchmark.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ protected override IEnumerable<TimedResult> TestOnceInternal()
2020
yield return TimedResult.Measure("Fill (.Add(item)) (In Parallel)",
2121
() => Parallel.For(0, TestSize, i => c.Add(_items[i])));
2222

23-
2423
yield return TimedResult.Measure("Enumerate (8 times)", () =>
2524
{
2625
for (int i = 0; i < 8; ++i)

source/CollectionWrapper.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
namespace Open.Collections;
66

7+
[ExcludeFromCodeCoverage]
78
public class CollectionWrapper<T, TCollection> : ReadOnlyCollectionWrapper<T, TCollection>, ICollection<T>
89
where TCollection : class, ICollection<T>
910
{
10-
[ExcludeFromCodeCoverage]
1111
public CollectionWrapper(TCollection source, bool owner = false)
1212
: base(source, owner)
1313
{
@@ -19,26 +19,22 @@ public CollectionWrapper(TCollection source, bool owner = false)
1919
/// The underlying object used for synchronization.
2020
/// This is exposed to allow for more complex synchronization operations.
2121
/// </summary>
22-
[ExcludeFromCodeCoverage]
2322
public object SyncRoot => Sync;
2423

2524
#region Implementation of ICollection<T>
2625

27-
[ExcludeFromCodeCoverage]
2826
[MethodImpl(MethodImplOptions.AggressiveInlining)]
2927
protected virtual void AddInternal(T item)
3028
=> InternalSource.Add(item);
3129

3230
/// <inheritdoc />
33-
[ExcludeFromCodeCoverage]
3431
[MethodImpl(MethodImplOptions.AggressiveInlining)]
3532
public virtual void Add(T item) => AddInternal(item);
3633

3734
/// <summary>Adds more than one item.</summary>
3835
/// <param name="item1">First item to add.</param>
3936
/// <param name="item2">Additional item to add.</param>
4037
/// <param name="items">Extended param items to add.</param>
41-
[ExcludeFromCodeCoverage]
4238
public virtual void AddThese(T item1, T item2, params T[] items)
4339
{
4440
AddInternal(item1);
@@ -53,7 +49,6 @@ public virtual void AddThese(T item1, T item2, params T[] items)
5349
/// An enumerable is potentially slow as it may be yielding to a process.
5450
/// </summary>
5551
/// <param name="items">The items to add.</param>
56-
[ExcludeFromCodeCoverage]
5752
[MethodImpl(MethodImplOptions.AggressiveInlining)]
5853
public virtual void AddRange(IEnumerable<T> items)
5954
{
@@ -62,19 +57,16 @@ public virtual void AddRange(IEnumerable<T> items)
6257
}
6358

6459
/// <inheritdoc />
65-
[ExcludeFromCodeCoverage]
6660
[MethodImpl(MethodImplOptions.AggressiveInlining)]
6761
public virtual void Clear()
6862
=> InternalSource.Clear();
6963

7064
/// <inheritdoc />
71-
[ExcludeFromCodeCoverage]
7265
[MethodImpl(MethodImplOptions.AggressiveInlining)]
7366
public virtual bool Remove(T item)
7467
=> InternalSource.Remove(item);
7568

7669
/// <inheritdoc />
77-
[ExcludeFromCodeCoverage]
7870
public override bool IsReadOnly
7971
=> InternalSource.IsReadOnly;
8072
#endregion

source/ConcurrentHashSet.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
using System.Collections.Concurrent;
22
using System.Collections.Generic;
3+
using System.Diagnostics.CodeAnalysis;
34

45
namespace Open.Collections;
56

7+
[ExcludeFromCodeCoverage]
68
public class ConcurrentHashSet<T> : DictionaryToHashSetWrapper<T>
79
{
810
public ConcurrentHashSet(IEnumerable<T>? intialValues = null)

source/DictionaryToHashSetWrapper.cs

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections;
33
using System.Collections.Generic;
4+
using System.Diagnostics.CodeAnalysis;
45

56
namespace Open.Collections;
67

@@ -37,31 +38,38 @@ public virtual bool Add(T item)
3738
return true;
3839
}
3940

40-
/// <inheritdoc />
41-
public bool Remove(T item) => InternalSource.Remove(item);
41+
/// <inheritdoc />
42+
[ExcludeFromCodeCoverage]
43+
public bool Remove(T item) => InternalSource.Remove(item);
4244

43-
/// <inheritdoc />
44-
public void Clear() => InternalSource.Clear();
45+
/// <inheritdoc />
46+
[ExcludeFromCodeCoverage]
47+
public void Clear() => InternalSource.Clear();
4548

46-
/// <inheritdoc />
47-
public bool Contains(T item) => InternalSource.ContainsKey(item);
49+
/// <inheritdoc />
50+
[ExcludeFromCodeCoverage]
51+
public bool Contains(T item) => InternalSource.ContainsKey(item);
4852

49-
/// <inheritdoc />
50-
public void CopyTo(T[] array, int arrayIndex) => InternalSource.Keys.CopyTo(array, arrayIndex);
53+
/// <inheritdoc />
54+
[ExcludeFromCodeCoverage]
55+
public void CopyTo(T[] array, int arrayIndex) => InternalSource.Keys.CopyTo(array, arrayIndex);
5156

52-
/// <inheritdoc cref="ReadOnlyCollectionWrapper{T, TCollection}.CopyTo(Span{T})"/>
53-
public virtual Span<T> CopyTo(Span<T> span) => InternalSource.Keys.CopyToSpan(span);
57+
/// <inheritdoc cref="ReadOnlyCollectionWrapper{T, TCollection}.CopyTo(Span{T})"/>
58+
[ExcludeFromCodeCoverage]
59+
public virtual Span<T> CopyTo(Span<T> span) => InternalSource.Keys.CopyToSpan(span);
5460

55-
/// <summary>
56-
/// Returns a copy of the underlying keys.
57-
/// </summary>
58-
public HashSet<T> ToHashSet() => new(InternalSource.Keys);
61+
/// <summary>
62+
/// Returns a copy of the underlying keys.
63+
/// </summary>
64+
[ExcludeFromCodeCoverage]
65+
public HashSet<T> ToHashSet() => new(InternalSource.Keys);
5966

60-
/// <inheritdoc />
61-
public IEnumerator<T> GetEnumerator() => InternalSource.Keys.GetEnumerator();
67+
/// <inheritdoc />
68+
[ExcludeFromCodeCoverage]
69+
public IEnumerator<T> GetEnumerator() => InternalSource.Keys.GetEnumerator();
6270

63-
/// <inheritdoc />
64-
public void ExceptWith(IEnumerable<T> other)
71+
/// <inheritdoc />
72+
public void ExceptWith(IEnumerable<T> other)
6573
{
6674
foreach (T? e in other) Remove(e);
6775
}
@@ -106,13 +114,15 @@ public void SymmetricExceptWith(IEnumerable<T> other)
106114
}
107115
}
108116

109-
/// <inheritdoc />
110-
public void UnionWith(IEnumerable<T> other)
117+
/// <inheritdoc />
118+
public void UnionWith(IEnumerable<T> other)
111119
{
112120
foreach (T? e in other) Add(e);
113121
}
114122

115-
void ICollection<T>.Add(T item) => Add(item);
123+
[ExcludeFromCodeCoverage]
124+
void ICollection<T>.Add(T item) => Add(item);
116125

117-
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
126+
[ExcludeFromCodeCoverage]
127+
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
118128
}

source/DictionaryWrapper.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
using System.Collections.Generic;
2+
using System.Diagnostics.CodeAnalysis;
23
using System.Runtime.CompilerServices;
34

45
namespace Open.Collections;
56

67
/// <inheritdoc />
8+
[ExcludeFromCodeCoverage]
79
public class DictionaryWrapper<TKey, TValue>
810
: CollectionWrapper<KeyValuePair<TKey, TValue>, IDictionary<TKey, TValue>>, IDictionary<TKey, TValue>
911
{

source/Extensions.Generic.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ public static void AddThese<T>(this ICollection<T> target, T a, T b, params T[]
5454
{
5555
target.Add(a);
5656
target.Add(b);
57-
target.AddRange(more);
57+
if(more.Length!=0)
58+
target.AddRange(more);
5859
}
5960

6061
public static int Remove<T>(this ICollection<T> target, IEnumerable<T> values)

source/LinkedList/LinkedList.Standard.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
using System.Collections.Generic;
2+
using System.Diagnostics.CodeAnalysis;
23

34
namespace Open.Collections;
45

56
public static class LinkedList
67
{
78
public class Standard<T> : LinkedList<T>, ILinkedList<T>
89
{
10+
[ExcludeFromCodeCoverage]
911
public Standard()
1012
{
1113
}
1214

13-
public Standard(IEnumerable<T> initial) : base(initial)
15+
[ExcludeFromCodeCoverage]
16+
public Standard(IEnumerable<T> initial) : base(initial)
1417
{
1518
}
1619

source/Queue/Extensions.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
using System.Collections.Concurrent;
22
using System.Collections.Generic;
3+
using System.Diagnostics.CodeAnalysis;
34

45
namespace Open.Collections;
56

67
public static partial class Extensions
78
{
8-
public static Queue<T> ToQueue<T>(this IEnumerable<T> source) => new(source);
9+
[ExcludeFromCodeCoverage]
910

10-
public static IEnumerable<T> AsDequeueingEnumerable<T>(this ConcurrentQueue<T> source)
11+
public static Queue<T> ToQueue<T>(this IEnumerable<T> source)
12+
=> new(source);
13+
14+
[ExcludeFromCodeCoverage]
15+
public static IEnumerable<T> AsDequeueingEnumerable<T>(this ConcurrentQueue<T> source)
1116
{
1217
while (source.TryDequeue(out T? entry))
1318
yield return entry;
1419
}
1520

16-
public static IEnumerable<T> AsDequeueingEnumerable<T>(this Queue<T> source)
21+
[ExcludeFromCodeCoverage]
22+
public static IEnumerable<T> AsDequeueingEnumerable<T>(this Queue<T> source)
1723
{
1824
while (source.Count != 0)
1925
yield return source.Dequeue();

source/Queue/Queue.Concurrent.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections.Concurrent;
2+
using System.Diagnostics.CodeAnalysis;
23

34
namespace Open.Collections;
45

@@ -7,8 +8,9 @@ public static partial class Queue
78
public class Concurrent<T> : ConcurrentQueue<T>, IQueue<T>
89
{
910
#if NETSTANDARD2_0
10-
/// <inheritdoc />
11-
public void Clear()
11+
/// <inheritdoc />
12+
[ExcludeFromCodeCoverage]
13+
public void Clear()
1214
{
1315
while (TryDequeue(out _)) { }
1416
}

source/Queue/Queue.Standard.cs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
using System.Collections.Generic;
2+
using System.Diagnostics.CodeAnalysis;
23

34
namespace Open.Collections;
45

56
public static partial class Queue
67
{
78
public class Standard<T> : Queue<T>, IQueue<T>
89
{
9-
protected Standard()
10+
[ExcludeFromCodeCoverage]
11+
protected Standard()
1012
{
1113
}
1214

13-
public Standard(IEnumerable<T> initial) : base(initial)
15+
[ExcludeFromCodeCoverage]
16+
public Standard(IEnumerable<T> initial) : base(initial)
1417
{
1518
}
1619

@@ -31,11 +34,17 @@ public virtual bool TryPeek(out T item)
3134
return ok;
3235
}
3336
#else
34-
/// <inheritdoc />
35-
public new virtual bool TryDequeue(out T item) => base.TryDequeue(out item);
37+
/* Allow for overriding. */
3638

37-
/// <inheritdoc />
38-
public new virtual bool TryPeek(out T item) => base.TryPeek(out item);
39+
/// <inheritdoc />
40+
[ExcludeFromCodeCoverage]
41+
public new virtual bool TryDequeue(out T item)
42+
=> base.TryDequeue(out item);
43+
44+
/// <inheritdoc />
45+
[ExcludeFromCodeCoverage]
46+
public new virtual bool TryPeek(out T item)
47+
=> base.TryPeek(out item);
3948
#endif
4049

4150
}

0 commit comments

Comments
 (0)