public void FIFO_change_capacity_preserves_items() { FIFOBuffer <int> f = new FIFOBuffer <int>(0); f.Capacity.Should().Be(0); AssertEmpty(f); f.Push(5); AssertEmpty(f); f.Push(12); AssertEmpty(f); f.Capacity = 1; f.Capacity.Should().Be(1); AssertEmpty(f); f.Push(5); AssertContains(f, 5); f.Push(6); AssertContains(f, 6); f.Capacity = 2; f.Capacity.Should().Be(2); AssertContains(f, 6); f.Push(7); AssertContains(f, 6, 7); f.Push(8); AssertContains(f, 7, 8); f.Capacity = 4; f.Capacity.Should().Be(4); AssertContains(f, 7, 8); f.Push(9); AssertContains(f, 7, 8, 9); f.Push(10); AssertContains(f, 7, 8, 9, 10); f.Push(11); AssertContains(f, 8, 9, 10, 11); f.Capacity = 7; f.Capacity.Should().Be(7); AssertContains(f, 8, 9, 10, 11); f.Push(12); AssertContains(f, 8, 9, 10, 11, 12); f.Push(13); AssertContains(f, 8, 9, 10, 11, 12, 13); f.Push(14); AssertContains(f, 8, 9, 10, 11, 12, 13, 14); f.Push(15); AssertContains(f, 9, 10, 11, 12, 13, 14, 15); f.Capacity = 2; f.Capacity.Should().Be(2); AssertContains(f, 14, 15); f.Capacity = 3; f.Capacity.Should().Be(3); AssertContains(f, 14, 15); f.Push(16); AssertContains(f, 14, 15, 16); f.Capacity = 2; f.Capacity.Should().Be(2); AssertContains(f, 15, 16); f.Capacity = 1; f.Capacity.Should().Be(1); AssertContains(f, 16); f.Capacity = 0; f.Capacity.Should().Be(0); AssertEmpty(f); f.Capacity = 2; f.Capacity = 2; f.Capacity.Should().Be(2); f.ToString().Should().Be(String.Format("Count = {0} (Capacity = {1})", 0, 2)); //ExceptionTest f.Invoking(sut => sut.Capacity = -1).Should().Throw <ArgumentException>(); f.Invoking(sut => new FIFOBuffer <int>(-1)).Should().Throw <ArgumentException>(); f.Invoking(sut => sut.CopyTo(new int[2], 0, -1)).Should().Throw <IndexOutOfRangeException>(); }
public void FIFO_change_capacity_preserves_items() { FIFOBuffer <int> f = new FIFOBuffer <int>(0); Assert.That(f.Capacity, Is.EqualTo(0)); AssertEmpty(f); f.Push(5); AssertEmpty(f); f.Push(12); AssertEmpty(f); f.Capacity = 1; Assert.That(f.Capacity, Is.EqualTo(1)); AssertEmpty(f); f.Push(5); AssertContains(f, 5); f.Push(6); AssertContains(f, 6); f.Capacity = 2; Assert.That(f.Capacity, Is.EqualTo(2)); AssertContains(f, 6); f.Push(7); AssertContains(f, 6, 7); f.Push(8); AssertContains(f, 7, 8); f.Capacity = 4; Assert.That(f.Capacity, Is.EqualTo(4)); AssertContains(f, 7, 8); f.Push(9); AssertContains(f, 7, 8, 9); f.Push(10); AssertContains(f, 7, 8, 9, 10); f.Push(11); AssertContains(f, 8, 9, 10, 11); f.Capacity = 7; Assert.That(f.Capacity, Is.EqualTo(7)); AssertContains(f, 8, 9, 10, 11); f.Push(12); AssertContains(f, 8, 9, 10, 11, 12); f.Push(13); AssertContains(f, 8, 9, 10, 11, 12, 13); f.Push(14); AssertContains(f, 8, 9, 10, 11, 12, 13, 14); f.Push(15); AssertContains(f, 9, 10, 11, 12, 13, 14, 15); f.Capacity = 2; Assert.That(f.Capacity, Is.EqualTo(2)); AssertContains(f, 14, 15); f.Capacity = 3; Assert.That(f.Capacity, Is.EqualTo(3)); AssertContains(f, 14, 15); f.Push(16); AssertContains(f, 14, 15, 16); f.Capacity = 2; Assert.That(f.Capacity, Is.EqualTo(2)); AssertContains(f, 15, 16); f.Capacity = 1; Assert.That(f.Capacity, Is.EqualTo(1)); AssertContains(f, 16); f.Capacity = 0; Assert.That(f.Capacity, Is.EqualTo(0)); AssertEmpty(f); f.Capacity = 2; f.Capacity = 2; Assert.That(f.Capacity, Is.EqualTo(2)); Assert.That(f.ToString(), Is.EqualTo(String.Format("Count = {0} (Capacity = {1})", 0, 2))); //ExceptionTest Assert.Throws <ArgumentException>(() => f.Capacity = -1); Assert.Throws <ArgumentException>(() => new FIFOBuffer <int>(-1)); Assert.Throws <IndexOutOfRangeException>(() => f.CopyTo(new int[2], 0, -1)); }