コード例 #1
0
            public void GroupToSpan_OutOfRange(long totalLength, int bufferLength, int spanLength)
            {
                using MemoryGroup <int> src = this.CreateTestGroup(totalLength, bufferLength, true);
                var trg = new int[spanLength];

                Assert.ThrowsAny <ArgumentOutOfRangeException>(() => src.CopyTo(trg));
            }
コード例 #2
0
            public void WhenTargetBufferTooShort_Throws()
            {
                using MemoryGroup <int> src = this.CreateTestGroup(10, 20, true);
                using MemoryGroup <int> trg = this.CreateTestGroup(5, 20, false);

                Assert.Throws <ArgumentOutOfRangeException>(() => src.CopyTo(trg));
            }
コード例 #3
0
            public void GroupToSpan_Success(long totalLength, int bufferLength, int spanLength)
            {
                using MemoryGroup <int> src = this.CreateTestGroup(totalLength, bufferLength, true);
                var trg = new int[spanLength];

                src.CopyTo(trg);

                int expected = 1;

                foreach (int val in trg.AsSpan().Slice(0, (int)totalLength))
                {
                    Assert.Equal(expected, val);
                    expected++;
                }
            }
コード例 #4
0
            public void WhenSourceBufferIsShorterOrEqual(int srcTotal, int srcBufLen, int trgTotal, int trgBufLen)
            {
                using MemoryGroup <int> src = this.CreateTestGroup(srcTotal, srcBufLen, true);
                using MemoryGroup <int> trg = this.CreateTestGroup(trgTotal, trgBufLen, false);

                src.CopyTo(trg);

                int pos            = 0;
                MemoryGroupIndex i = src.MinIndex();
                MemoryGroupIndex j = trg.MinIndex();

                for (; i < src.MaxIndex(); i += 1, j += 1, pos++)
                {
                    int a = src.GetElementAt(i);
                    int b = trg.GetElementAt(j);

                    Assert.True(a == b, $"Mismatch @ {pos} Expected: {a} Actual: {b}");
                }
            }