Exemple #1
0
 static void CheckOnlyOneValueType <T>(FIFOBuffer <T> f, T value, T otherValue) where T : struct
 {
     f[0].Should().Be(value);
     f.Contains(value).Should().BeTrue();
     f.Contains(otherValue).Should().BeFalse();
     f.Contains(null).Should().BeFalse();
     f.SequenceEqual(new[] { value }).Should().BeTrue();
 }
Exemple #2
0
 static void CheckOnlyOneValueType <T>(FIFOBuffer <T> f, T value, T otherValue) where T : struct
 {
     Assert.That(f[0], Is.EqualTo(value));
     Assert.That(f.Contains(value), Is.True);
     Assert.That(f.Contains(otherValue), Is.False);
     Assert.That(f.Contains(null), Is.False);
     Assert.That(f.SequenceEqual(new[] { value }), Is.True);
 }
Exemple #3
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>();
        }
Exemple #4
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());
        }
Exemple #5
0
        public void FIFOSupportNull()
        {
            CultureInfo c0 = CultureInfo.InvariantCulture;
            CultureInfo c1 = CultureInfo.GetCultureInfo("fr");

            FIFOBuffer <CultureInfo> f = new FIFOBuffer <CultureInfo>(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));
            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));
            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));
            AssertContains(f, null, c1);

            f.Push(null);
            AssertContains(f, c1, null);
            f.Push(null);
            AssertContains(f, null, null);
        }