Пример #1
0
        public void FIFO_supports_Null_entries()
        {
            var c0 = CultureInfo.InvariantCulture;
            var c1 = this;

            var f = new FIFOBuffer <object>(2);

            AssertEmpty(f);

            // When calling with null, it is the IndexOf( T ) that is called
            // since T is a reference type.
            int iNull = f.IndexOf(null);

            iNull.Should().BeLessThan(0);

            f.Push(c0);
            f.Contains(null).Should().BeFalse();
            f.IndexOf(null).Should().BeLessThan(0);
            f.PeekLast().Should().BeSameAs(c0);
            AssertContains(f, c0);

            f.Push(null);
            f.Count.Should().Be(2);
            f.IndexOf(null).Should().Be(1);
            f.IndexOf(c0).Should().Be(0);
            f.PeekLast().Should().BeNull();
            AssertContains(f, c0, null);

            f.Push(c1);
            f.IndexOf(null).Should().Be(0);
            f.IndexOf(c1).Should().Be(1);
            f.Contains(c0).Should().BeFalse();
            f.IndexOf(c0).Should().BeLessThan(0);
            f.PeekLast().Should().BeSameAs(c1);
            AssertContains(f, null, c1);

            f.Push(null);
            AssertContains(f, c1, null);
            f.Push(null);
            AssertContains(f, null, null);
            f.PopLast().Should().BeNull();
            f.PopLast().Should().BeNull();
            f.Invoking(sut => sut.PopLast()).Should().Throw <InvalidOperationException>();
        }
Пример #2
0
        public void FIFO_supports_Null_entries()
        {
            var c0 = CultureInfo.InvariantCulture;
            var c1 = this;

            var f = new FIFOBuffer <object>(2);

            AssertEmpty(f);

            // When calling with null, it is the IndexOf( T ) that is called
            // since T is a reference type.
            int iNull = f.IndexOf(null);

            Assert.That(iNull, Is.LessThan(0));

            f.Push(c0);
            Assert.That(f.Contains(null), Is.False);
            Assert.That(f.IndexOf(null), Is.LessThan(0));
            Assert.That(f.PeekLast(), Is.SameAs(c0));
            AssertContains(f, c0);

            f.Push(null);
            Assert.That(f.Count, Is.EqualTo(2));
            Assert.That(f.IndexOf(null), Is.EqualTo(1));
            Assert.That(f.IndexOf(c0), Is.EqualTo(0));
            Assert.That(f.PeekLast(), Is.Null);
            AssertContains(f, c0, null);

            f.Push(c1);
            Assert.That(f.IndexOf(null), Is.EqualTo(0));
            Assert.That(f.IndexOf(c1), Is.EqualTo(1));
            Assert.That(f.Contains(c0), Is.False);
            Assert.That(f.IndexOf(c0), Is.LessThan(0));
            Assert.That(f.PeekLast(), Is.SameAs(c1));
            AssertContains(f, null, c1);

            f.Push(null);
            AssertContains(f, c1, null);
            f.Push(null);
            AssertContains(f, null, null);
            Assert.That(f.PopLast(), Is.Null);
            Assert.That(f.PopLast(), Is.Null);
            Assert.Throws <InvalidOperationException>(() => f.PopLast());
        }