当前位置: 首页>>代码示例>>C#>>正文


C# LruCache.Add方法代码示例

本文整理汇总了C#中LruCache.Add方法的典型用法代码示例。如果您正苦于以下问题:C# LruCache.Add方法的具体用法?C# LruCache.Add怎么用?C# LruCache.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在LruCache的用法示例。


在下文中一共展示了LruCache.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Add_ItemIsAdded_CurrentSizeIncreasesByItemSize

 public void Add_ItemIsAdded_CurrentSizeIncreasesByItemSize()
 {
     var lru = new LruCache<string, string>(1024, 2);
     Assert.AreEqual(0, lru.CurrentSize);
     lru.Add("k1", "v1");
     Assert.AreEqual(2, lru.CurrentSize);
     lru.Add("k2", "v2");
     Assert.AreEqual(4, lru.CurrentSize);
     lru.Add("k3", "v3");
     Assert.AreEqual(6, lru.CurrentSize);
     lru.Add("k4", "v4");
     Assert.AreEqual(8, lru.CurrentSize);
     lru.Add("k5", "v5");
 }
开发者ID:youkebing,项目名称:dotnet-lru-cache,代码行数:14,代码来源:LruCacheTests.cs

示例2: Add_DuplicateKeyAdded_ThrowsArgumentException

 public void Add_DuplicateKeyAdded_ThrowsArgumentException()
 {
     try
     {
         var lru = new LruCache<string, string>(5);
         lru.Add("k1", "v1");
         lru.Add("k1", "v1");
         Assert.Fail("Should not have reached this point");
     }
     catch (ArgumentException)
     {
         Assert.Pass();
     }
 }
开发者ID:youkebing,项目名称:dotnet-lru-cache,代码行数:14,代码来源:LruCacheTests.cs

示例3: Add_ItemIsAdded_ItemExistsInCache

        public void Add_ItemIsAdded_ItemExistsInCache()
        {
            var lru = new LruCache<string, string>(1);
            lru.Add("k1", "v1");

            Assert.IsTrue(lru.ContainsKey("k1"));
        }
开发者ID:youkebing,项目名称:dotnet-lru-cache,代码行数:7,代码来源:LruCacheTests.cs

示例4: GetInitializedCache

 private static LruCache<string, string> GetInitializedCache(int max, params string[] entries)
 {
     var cache = new LruCache<string, string>(max);
     foreach (var entry in entries)
     {
         cache.Add(entry, entry);
     }
     return cache;
 }
开发者ID:jjnguy,项目名称:LRU.Net,代码行数:9,代码来源:UnitTest1.cs

示例5: Add_MaxSizeIsReached_OldestItemDiscarded

        public void Add_MaxSizeIsReached_OldestItemDiscarded()
        {
            var lru = new LruCache<string, string>(5);
            lru.Add("k1", "v1");
            lru.Add("k2", "v2");
            lru.Add("k3", "v3");
            lru.Add("k4", "v4");
            lru.Add("k5", "v5");
            lru.Add("k6", "v6");

            Assert.IsFalse(lru.ContainsKey("k1"));
        }
开发者ID:youkebing,项目名称:dotnet-lru-cache,代码行数:12,代码来源:LruCacheTests.cs

示例6: Add_MaxSizeIsReached_DiscardedCountIncreases

        public void Add_MaxSizeIsReached_DiscardedCountIncreases()
        {
            var lru = new LruCache<string, string>(5);
            lru.Add("k1", "v1");
            lru.Add("k2", "v2");
            lru.Add("k3", "v3");
            lru.Add("k4", "v4");
            lru.Add("k5", "v5");

            Assert.AreEqual(0, lru.DiscardedCount);

            lru.Add("k6", "v6");
            Assert.AreEqual(1, lru.DiscardedCount);

            lru.Add("k7", "v7");
            Assert.AreEqual(2, lru.DiscardedCount);
        }
开发者ID:youkebing,项目名称:dotnet-lru-cache,代码行数:17,代码来源:LruCacheTests.cs

示例7: NewestItemKey_CacheNotEmpty_ReturnsNewestKey

        public void NewestItemKey_CacheNotEmpty_ReturnsNewestKey()
        {
            var lru = new LruCache<string, string>(2);
            lru.Add("k1", "v1");
            lru.Add("k2", "v2");

            Assert.AreEqual("k2", lru.NewestKey);
        }
开发者ID:youkebing,项目名称:dotnet-lru-cache,代码行数:8,代码来源:LruCacheTests.cs

示例8: ContainsKey_KeyExists_ReturnsTrue

        public void ContainsKey_KeyExists_ReturnsTrue()
        {
            var lru = new LruCache<string, string>(1);
            lru.Add("k1", "v1");

            Assert.IsTrue(lru.ContainsKey("k1"));
        }
