Skip to content

Commit 499a2cd

Browse files
More coverage tweaks.
1 parent 93a20f5 commit 499a2cd

9 files changed

Lines changed: 76 additions & 18 deletions

source/ArrayPoolSegment.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Buffers;
3+
using System.Diagnostics.CodeAnalysis;
34

45
namespace Open.Collections;
56

@@ -22,13 +23,17 @@ public ArrayPoolSegment(
2223

2324
public void Dispose() => Pool?.Return(Segment.Array, _clear);
2425

25-
public static implicit operator ArraySegment<T> (ArrayPoolSegment<T> segment) => segment.Segment;
26-
public static implicit operator Memory<T> (ArrayPoolSegment<T> segment) => segment.Segment;
27-
public static implicit operator ReadOnlyMemory<T>(ArrayPoolSegment<T> segment) => segment.Segment;
26+
[ExcludeFromCodeCoverage]
27+
public static implicit operator ArraySegment<T> (ArrayPoolSegment<T> segment) => segment.Segment;
28+
[ExcludeFromCodeCoverage]
29+
public static implicit operator Memory<T> (ArrayPoolSegment<T> segment) => segment.Segment;
30+
[ExcludeFromCodeCoverage]
31+
public static implicit operator ReadOnlyMemory<T>(ArrayPoolSegment<T> segment) => segment.Segment;
2832
}
2933

