From cfd21c6c96d21556a2aaaef20d06d0dd34b066e3 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sat, 21 Mar 2026 17:17:16 +0000 Subject: [PATCH] test: add happy path tests for ArenaBlockList.GetSpan() Add unit tests to verify: - GetSpan() returns an empty span for an empty list. - GetSpan() returns a correct span for a single-block list. - GetSpan() correctly consolidates data from multiple blocks into a single contiguous span. Co-authored-by: myarichuk <1473701+myarichuk@users.noreply.github.com> --- .../Collections/ArenaBlockTests.cs | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/tests/SharpArena.Tests/Collections/ArenaBlockTests.cs b/tests/SharpArena.Tests/Collections/ArenaBlockTests.cs index 51f1c56..b0848e2 100644 --- a/tests/SharpArena.Tests/Collections/ArenaBlockTests.cs +++ b/tests/SharpArena.Tests/Collections/ArenaBlockTests.cs @@ -157,4 +157,56 @@ public void StructCopy_SharesState() Assert.Equal(new[] { 1, 2, 3 }, elements1); Assert.Equal(new[] { 1, 2, 3 }, elements2); } + + [Fact] + public void GetSpan_EmptyList_ReturnsEmptySpan() + { + var list = new ArenaBlockList(_arena); + var span = list.GetSpan(); + Assert.True(span.IsEmpty); + Assert.Equal(0, span.Length); + } + + [Fact] + public void GetSpan_SingleBlock_ReturnsCorrectSpan() + { + var list = new ArenaBlockList(_arena, blockSize: 10); + for (int i = 0; i < 5; i++) + { + list.Add(i); + } + + var span = list.GetSpan(); + Assert.Equal(5, span.Length); + for (int i = 0; i < 5; i++) + { + Assert.Equal(i, span[i]); + } + } + + [Fact] + public void GetSpan_MultipleBlocks_ReturnsContiguousSpan() + { + // Use a small block size to force multiple blocks + var list = new ArenaBlockList(_arena, blockSize: 2); + + // This will create blocks of size 2, 4, 8, 16... + // 2 + 4 + 8 = 14. Adding 15 elements should use at least 3-4 blocks. + for (int i = 0; i < 15; i++) + { + list.Add(i); + } + + var span = list.GetSpan(); + Assert.Equal(15, span.Length); + + for (int i = 0; i < 15; i++) + { + Assert.Equal(i, span[i]); + } + + // Verify it is indeed contiguous and correctly copied from multiple blocks + var expected = Enumerable.Range(0, 15).ToArray(); + Assert.True(span.SequenceEqual(expected)); + } }