Exemple #1
0
        public void ReverseWorksAsExpected()
        {
            // --- Arrange
            var lru = new LruList <int>(3);

            lru.Add(100);
            lru.Add(200);
            lru.Add(300);
            lru.Add(400);
            lru.Add(500);
            lru.Add(600);
            lru.Add(700);
            lru.Add(800);
            var revList = new List <int>();

            // --- Act
            foreach (var item in lru.Reverse())
            {
                revList.Add(item);
            }

            // --- Assert
            revList.Count.ShouldBe(3);
            revList[0].ShouldBe(800);
            revList[1].ShouldBe(700);
            revList[2].ShouldBe(600);
        }
Exemple #2
0
 public void LruList_AddEmpty()
 {
     var lruList = new LruList<string, string>();
     var item1 = new LruListItem<string, string>("key1", "value1");
     lruList.Add(item1);
     AssertListState(lruList, item1);
 }
Exemple #3
0
        public void ContainsWorksWhenCapacityIsExceededMultipleTimes()
        {
            // --- Arrange
            var lru = new LruList <int>(3);

            // --- Act
            lru.Add(100);
            lru.Add(200);
            lru.Add(300);
            lru.Add(400);
            lru.Add(500);
            lru.Add(600);
            lru.Add(700);
            lru.Add(800);

            // --- Assert
            lru.Contains(100).ShouldBeFalse();
            lru.Contains(200).ShouldBeFalse();
            lru.Contains(300).ShouldBeFalse();
            lru.Contains(400).ShouldBeFalse();
            lru.Contains(500).ShouldBeFalse();
            lru.Contains(600).ShouldBeTrue();
            lru.Contains(700).ShouldBeTrue();
            lru.Contains(800).ShouldBeTrue();
            lru.Contains(900).ShouldBeFalse();
        }
Exemple #4
0
        private void AssertListState(LruList <string, string> lruList, params LruListItem <string, string>[] items)
        {
            if (items.Length == 0)
            {
                Assert.IsNull(lruList.Head);
                Assert.IsNull(lruList.Tail);
            }
            else
            {
                // check references on ends
                Assert.IsNull(lruList.Head.Previous);
                Assert.IsNull(lruList.Tail.Next);

                // make sure head and tail are correct
                Assert.AreEqual(items[0], lruList.Head);
                Assert.AreEqual(items[items.Length - 1], lruList.Tail);

                // make sure Next references are in the expected order
                for (int i = 0; i < items.Length - 1; i++)
                {
                    Assert.AreEqual(items[i].Next, items[i + 1]);
                }

                // make sure Previous references are in the expected order
                for (int i = items.Length - 1; i > 0; i--)
                {
                    Assert.AreEqual(items[i].Previous, items[i - 1]);
                }
            }
        }
Exemple #5
0
        public void LruList_AddEmpty()
        {
            var lruList = new LruList <string, string>();
            var item1   = new LruListItem <string, string>("key1", "value1");

            lruList.Add(item1);
            AssertListState(lruList, item1);
        }
        /// <summary>
        /// Resets the debug support
        /// </summary>
        public void Reset()
        {
            var package = SpectNetPackage.Default;

            StackPointerEvents = new LruList <StackPointerManipulationEvent>(
                package.Options.StackPointerEvents);
            StackContentEvents = new Dictionary <ushort, StackContentManipulationEvent>();
        }
Exemple #7
0
        public void ConstructionWithDefaultCapacityWorksAsExpected()
        {
            // --- Act
            var lru = new LruList <int>();

            // --- Assert
            lru.Capacity.ShouldBe(10);
            lru.Count.ShouldBe(0);
        }
Exemple #8
0
 public void LruList_RemoveOneItem()
 {
     var lruList = new LruList<string, string>();
     var item1 = new LruListItem<string, string>("key1", "value1");
     lruList.Add(item1);
     lruList.Remove(item1);
     AssertDisconnected(item1);
     AssertListState(lruList);
 }
Exemple #9
0
 public HostService(string baseDir, IEnumerable <FileModel> models, string versionName, string versionDir, int lruSize)
 {
     VersionName         = versionName;
     VersionOutputFolder = versionDir;
     if (lruSize > 0)
     {
         _lru = LruList <ModelWithCache> .CreateSynchronized(lruSize, OnLruRemoving);
     }
     LoadCore(models);
 }
Exemple #10
0
 public XRefArchiveReader(XRefArchive archive)
     : base(XRefArchive.MajorFileName, new HashSet <string>(archive.Entries))
 {
     if (archive == null)
     {
         throw new ArgumentNullException(nameof(archive));
     }
     _archive = archive;
     _lru     = LruList <Tuple <string, XRefMap> > .Create(0x10, comparer : new TupleComparer());
 }
