public void IIEnumerable() { int LCacheSize = 5; FTestCache = new FixedSizeCache <string, string>(LCacheSize); for (int i = 1; i <= FTestCache.Size; i++) { FTestCache.Add(GetKey(i), GetValue(i)); } int LValueIndex = 0; foreach (string LValue in (IEnumerable <string>)FTestCache) { LValueIndex++; Assert.AreEqual(GetValue(LValueIndex), LValue); } Assert.AreEqual(FTestCache.Size, LValueIndex); LValueIndex = 0; foreach (FixedSizeCache <string, string> .Entry LEntry in (IEnumerable)FTestCache) { LValueIndex++; Assert.AreEqual(GetValue(LValueIndex), LEntry.Value); } Assert.AreEqual(FTestCache.Size, LValueIndex); }
public void Run() { Random LRandom = new Random(); for (int j = 0; j < FIterations; j++) { int LEntry; for (int i = 0; i < FAccessCount; i++) { LEntry = LRandom.Next(1, FSeed); switch (LRandom.Next(1, 10)) { case 1: case 2: case 3: FFixedSizeCache.Add(FixedSizeCacheTest.GetKey(LEntry), FixedSizeCacheTest.GetValue(LEntry)); break; case 4: case 5: case 6: FFixedSizeCache[FixedSizeCacheTest.GetKey(LEntry)] = FixedSizeCacheTest.GetValue(LRandom.Next(1, FSeed)); break; case 8: FFixedSizeCache.Reference(FixedSizeCacheTest.GetKey(LEntry), FixedSizeCacheTest.GetValue(LEntry)); break; default: FFixedSizeCache.Remove(FixedSizeCacheTest.GetKey(LEntry)); break; } } } }
public void Remove() { int LCacheSize = 5; FTestCache = new FixedSizeCache <string, string>(LCacheSize); for (int i = 1; i <= FTestCache.Size; i++) { FTestCache.Add(GetKey(i), GetValue(i)); } int LTestKey = 3; FTestCache.Remove(GetKey(LTestKey)); Assert.False(FTestCache.ContainsKey(GetValue(LTestKey))); Assert.AreEqual(LCacheSize - 1, FTestCache.Count); LTestKey = 1; FTestCache.Remove(GetKey(LTestKey)); Assert.False(FTestCache.ContainsKey(GetValue(LTestKey))); Assert.AreEqual(LCacheSize - 2, FTestCache.Count); LTestKey = 5; FTestCache.Remove(GetKey(LTestKey)); Assert.False(FTestCache.ContainsKey(GetValue(LTestKey))); Assert.AreEqual(LCacheSize - 3, FTestCache.Count); Assert.True(ValidateList()); }
public void Add() { int LCacheSize = 5; FTestCache = new FixedSizeCache <string, string>(LCacheSize); for (int i = 1; i <= FTestCache.Size; i++) { FTestCache.Add(GetKey(i), GetValue(i)); Assert.AreEqual(i, FTestCache.Count); Assert.AreEqual(FTestCache[GetKey(i)], GetValue(i)); Assert.True(FTestCache.ContainsKey(GetKey(i))); Assert.True(ValidateCutoff()); } Assert.AreEqual(5, FTestCache.Count); FTestCache.Add(GetKey(FTestCache.Size + 1), GetValue(FTestCache.Size + 1)); Assert.AreEqual(LCacheSize, FTestCache.Count); Assert.True(ValidateCutoff()); Assert.True(ValidateList()); }
public void ClearAndCount() { int LCacheSize = 5; FTestCache = new FixedSizeCache <string, string>(LCacheSize); for (int i = 1; i <= FTestCache.Size; i++) { FTestCache.Add(GetKey(i), GetValue(i)); Assert.AreEqual(i, FTestCache.Count); } Assert.AreEqual(LCacheSize, FTestCache.Count); FTestCache.Clear(); Assert.AreEqual(0, FTestCache.Count); Assert.True(ValidateList()); }
public void ContainsKey() { int LCacheSize = 5; int LTestCacheItem = 3; FTestCache = new FixedSizeCache <string, string>(LCacheSize); Assert.False(FTestCache.ContainsKey(GetKey(LTestCacheItem))); for (int i = 1; i <= FTestCache.Size; i++) { FTestCache.Add(GetKey(i), GetValue(i)); } Assert.True(FTestCache.ContainsKey(GetKey(LTestCacheItem))); FTestCache.Clear(); Assert.False(FTestCache.ContainsKey(GetKey(LTestCacheItem))); Assert.True(ValidateList()); }
public void IIndexor() { int LCacheSize = 5; FTestCache = new FixedSizeCache <string, string>(LCacheSize); Assert.IsNull(FTestCache[GetKey(0)]); for (int i = 1; i <= FTestCache.Size; i++) { FTestCache.Add(GetKey(i), GetValue(i)); } for (int j = 1; j <= FTestCache.Size; j++) { Assert.AreEqual(GetValue(j), FTestCache[GetKey(j)]); } Assert.IsNull(FTestCache[GetKey(FTestCache.Size + 1)]); }
private void IncrementTestEntry() { FTestEntry++; FTestCache.Add(GetKey(FTestEntry), GetValue(FTestEntry)); }