Ejemplo n.º 1
0
        public void FirstLastTest()
        {
            var master = new SortSet <int, int>(0.25, 32);

            for (var i = 0; i < 65536; i++)
            {
                master.Add(i, i);
            }

            Assert.AreEqual(0, master.First());
            Assert.AreEqual(65535, master.Last());

            for (var i = 0; i < 65536; i++)
            {
                Assert.AreEqual(i, master.First());
                Assert.AreEqual(i, master.Shift());
            }

            Assert.AreEqual(0, master.Count);

            master = new SortSet <int, int>(0.25, 32);
            for (var i = 0; i < 65536; i++)
            {
                master.Add(i, i);
            }
            for (var i = 0; i < 65536; i++)
            {
                Assert.AreEqual(65535 - i, master.Last());
                Assert.AreEqual(65535 - i, master.Pop());
            }
        }
Ejemplo n.º 2
0
        public void TestCustomComparer()
        {
            var foo = new SortSet <object, int>(new PriorityComparer());

            for (var i = 0; i < 10; i++)
            {
                foo.Add(i, i);
            }

            for (var i = 9; i >= 0; i--)
            {
                Assert.AreEqual(i, foo.Shift());
            }

            foo = new SortSet <object, int>();
            for (var i = 0; i < 10; i++)
            {
                foo.Add(i, i);
            }

            for (var i = 0; i < 10; i++)
            {
                Assert.AreEqual(i, foo.Shift());
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 记录一个日志
 /// </summary>
 /// <param name="entry">日志条目</param>
 internal void Log(ILogEntry entry)
 {
     while (logEntrys.Count >= maxLogEntrys)
     {
         logEntrys.Shift();
     }
     logEntrys.Add(entry, entry.Id);
 }
Ejemplo n.º 4
0
        public void ShiftEmptySortSet()
        {
            var master = new SortSet <int, int>(0.25, 32);

            ExceptionAssert.Throws <InvalidOperationException>(() =>
            {
                master.Shift();
            });
        }
Ejemplo n.º 5
0
        public void TestCustomComparer()
        {
            var list = new SortSet <object, int>(new PriorityComparer());

            for (var i = 0; i < 10; i++)
            {
                list.Add(i, i);
            }

            Assert.AreEqual(9, list.Shift());
            Assert.AreEqual(8, list.Shift());
            Assert.AreEqual(7, list.Shift());
            Assert.AreEqual(6, list.Shift());
            Assert.AreEqual(5, list.Shift());
            Assert.AreEqual(4, list.Shift());
            Assert.AreEqual(3, list.Shift());
            Assert.AreEqual(2, list.Shift());
            Assert.AreEqual(1, list.Shift());
            Assert.AreEqual(0, list.Shift());

            list = new SortSet <object, int>();
            for (var i = 0; i < 10; i++)
            {
                list.Add(i, i);
            }

            Assert.AreEqual(0, list.Shift());
            Assert.AreEqual(1, list.Shift());
            Assert.AreEqual(2, list.Shift());
            Assert.AreEqual(3, list.Shift());
            Assert.AreEqual(4, list.Shift());
            Assert.AreEqual(5, list.Shift());
            Assert.AreEqual(6, list.Shift());
            Assert.AreEqual(7, list.Shift());
            Assert.AreEqual(8, list.Shift());
            Assert.AreEqual(9, list.Shift());
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 头部推出测试
        /// </summary>
        public void ShiftTest()
        {
            var master = new SortSet <int, int>(0.25, 32);

            for (var i = 0; i < 100; i++)
            {
                master.Add(i, i);
            }

            for (var i = 0; i < 65536; i++)
            {
                Assert.AreEqual(i, master.Shift());
            }
            Assert.AreEqual(0, master.Count);
        }