开发者ID:youkebing,项目名称:dotnet-lru-cache,代码行数:7,代码来源:LruCacheTests.cs

示例9: Resize_NewSizeCausesTrim_OnlyOldestItemsDiscarded

        public void Resize_NewSizeCausesTrim_OnlyOldestItemsDiscarded()
        {
            var lru = new LruCache<string, string>(5);
            lru.Add("k1", "v1");
            lru.Add("k2", "v2");
            lru.Add("k3", "v3");
            lru.Add("k4", "v4");
            lru.Add("k5", "v5");

            lru.Resize(3);

            Assert.IsFalse(lru.ContainsKey("k1"));
            Assert.IsFalse(lru.ContainsKey("k2"));
            Assert.IsTrue(lru.ContainsKey("k3"));
            Assert.IsTrue(lru.ContainsKey("k4"));
            Assert.IsTrue(lru.ContainsKey("k5"));
        }
开发者ID:youkebing,项目名称:dotnet-lru-cache,代码行数:17,代码来源:LruCacheTests.cs

示例10: Remove_ItemIsRemoved_ReturnsTrue

        public void Remove_ItemIsRemoved_ReturnsTrue()
        {
            var lru = new LruCache<string, string>(1);
            lru.Add("k1", "v1");

            Assert.IsTrue(lru.Remove("k1"));
        }
开发者ID:youkebing,项目名称:dotnet-lru-cache,代码行数:7,代码来源:LruCacheTests.cs

示例11: Remove_KeyDoesNotExist_ReturnsFalse

        public void Remove_KeyDoesNotExist_ReturnsFalse()
        {
            var lru = new LruCache<string, string>(1);
            lru.Add("k1", "v1");

            Assert.IsFalse(lru.Remove("k2"));
        }
开发者ID:youkebing,项目名称:dotnet-lru-cache,代码行数:7,代码来源:LruCacheTests.cs

示例12: Clear_CacheIsNotEmpty_CurrentSizeIsZero

        public void Clear_CacheIsNotEmpty_CurrentSizeIsZero()
        {
            var lru = new LruCache<string, string>(5);
            lru.Add("k1", "v1");
            lru.Add("k2", "v2");
            lru.Add("k3", "v3");
            lru.Add("k4", "v4");
            lru.Add("k5", "v5");

            Assert.AreEqual(5, lru.CurrentSize);

            lru.Clear();

            Assert.AreEqual(0, lru.CurrentSize);
        }
开发者ID:youkebing,项目名称:dotnet-lru-cache,代码行数:15,代码来源:LruCacheTests.cs

示例13: Remove_ItemIsRemoved_CurrentSizeDecreasesByItemSize

        public void Remove_ItemIsRemoved_CurrentSizeDecreasesByItemSize()
        {
            var lru = new LruCache<string, string>(5);
            lru.Add("k1", "v1");
            lru.Add("k2", "v2");
            lru.Add("k3", "v3");
            lru.Add("k4", "v4");
            lru.Add("k5", "v5");

            Assert.AreEqual(5, lru.CurrentSize);

            lru.Remove("k1");
            Assert.AreEqual(4, lru.CurrentSize);

            lru.Remove("k2");
            Assert.AreEqual(3, lru.CurrentSize);

            lru.Remove("k3");
            Assert.AreEqual(2, lru.CurrentSize);

            lru.Remove("k4");
            Assert.AreEqual(1, lru.CurrentSize);

            lru.Remove("k5");
            Assert.AreEqual(0, lru.CurrentSize);
        }
开发者ID:youkebing,项目名称:dotnet-lru-cache,代码行数:26,代码来源:LruCacheTests.cs

示例14: Contains_EntryExists_ReturnsTrue

        public void Contains_EntryExists_ReturnsTrue()
        {
            var lru = new LruCache<string, string>(1);
            lru.Add("k1", "v1");

            var entry = new KeyValuePair<string, string>("k1", "v1");

            Assert.IsTrue(lru.Contains(entry));
        }
开发者ID:youkebing,项目名称:dotnet-lru-cache,代码行数:9,代码来源:LruCacheTests.cs

示例15: TryGetValue_KeyExists_HitCountIncreased

        public void TryGetValue_KeyExists_HitCountIncreased()
        {
            var lru = new LruCache<string, string>(1);
            lru.Add("k1", "v1");

            Assert.AreEqual(0, lru.HitCount);

            string value;
            lru.TryGetValue("k1", out value);

            Assert.AreEqual(1, lru.HitCount);
        }
开发者ID:youkebing,项目名称:dotnet-lru-cache,代码行数:12,代码来源:LruCacheTests.cs


注:本文中的LruCache.Add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。