예제 #1
0
        public void Get_GetFromEmptyRingBufferShouldNotWork()
        {
            // Arrange
            RingBufferArray <int> sut = new RingBufferArray <int>(10)
            {
                // Act
                42
            };

            sut.Get();

            // Assert
            Assert.Throws <DataStructureIsEmptyOnReadExeption>(() => sut.Get());
        }
        public Object Dequeue()
        {
            full.WaitOne();
            Object x = buf.Get();

            empty.Release();
            return(x);
        }
예제 #3
0
        public void IsEmpty_EmptyRingBufferShouldReturnTrue()
        {
            // Arrange
            RingBufferArray <int> sut = new RingBufferArray <int>(5);
            bool expected             = true;

            // Act
            sut.Add(42);
            sut.Get();
            bool actual = sut.IsEmpty();

            // Assert
            Assert.Equal(expected, actual);
        }
예제 #4
0
        public void Add_RingBuferShouldOverwriteWhenItFull()
        {
            // Arrange
            RingBufferArray <int> sut = new RingBufferArray <int>(7);
            int expected = 1;

            // Act
            for (int i = 0; i < 8; i++)
            {
                sut.Add(i);
            }
            int actual = sut.Get();

            // Assert
            Assert.Equal(expected, actual);
        }
예제 #5
0
        public void Get_GetAllNumbersFromRingBufferShouldWork()
        {
            // Arrange
            RingBufferArray <int> sut = new RingBufferArray <int>(10);
            int expected = 0;

            // Act
            for (int i = 0; i < 20; i++)
            {
                sut.Add(i);
            }
            for (int i = 0; i <= 10; i++)
            {
                sut.Get();
            }
            int actual = sut.Size();

            // Assert
            Assert.Equal(expected, actual);
        }
예제 #6
0
        public void Indexer_IndexerGetAndSetShouldWork()
        {
            // Arrange
            RingBufferArray <double> sut = new RingBufferArray <double>(10);
            double expected = 42.2;

            // Act
            for (int i = 0; i < 10; i++)
            {
                sut.Add(i);
            }
            for (int i = 0; i < 5; i++)
            {
                sut.Get();
            }
            sut.Add(2);
            sut.Add(5);
            sut.Add(11);
            sut[7] = 42.2;
            double actual = sut[7];

            // Assert
            Assert.Equal(expected, actual);
        }