public void Equality_Default() { var a = new FifoCache <int, int>(1); var b = new FifoCache <int, int>(1); Assert.AreEqual(a, b); }
public void Equality_DifferentSize() { var a = new FifoCache <int, int>(1); var b = new FifoCache <int, int>(2); Assert.AreNotEqual(a, b); }
public void GetPagesReturnsNullsInitially() { var sut = new FifoCache(3); var result = sut.Pages; Assert.IsTrue(result.All(it => it == null)); }
public void AddingASinglePageReturnsThatPageFollowedByNulls() { var sut = new FifoCache(3); sut.AddPage(1); var result = sut.Pages; CollectionAssert.AreEqual(new int?[] { 1, null, null }, result); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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)); }
public void Setup() { _sut = new FifoCache <int, int>(2); }