Example #1
0
        public void Equality_Default()
        {
            var a = new FifoCache <int, int>(1);
            var b = new FifoCache <int, int>(1);

            Assert.AreEqual(a, b);
        }
Example #2
0
        public void Equality_DifferentSize()
        {
            var a = new FifoCache <int, int>(1);
            var b = new FifoCache <int, int>(2);

            Assert.AreNotEqual(a, b);
        }
Example #3
0
        public void GetPagesReturnsNullsInitially()
        {
            var sut = new FifoCache(3);

              var result = sut.Pages;

              Assert.IsTrue(result.All(it => it == null));
        }
Example #4
0
        public void GetPagesReturnsNullsInitially()
        {
            var sut = new FifoCache(3);

            var result = sut.Pages;

            Assert.IsTrue(result.All(it => it == null));
        }
Example #5
0
        public void AddingASinglePageReturnsThatPageFollowedByNulls()
        {
            var sut = new FifoCache(3);

              sut.AddPage(1);

              var result = sut.Pages;
              CollectionAssert.AreEqual(new int?[] { 1, null, null }, result);
        }
Example #6
0
        public void Item_should_be_removed_on_demand()
        {
            ICache cache = new FifoCache();

            cache[0] = 0;
            Assert.That(cache[0], Is.Not.Null);

            cache.Remove(0);
            Assert.That(cache[0], Is.Null);
        }
Example #7
0
        public void Equality_ReallyTheSame()
        {
            var a = new FifoCache <int, int>(1);

            a.SetValue(1, 11);
            var b = new FifoCache <int, int>(1);

            b.SetValue(1, 11);
            Assert.AreEqual(a, b);
        }
Example #8
0
        public void Equality_DifferentValues()
        {
            var a = new FifoCache <int, int>(1);

            a.SetValue(1, 11);
            var b = new FifoCache <int, int>(1);

            b.SetValue(1, 12);
            Assert.AreNotEqual(a, b);
        }
Example #9
0
        public void AddingASinglePageReturnsThatPageFollowedByNulls()
        {
            var sut = new FifoCache(3);

            sut.AddPage(1);

            var result = sut.Pages;

            CollectionAssert.AreEqual(new int?[] { 1, null, null }, result);
        }
Example #10
0
        public void AddingAPageThatAlreadyExistsDoesNotChangeThePages()
        {
            var sut = new FifoCache(3);
              var pages = new[] { 0, 1, 2 };
              foreach (var page in pages)
            sut.AddPage(page);

              sut.AddPage(1);

              CollectionAssert.AreEqual(new[] { 2, 1, 0 }, sut.Pages);
        }
Example #11
0
        public void Complex()
        {
            var sut = new FifoCache(3);
              var pages = new[] { 0, 1, 2, 3, 2, 3, 0, 4, 5, 2, 3, 1, 4, 3, 2, 6, 3, 2, 1, 2 };

              foreach (var page in pages)
            sut.AddPage(page);

              var result = sut.Pages;
              CollectionAssert.AreEqual(new[] { 2, 1, 3 }, result);
              Assert.AreEqual(16, sut.PageFaults);
        }
Example #12
0
        public void AddingAPageThatAlreadyExistsDoesNotChangeThePages()
        {
            var sut   = new FifoCache(3);
            var pages = new[] { 0, 1, 2 };

            foreach (var page in pages)
            {
                sut.AddPage(page);
            }

            sut.AddPage(1);

            CollectionAssert.AreEqual(new[] { 2, 1, 0 }, sut.Pages);
        }
Example #13
0
        public void Cache_should_be_clear_on_demand()
        {
            ICache cache = new FifoCache();

            for (int i = 0; i < 5; i++)
            {
                cache[i] = i;
            }

            Assert.That(cache[0], Is.Not.Null);
            Assert.That(cache[4], Is.Not.Null);
            cache.Clear();
            Assert.That(cache[0], Is.Null);
            Assert.That(cache[4], Is.Null);
        }
Example #14
0
        public void Complex()
        {
            var sut   = new FifoCache(3);
            var pages = new[] { 0, 1, 2, 3, 2, 3, 0, 4, 5, 2, 3, 1, 4, 3, 2, 6, 3, 2, 1, 2 };

            foreach (var page in pages)
            {
                sut.AddPage(page);
            }

            var result = sut.Pages;

            CollectionAssert.AreEqual(new[] { 2, 1, 3 }, result);
            Assert.AreEqual(16, sut.PageFaults);
        }
Example #15
0
        public void First_item_should_be_removed()
        {
            FifoCache cache = new FifoCache();

            cache.Size = 5;

            for (int i = 0; i < 5; i++)
            {
                cache[i] = i;
            }

            Assert.That(cache[0], Is.EqualTo(0));
            cache[5] = 5;
            Assert.That(cache[0], Is.Null);
            Assert.That(cache.Size, Is.EqualTo(5));
        }
Example #16
0
 public void Setup()
 {
     _sut = new FifoCache <int, int>(2);
 }