public void Test_TRexSpatialMemoryCacheStorageTests_MaxEpochTokenAgeOnGet() { var storage = new TRexSpatialMemoryCacheStorage <ITRexMemoryCacheItem>(1000, 500); var dummyCache = new TRexSpatialMemoryCacheContext(new TRexSpatialMemoryCache(1000, 1000, 0), storage); // Fill half slots for (int i = 0; i < 500; i++) { storage.Add(new TRexSpatialMemoryCacheContextTests_Element() { CacheOriginX = (int)(1000 + i * SubGridTreeConsts.SubGridTreeDimension), CacheOriginY = 1000, SizeInBytes = 1000 }, dummyCache); } var currentMRUHead = storage.MRUHead; // Get each item in the same order and verify they are not touched and moved to the MRUHead for (int i = 0; i < 500; i++) { var item = storage.Get(i); Assert.True(storage.MRUHead == currentMRUHead, $"MRUHead changed unexpectedly after getting item {item}: storage.MRUHead = {storage.MRUHead}, currentMRUHead = {currentMRUHead}"); } // Fill remaining slots for (int i = 500; i < 1000; i++) { storage.Add(new TRexSpatialMemoryCacheContextTests_Element() { CacheOriginX = (int)(1000 + i * SubGridTreeConsts.SubGridTreeDimension), CacheOriginY = 1000, SizeInBytes = 1000 }, dummyCache); } // Get each item in the same order and verify they are touched and moved to the MRUHead for (int i = 0; i < 1000; i++) { var item = storage.Get(i); Assert.True(storage.MRUHead == i, $"Referenced item not promoted to MRU head after getting item {item} at index {i}, MRUHead = {storage.MRUHead}"); } }
public void Test_TRexSpatialMemoryCacheStorageTests_GetAfterRemove() { var storage = new TRexSpatialMemoryCacheStorage <ITRexMemoryCacheItem>(100, 50); var dummyCache = new TRexSpatialMemoryCacheContext(new TRexSpatialMemoryCache(1000, 1000, 0), storage); var item = new TRexSpatialMemoryCacheContextTests_Element { SizeInBytes = 0, CacheOriginX = 2000, CacheOriginY = 3000 }; var index = storage.Add(item, dummyCache); Assert.True(storage.TokenCount == 1, $"Element count incorrect after add (= {storage.TokenCount})"); Assert.True(storage.Get(index) != null); // Remove the item storage.Remove(index); Assert.True(storage.Get(index) == null, "Was able to extract item after invalidation"); Assert.True(storage.TokenCount == 0, $"Element count incorrect after get after invalidation(= {storage.TokenCount})"); }
public void Test_TRexSpatialMemoryCacheStorageTests_GetElement() { var storage = new TRexSpatialMemoryCacheStorage <ITRexMemoryCacheItem>(100, 50); var dummyCache = new TRexSpatialMemoryCacheContext(new TRexSpatialMemoryCache(1000, 1000, 0), storage); var item = new TRexSpatialMemoryCacheContextTests_Element { SizeInBytes = 0, CacheOriginX = 2000, CacheOriginY = 3000 }; var index = storage.Add(item, dummyCache); Assert.True(storage.TokenCount == 1, $"Element count incorrect (= {storage.TokenCount})"); var getItem = storage.Get(index); Assert.True(ReferenceEquals(item, getItem), "Item retrieved from storage not same as item placed in storage"); }