Exemple #11
0
        public void LruList_RemoveOneItem()
        {
            var lruList = new LruList <string, string>();
            var item1   = new LruListItem <string, string>("key1", "value1");

            lruList.Add(item1);
            lruList.Remove(item1);
            AssertDisconnected(item1);
            AssertListState(lruList);
        }
Exemple #12
0
 public void LruList_RemoveTailTwoItems()
 {
     var lruList = new LruList<string, string>();
     var item1 = new LruListItem<string, string>("key1", "value1");
     var item2 = new LruListItem<string, string>("key2", "value2");
     lruList.Add(item1);
     lruList.Add(item2);
     lruList.Remove(item1);
     AssertDisconnected(item1);
     AssertListState(lruList, item2);
 }
Exemple #13
0
        public void LruList_RemoveTailTwoItems()
        {
            var lruList = new LruList <string, string>();
            var item1   = new LruListItem <string, string>("key1", "value1");
            var item2   = new LruListItem <string, string>("key2", "value2");

            lruList.Add(item1);
            lruList.Add(item2);
            lruList.Remove(item1);
            AssertDisconnected(item1);
            AssertListState(lruList, item2);
        }
        protected override void InsertCore(TKey key, LinkedListNode <KeyValuePair <TKey, TValue> > newNode)
        {
            base.InsertCore(key, newNode);
            var value = newNode.Value.Value;

            // if there was a node already with same distinct value we need to remove it
            if (_distinctDictionary.TryGetValue(value, out var oldNode))
            {
                LruList.Remove(oldNode);
                Remove(oldNode.Value.Key);
            }

            _distinctDictionary[value] = newNode;
        }
Exemple #15
0
        public void ContainsWorksWhenCapacityIsNotExceeded()
        {
            // --- Arrange
            var lru = new LruList <int>(3);

            // --- Act
            lru.Add(100);
            lru.Add(200);

            // --- Assert
            lru.Contains(100).ShouldBeTrue();
            lru.Contains(200).ShouldBeTrue();
            lru.Contains(300).ShouldBeFalse();
        }
Exemple #16
0
        public void AddWorksWhenCapacityIsNotExceeded()
        {
            // --- Arrange
            var lru = new LruList <int>(3);

            // --- Act
            lru.Add(100);
            lru.Add(200);

            // --- Assert
            lru.Capacity.ShouldBe(3);
            lru.Count.ShouldBe(2);
            lru[0].ShouldBe(100);
            lru[1].ShouldBe(200);
        }
Exemple #17
0
        public void AddWorksWhenCapacityIsExceededMultipleTimes()
        {
            // --- Arrange
            var lru = new LruList <int>(3);

            // --- Act
            lru.Add(100);
            lru.Add(200);
            lru.Add(300);
            lru.Add(400);
            lru.Add(500);
            lru.Add(600);
            lru.Add(700);
            lru.Add(800);

            // --- Assert
            lru.Capacity.ShouldBe(3);
            lru.Count.ShouldBe(3);
            lru[0].ShouldBe(600);
            lru[1].ShouldBe(700);
            lru[2].ShouldBe(800);
        }
Exemple #18
0
        private void AssertListState(LruList<string, string> lruList, params LruListItem<string, string>[] items)
        {
            if (items.Length == 0)
            {
                Assert.IsNull(lruList.Head);
                Assert.IsNull(lruList.Tail);
            }
            else
            {
                // check references on ends
                Assert.IsNull(lruList.Head.Previous);
                Assert.IsNull(lruList.Tail.Next);

                // make sure head and tail are correct
                Assert.AreEqual(items[0], lruList.Head);
                Assert.AreEqual(items[items.Length - 1], lruList.Tail);

                // make sure Next references are in the expected order
                for (int i = 0; i < items.Length - 1; i++)
                {
                    Assert.AreEqual(items[i].Next, items[i + 1]);
                }

                // make sure Previous references are in the expected order
                for (int i = items.Length - 1; i > 0; i--)
                {
                    Assert.AreEqual(items[i].Previous, items[i - 1]);
                }
            }
        }
Exemple #19
0
 /// <summary>
 /// Resets the debug support
 /// </summary>
 public void Reset()
 {
     StackPointerEvents = new LruList <StackPointerManipulationEvent>(16);
     StackContentEvents = new Dictionary <ushort, StackContentManipulationEvent>();
 }