Beispiel #1
0
        public void TestNextLowerItem()
        {
            var alist = new SparseAList <int>(_maxLeafSize, _maxInnerSize);
            int?i;

            for (i = 0; i < 100; i++)
            {
                alist.Add(i.Value);
                alist.InsertSpace(alist.Count, 1000);
            }
            i = int.MaxValue;
            Assert.AreEqual(alist.NextLowerItem(ref i), 99);
            Assert.AreEqual(i.Value, 99099);
            i = 99100;
            Assert.AreEqual(alist.NextLowerItem(ref i), 99);
            Assert.AreEqual(i.Value, 99099);
            Assert.AreEqual(alist.NextLowerItem(ref i), 98);
            Assert.AreEqual(i.Value, 98098);
            i = 55555;
            Assert.AreEqual(alist.NextLowerItem(ref i), 55);
            Assert.AreEqual(i.Value, 55055);
            i = 1002;
            Assert.AreEqual(alist.NextLowerItem(ref i), 1);
            Assert.AreEqual(i.Value, 1001);
            Assert.AreEqual(alist.NextLowerItem(ref i), 0);
            Assert.AreEqual(i.Value, 0);
            i = 1;
            Assert.AreEqual(alist.NextLowerItem(ref i), 0);
            Assert.AreEqual(i.Value, 0);
            Assert.AreEqual(alist.NextLowerItem(ref i), default(int));
            Assert.AreEqual(i.HasValue, false);
            i = int.MinValue;
            Assert.AreEqual(alist.NextLowerItem(ref i), default(int));
            Assert.AreEqual(i.HasValue, false);

            // Place a value at the edge of integer space
            alist.Clear();
            alist.InsertSpace(0, int.MaxValue - 1);
            alist.Add(777);
            i = int.MinValue;
            Assert.AreEqual(alist.NextLowerItem(ref i), default(int));
            Assert.AreEqual(i.HasValue, false);
            i = int.MaxValue;
            Assert.AreEqual(alist.NextLowerItem(ref i), default(int));
            Assert.AreEqual(i.HasValue, false);
            i = null;
            Assert.AreEqual(alist.NextLowerItem(ref i), 777);
            Assert.AreEqual(i.Value, int.MaxValue);
        }