Exemplo n.º 1
0
        public void CopyToArrayWithStartingIndexOffsetAndCountTest()
        {
            // arrange
            ByteCircularBuffer target;
            int expectedHead;

            byte[] expected;
            byte[] actual;
            int    offset;
            int    count;
            int    index;

            target = new ByteCircularBuffer(10);

            expected = new byte[]
            {
                5,
                2,
                3,
                7
            };
            actual = new byte[]
            {
                5,
                0,
                0,
                7
            };

            expectedHead = 0;
            index        = 1;
            offset       = 1;
            count        = 2;

            target.Put(1);
            target.Put(2);
            target.Put(3);

            // act
            target.CopyTo(index, actual, offset, count);

            // assert
            actual.Should().
            Equal(expected);
            target.Contains(1).
            Should().
            BeTrue();
            target.Contains(2).
            Should().
            BeTrue();
            target.Contains(3).
            Should().
            BeTrue();
            target.Head.Should().
            Be(expectedHead);
        }
Exemplo n.º 2
0
        public void GetWithArrayTest()
        {
            // arrange
            ByteCircularBuffer target;
            int expectedSize;
            int expectedHead;
            int expectedTail;
            int expectedElements;
            int actualElements;

            byte[] expected;
            byte[] actual;

            target = new ByteCircularBuffer(10);

            expected = new byte[]
            {
                1,
                2
            };
            expectedHead     = 2;
            expectedSize     = 1;
            expectedTail     = 3;
            expectedElements = 2;

            actual = new byte[expectedElements];

            target.Put(1);
            target.Put(2);
            target.Put(3);

            // act
            actualElements = target.Get(actual);

            // assert
            actualElements.Should().
            Be(expectedElements);
            actual.Should().
            Equal(expected);
            target.Contains(1).
            Should().
            BeFalse();
            target.Contains(2).
            Should().
            BeFalse();
            target.Contains(3).
            Should().
            BeTrue();
            target.Head.Should().
            Be(expectedHead);
            target.Tail.Should().
            Be(expectedTail);
            target.Size.Should().
            Be(expectedSize);
        }
Exemplo n.º 3
0
        public void CopyToArrayWithOffsetTest()
        {
            // arrange
            ByteCircularBuffer target;
            int expectedHead;

            byte[] expected;
            byte[] actual;
            int    offset;

            target = new ByteCircularBuffer(10);

            expected = new byte[]
            {
                5,
                1,
                2,
                3
            };
            actual = new byte[]
            {
                5,
                0,
                0,
                0
            };

            expectedHead = 0;
            offset       = 1;

            target.Put(1);
            target.Put(2);
            target.Put(3);

            // act
            target.CopyTo(actual, offset);

            // assert
            actual.Should().
            Equal(expected);
            target.Contains(1).
            Should().
            BeTrue();
            target.Contains(2).
            Should().
            BeTrue();
            target.Contains(3).
            Should().
            BeTrue();
            target.Head.Should().
            Be(expectedHead);
        }
Exemplo n.º 4
0
        public void PutTest()
        {
            // arrange
            ByteCircularBuffer target;
            int  expectedSize;
            int  expectedHead;
            int  expectedTail;
            byte expected;

            target = new ByteCircularBuffer(10);

            expected     = 1;
            expectedHead = 0;
            expectedSize = 1;
            expectedTail = 1;

            // act
            target.Put(expected);

            // assert
            target.Contains(expected).
            Should().
            BeTrue();
            target.Head.Should().
            Be(expectedHead);
            target.Tail.Should().
            Be(expectedTail);
            target.Size.Should().
            Be(expectedSize);
        }
Exemplo n.º 5
0
        public void GetTest()
        {
            // arrange
            ByteCircularBuffer target;
            int  expectedSize;
            int  expectedHead;
            int  expectedTail;
            byte expected;
            byte actual;

            target = new ByteCircularBuffer(10);

            expected     = 1;
            expectedHead = 1;
            expectedSize = 2;
            expectedTail = 3;

            target.Put(1);
            target.Put(2);
            target.Put(3);

            // act
            actual = target.Get();

            // assert
            actual.Should().
            Be(expected);
            target.Contains(1).
            Should().
            BeFalse();
            target.Contains(2).
            Should().
            BeTrue();
            target.Contains(3).
            Should().
            BeTrue();
            target.Head.Should().
            Be(expectedHead);
            target.Tail.Should().
            Be(expectedTail);
            target.Size.Should().
            Be(expectedSize);
        }
Exemplo n.º 6
0
        public void CopyToTest()
        {
            // arrange
            ByteCircularBuffer target;
            int expectedHead;

            byte[] expected;
            byte[] actual;

            target = new ByteCircularBuffer(10);

            expected = new byte[]
            {
                1,
                2,
                3
            };
            expectedHead = 0;

            actual = new byte[3];

            target.Put(1);
            target.Put(2);
            target.Put(3);

            // act
            target.CopyTo(actual);

            // assert
            actual.Should().
            Equal(expected);
            target.Contains(1).
            Should().
            BeTrue();
            target.Contains(2).
            Should().
            BeTrue();
            target.Contains(3).
            Should().
            BeTrue();
            target.Head.Should().
            Be(expectedHead);
        }
Exemplo n.º 7
0
        public void PutMultipleTest()
        {
            // arrange
            ByteCircularBuffer target;
            int  expectedSize;
            int  expectedHead;
            int  expectedTail;
            byte expected1;
            byte expected2;
            byte expected3;

            target = new ByteCircularBuffer(10);

            expected1    = 1;
            expected2    = 2;
            expected3    = 3;
            expectedHead = 0;
            expectedSize = 3;
            expectedTail = 3;

            // act
            target.Put(expected1);
            target.Put(expected2);
            target.Put(expected3);

            // assert
            target.Contains(expected1).
            Should().
            BeTrue();
            target.Contains(expected2).
            Should().
            BeTrue();
            target.Contains(expected3).
            Should().
            BeTrue();
            target.Head.Should().
            Be(expectedHead);
            target.Tail.Should().
            Be(expectedTail);
            target.Size.Should().
            Be(expectedSize);
        }
Exemplo n.º 8
0
        public void ContainsTest()
        {
            // arrange
            ByteCircularBuffer target;
            bool actual;

            target = new ByteCircularBuffer(10);
            target.Put(1);
            target.Put(2);
            target.Put(3);

            // act
            actual = target.Contains(1);

            // assert
            actual.Should().
            BeTrue();
        }