public void RefersToOwnerGroupContent() { using MemoryGroup <int> group = this.CreateTestGroup(240, 80, true); MemoryGroupView <int> view = group.View; Assert.True(view.IsValid); Assert.Equal(group.Count, view.Count); Assert.Equal(group.BufferLength, view.BufferLength); Assert.Equal(group.TotalLength, view.TotalLength); int cnt = 1; foreach (Memory <int> memory in view) { Span <int> span = memory.Span; foreach (int t in span) { Assert.Equal(cnt, t); cnt++; } } }
public void WhenBothAreMemoryOwners_ShouldReplaceViews() { using Buffer2D <int> a = this.MemoryAllocator.Allocate2D <int>(100, 1); using Buffer2D <int> b = this.MemoryAllocator.Allocate2D <int>(100, 2); a.FastMemoryGroup[0].Span[42] = 1; b.FastMemoryGroup[0].Span[33] = 2; MemoryGroupView <int> aView0 = (MemoryGroupView <int>)a.MemoryGroup; MemoryGroupView <int> bView0 = (MemoryGroupView <int>)b.MemoryGroup; Buffer2D <int> .SwapOrCopyContent(a, b); Assert.False(aView0.IsValid); Assert.False(bView0.IsValid); Assert.ThrowsAny <InvalidOperationException>(() => _ = aView0[0].Span); Assert.ThrowsAny <InvalidOperationException>(() => _ = bView0[0].Span); Assert.True(a.MemoryGroup.IsValid); Assert.True(b.MemoryGroup.IsValid); Assert.Equal(2, a.MemoryGroup[0].Span[33]); Assert.Equal(1, b.MemoryGroup[0].Span[42]); }
public void WhenBothAreMemoryOwners_ShouldReplaceViews() { using MemoryGroup <int> a = this.MemoryAllocator.AllocateGroup <int>(100, 100); using MemoryGroup <int> b = this.MemoryAllocator.AllocateGroup <int>(120, 100); a[0].Span[42] = 1; b[0].Span[33] = 2; MemoryGroupView <int> aView0 = a.View; MemoryGroupView <int> bView0 = b.View; MemoryGroup <int> .SwapOrCopyContent(a, b); Assert.False(aView0.IsValid); Assert.False(bView0.IsValid); Assert.ThrowsAny <InvalidOperationException>(() => _ = aView0[0].Span); Assert.ThrowsAny <InvalidOperationException>(() => _ = bView0[0].Span); Assert.True(a.View.IsValid); Assert.True(b.View.IsValid); Assert.Equal(2, a.View[0].Span[33]); Assert.Equal(1, b.View[0].Span[42]); }