3034
public static class ArrayPoolExtensions
3135
{
36+
[ExcludeFromCodeCoverage]
3237
public static ArrayPoolSegment<T> RentSegment<T>(
3338
this ArrayPool<T> pool,
3439
int length,

source/DictionaryToHashSetWrapper.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,18 @@ public class DictionaryToHashSetWrapper<T> : ISet<T>
99
{
1010
protected readonly IDictionary<T, bool> InternalSource;
1111

12-
// ReSharper disable once MemberCanBeProtected.Global
13-
public DictionaryToHashSetWrapper(IDictionary<T, bool> source)
12+
[ExcludeFromCodeCoverage]
13+
public DictionaryToHashSetWrapper(IDictionary<T, bool> source)
1414
=> InternalSource = source;
1515

16-
/// <inheritdoc />
17-
public int Count
16+
/// <inheritdoc />
17+
[ExcludeFromCodeCoverage]
18+
public int Count
1819
=> InternalSource.Count;
1920

20-
/// <inheritdoc />
21-
public bool IsReadOnly
21+
/// <inheritdoc />
22+
[ExcludeFromCodeCoverage]
23+
public bool IsReadOnly
2224
=> InternalSource.IsReadOnly;
2325

2426
/// <inheritdoc />

source/KeyValuePair.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
using System.Collections.Generic;
2+
using System.Diagnostics.CodeAnalysis;
3+
using System.Runtime.CompilerServices;
24

35
namespace Open.Collections;
46

57
public static class KeyValuePair
68
{
7-
public static KeyValuePair<TKey, TValue> Create<TKey, TValue>(TKey key, TValue value) => new(key, value);
9+
[ExcludeFromCodeCoverage]
10+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
11+
public static KeyValuePair<TKey, TValue> Create<TKey, TValue>(TKey key, TValue value) => new(key, value);
812
}

source/ListWrapper.cs

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

45
namespace Open.Collections;
@@ -12,6 +13,7 @@ public ListWrapper(TList source, bool owner = false)
1213
}
1314

1415
/// <inheritdoc />
16+
[ExcludeFromCodeCoverage]
1517
public virtual T this[int index]
1618
{
1719
get => InternalSource[index];
@@ -34,6 +36,7 @@ public virtual void RemoveAt(int index)
3436
=> InternalSource.RemoveAt(index);
3537
}
3638

39+
[ExcludeFromCodeCoverage]
3740
public class ListWrapper<T>
3841
: ListWrapper<T, IList<T>>
3942
{

source/OrderedDictionary.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@ public override TValue this[TKey key]
3232
}
3333

3434
/// <inheritdoc />
35+
[ExcludeFromCodeCoverage]
3536
public override ICollection<TKey> Keys => _keys.AsReadOnly();
3637

3738
/// <inheritdoc />
39+
[ExcludeFromCodeCoverage]
3840
public override ICollection<TValue> Values => _values.AsReadOnly();
3941

4042
/// <inheritdoc />

source/ReadOnlyCollectionWrapper.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ public virtual Span<T> CopyTo(Span<T> span)
7070
=> InternalSource.CopyToSpan(span);
7171

7272
/// <inheritdoc cref="ISynchronizedCollection&lt;T&gt;.Export(ICollection{T})" />
73+
74+
[ExcludeFromCodeCoverage]
7375
[MethodImpl(MethodImplOptions.AggressiveInlining)]
7476
public virtual void Export(ICollection<T> to)
7577
=> to.AddRange(InternalSource);

testing/Open.Collections.Tests/BasicCollectionTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using FluentAssertions;
22
using System;
3-
using System.Collections;
43
using System.Collections.Generic;
54
using System.Linq;
65
using Xunit;

testing/Open.Collections.Tests/LazyListTests.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,24 @@ public void LazyListSmokeTest()
1313
System.Collections.Generic.IEnumerable<int> e = Enumerable.Range(0, 5);
1414
Assert.Equal(5, e.Memoize().Count);
1515
Assert.Equal(5, e.MemoizeUnsafe().Count);
16+
Assert.True(e.Memoize().TryGetValueAt(1, out _));
17+
Assert.False(e.Memoize().TryGetValueAt(8, out _));
18+
Assert.False(e.MemoizeUnsafe().Contains(9));
1619

17-
Assert.Throws<InvalidOperationException>(() => e.Memoize(true).Count);
18-
}
20+
Assert.Throws<InvalidOperationException>(() => e.Memoize(true).IndexOf(9));
21+
Assert.Throws<InvalidOperationException>(() => e.Memoize(true).Count);
22+
Assert.Throws<ArgumentOutOfRangeException>(() => e.MemoizeUnsafe()[-1]);
23+
Assert.Throws<ArgumentOutOfRangeException>(() => e.MemoizeUnsafe().TryGetValueAt(-1, out _));
24+
Assert.Throws<ArgumentOutOfRangeException>(() => e.MemoizeUnsafe()[6]);
1925

20-
{
26+
int i = 0;
27+
foreach(int x in e.Memoize())
28+
{
29+
Assert.Equal(i++, x);
30+
}
31+
}
32+
33+
{
2134
System.Collections.Generic.IEnumerable<int> e = Enumerable.Range(0, 30);
2235
LazyList<int> a = e.Memoize();
2336
LazyListUnsafe<int> b = e.MemoizeUnsafe();

testing/Open.Collections.Tests/SubsetTests.cs

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Buffers;
12
using System.Collections.Immutable;
23
using System.Linq;
34
using Xunit;
@@ -71,11 +72,28 @@ public void TestSubset3_3()
7172
char[][] actual = Set3.Subsets(3).ToArray();
7273
Assert.Equal(expected, actual);
7374

75+
actual = Set3
76+
.Subsets(3, ArrayPool<char>.Shared, true)
77+
.Select(Selector).ToArray();
78+
Assert.Equal(expected, actual);
79+
7480
char[][] progressive = Set3.SubsetsProgressive(3).ToArray();
7581
Assert.Equal(expected, progressive);
76-
}
7782

78-
[Fact]
83+
progressive = Set3
84+
.SubsetsProgressive(3, ArrayPool<char>.Shared, true)
85+
.Select(Selector).ToArray();
86+
Assert.Equal(expected, progressive);
87+
}
88+
89+
static T[] Selector<T>(ArrayPoolSegment<T> e)
90+
{
91+
T[] a = e.Segment.ToArray();
92+
e.Dispose();
93+
return a;
94+
}
95+
96+
[Fact]
7997
public void TestSubset4_4()
8098
{
8199
int[][] expected = new int[][] {
@@ -88,9 +106,19 @@ public void TestSubset4_4()
88106
int[][] actual = Set4.Subsets(4).ToArray();
89107
Assert.Equal(expected, actual);
90108

109+
actual = Set4
110+
.Subsets(4, ArrayPool<int>.Shared)
111+
.Select(Selector).ToArray();
112+
Assert.Equal(expected, actual);
113+
91114
int[][] progressive = Set4.SubsetsProgressive(4).ToArray();
92-
Assert.Equal(expected, progressive);
93-
}
115+
Assert.Equal(expected, progressive);
116+
117+
progressive = Set4
118+
.SubsetsProgressive(4, ArrayPool<int>.Shared)
119+
.Select(Selector).ToArray();
120+
Assert.Equal(expected, progressive);
121+
}
94122

95123
[Fact]
96124
public void TestSubset4_3()

0 commit comments

Comments
 (0)