Esempio n. 1
0
        public void RangedBufferEquivalenceAndImplicitCastsAreEqual(byte[] bytes, int start, int length)
        {
            var buffer         = new Buffer <byte>(bytes, start, length);
            var readOnlyBuffer = new ReadOnlyBuffer <byte>(bytes, start, length);
            ReadOnlyBuffer <byte> implicitReadOnlyBuffer = buffer;

            Assert.True(readOnlyBuffer.Equals(buffer));
            Assert.True(implicitReadOnlyBuffer.Equals(buffer));

            Assert.True(buffer.Equals(readOnlyBuffer));
            Assert.True(implicitReadOnlyBuffer.Equals(readOnlyBuffer));

            Assert.True(buffer.Equals(implicitReadOnlyBuffer));
            Assert.True(readOnlyBuffer.Equals(implicitReadOnlyBuffer));
        }
Esempio n. 2
0
        private static void BuffersReferencingSameMemoryAreEqualInEveryAspect(ref ReadOnlyBuffer <byte> buffer, ref ReadOnlyBuffer <byte> pointingToSameMemory)
        {
            Assert.True(buffer.Equals(pointingToSameMemory));
            Assert.True(pointingToSameMemory.Equals(buffer));

            Assert.True(buffer.SequenceEqual(pointingToSameMemory));
            Assert.True(pointingToSameMemory.SequenceEqual(buffer));
            Assert.True(buffer.SequenceEqual(pointingToSameMemory));
            Assert.True(pointingToSameMemory.SequenceEqual(buffer));
        }
Esempio n. 3
0
        public void BufferArrayEquivalenceAndImplicitCastsAreEqual(byte[] bytes)
        {
            var buffer         = new Buffer <byte>(bytes);
            var readOnlyBuffer = new ReadOnlyBuffer <byte>(bytes);
            ReadOnlyBuffer <byte> implicitReadOnlyBuffer      = buffer;
            Buffer <byte>         implicitBufferArray         = bytes;
            ReadOnlyBuffer <byte> implicitReadOnlyBufferArray = bytes;

            Assert.True(buffer.Equals(bytes));
            Assert.True(readOnlyBuffer.Equals(bytes));
            Assert.True(implicitReadOnlyBuffer.Equals(bytes));
            Assert.True(implicitBufferArray.Equals(bytes));
            Assert.True(implicitReadOnlyBufferArray.Equals(bytes));

            Assert.True(readOnlyBuffer.Equals(buffer));
            Assert.True(implicitReadOnlyBuffer.Equals(buffer));
            Assert.True(implicitBufferArray.Equals(buffer));
            Assert.True(implicitReadOnlyBufferArray.Equals(buffer));

            Assert.True(buffer.Equals(readOnlyBuffer));
            Assert.True(implicitReadOnlyBuffer.Equals(readOnlyBuffer));
            Assert.True(implicitBufferArray.Equals(readOnlyBuffer));
            Assert.True(implicitReadOnlyBufferArray.Equals(readOnlyBuffer));

            Assert.True(buffer.Equals(implicitBufferArray));
            Assert.True(readOnlyBuffer.Equals(implicitBufferArray));
            Assert.True(implicitReadOnlyBuffer.Equals(implicitBufferArray));
            Assert.True(implicitReadOnlyBufferArray.Equals(implicitBufferArray));

            Assert.True(buffer.Equals(implicitReadOnlyBuffer));
            Assert.True(readOnlyBuffer.Equals(implicitReadOnlyBuffer));
            Assert.True(implicitBufferArray.Equals(implicitReadOnlyBuffer));
            Assert.True(implicitReadOnlyBufferArray.Equals(implicitReadOnlyBuffer));

            Assert.True(buffer.Equals(implicitReadOnlyBufferArray));
            Assert.True(readOnlyBuffer.Equals(implicitReadOnlyBufferArray));
            Assert.True(implicitReadOnlyBuffer.Equals(implicitReadOnlyBufferArray));
            Assert.True(implicitBufferArray.Equals(implicitReadOnlyBufferArray));
        }
Esempio n. 4
0
        public void ReadOnlyBuffersOfDifferentValuesAreNotEqual(byte[] bytes, int start, int length)
        {
            var differentBytes = bytes.Select(value => ++ value).ToArray();

            var buffer            = new ReadOnlyBuffer <byte>(bytes, start, length);
            var ofDifferentValues = new ReadOnlyBuffer <byte>(differentBytes, start, length);

            Assert.False(buffer.SequenceEqual(ofDifferentValues));
            Assert.False(ofDifferentValues.SequenceEqual(buffer));
            Assert.False(buffer.SequenceEqual(ofDifferentValues));
            Assert.False(ofDifferentValues.SequenceEqual(buffer));

            Assert.False(buffer.Equals(ofDifferentValues));
            Assert.False(ofDifferentValues.Equals(buffer));
        }
Esempio n. 5
0
        public void ReadOnlyBuffersOfEqualValuesInSameOrderAreSequentiallyAndStructurallyEqual(byte[] bytes, int start, int length)
        {
            var bytesCopy = bytes.ToArray();

            var buffer       = new ReadOnlyBuffer <byte>(bytes, start, length);
            var ofSameValues = new ReadOnlyBuffer <byte>(bytesCopy, start, length);

            Assert.True(buffer.SequenceEqual(ofSameValues));
            Assert.True(ofSameValues.SequenceEqual(buffer));
            Assert.True(buffer.SequenceEqual(ofSameValues));
            Assert.True(ofSameValues.SequenceEqual(buffer));

            Assert.False(buffer.Equals(ofSameValues));
            Assert.False(ofSameValues.Equals(buffer));
        }