Skip to content

Commit c237de5

Browse files
committed
Added new tests for all IMemoryGroup<T> enumerators
1 parent ad69c23 commit c237de5

1 file changed

Lines changed: 32 additions & 2 deletions

File tree

tests/ImageSharp.Tests/Memory/DiscontiguousBuffers/MemoryGroupTests.cs

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
// Copyright (c) Six Labors and contributors.
1+
// Copyright (c) Six Labors and contributors.
22
// Licensed under the Apache License, Version 2.0.
33

44
using System;
55
using System.Buffers;
6+
using System.Collections;
7+
using System.Collections.Generic;
68
using System.Linq;
79
using System.Runtime.InteropServices;
810
using SixLabors.ImageSharp.Memory;
@@ -165,7 +167,7 @@ public void GetBoundedSlice_WhenOverlapsBuffers_Throws(long totalLength, int buf
165167
}
166168

167169
[Fact]
168-
public void Fill()
170+
public void FillWithFastEnumerator()
169171
{
170172
using MemoryGroup<int> group = this.CreateTestGroup(100, 10, true);
171173
group.Fill(42);
@@ -177,6 +179,34 @@ public void Fill()
177179
}
178180
}
179181

182+
[Fact]
183+
public void FillWithSlowGenericEnumerator()
184+
{
185+
using MemoryGroup<int> group = this.CreateTestGroup(100, 10, true);
186+
group.Fill(42);
187+
188+
int[] expectedRow = Enumerable.Repeat(42, 10).ToArray();
189+
IReadOnlyList<Memory<int>> groupAsList = group;
190+
foreach (Memory<int> memory in groupAsList)
191+
{
192+
Assert.True(memory.Span.SequenceEqual(expectedRow));
193+
}
194+
}
195+
196+
[Fact]
197+
public void FillWithSlowEnumerator()
198+
{
199+
using MemoryGroup<int> group = this.CreateTestGroup(100, 10, true);
200+
group.Fill(42);
201+
202+
int[] expectedRow = Enumerable.Repeat(42, 10).ToArray();
203+
IEnumerable groupAsList = group;
204+
foreach (Memory<int> memory in groupAsList)
205+
{
206+
Assert.True(memory.Span.SequenceEqual(expectedRow));
207+
}
208+
}
209+
180210
[Fact]
181211
public void Clear()
182212
{

0 commit comments

Comments
 (0)