Exemple #1
0
        public void TestRank()
        {
            var n = 100;

            while (n-- > 0)
            {
                var sortSets = new SortSet <int, int>();

                sortSets.Add(1000, 85);
                sortSets.Add(999, 75);
                sortSets.Add(998, 185);
                sortSets.Add(997, 85);
                sortSets.Add(996, 185);
                sortSets.Add(995, 85);

                Assert.AreEqual(1, sortSets.GetRank(995));
                Assert.AreEqual(995, sortSets.GetElementByRank(1));
                Assert.AreEqual(997, sortSets.GetElementByRank(2));
                Assert.AreEqual(1000, sortSets.GetElementByRank(3));
                Assert.AreEqual(996, sortSets.GetElementByRank(4));
                Assert.AreEqual(998, sortSets.GetElementByRank(5));

                var i     = 100;
                var faild = 0;
                while (i-- > 0)
                {
                    Assert.AreEqual(3, sortSets.GetRangeCount(80, 90));
                }
                Console.WriteLine(faild);
            }
        }
Exemple #2
0
        public void RemoveRangeByRank()
        {
            for (var _ = 0; _ < 100; _++)
            {
                var list = new SortSet <int, int>();
                for (var i = 0; i < 10; i++)
                {
                    list.Add(i, i);
                }

                list.RemoveRangeByRank(3, 8);
                Assert.AreEqual(0, list.GetElementByRank(0));
                Assert.AreEqual(1, list.GetElementByRank(1));
                Assert.AreEqual(2, list.GetElementByRank(2));
                Assert.AreEqual(9, list.GetElementByRank(3));
                for (var i = 3; i < 9; i++)
                {
                    list.Add(i, i);
                }
                list.Add(33, 3);
                list.RemoveRangeByRank(3, 3);
                Assert.AreEqual(0, list.GetElementByRank(0));
                Assert.AreEqual(1, list.GetElementByRank(1));
                Assert.AreEqual(2, list.GetElementByRank(2));
                var r = list.GetElementByRank(3);
                Assert.AreEqual(true, r == 3 || r == 33);
            }
        }
Exemple #3
0
        public void GetElementByRankOverflowTest()
        {
            var master = new SortSet <int, int>();

            master.Add(10, 10);

            Assert.AreEqual(0, master.GetElementByRank(1000));
        }
Exemple #4
0
        public void GetElementByRankEmptyTest()
        {
            var master = new SortSet <int, int>();

            ExceptionAssert.Throws <InvalidOperationException>(() =>
            {
                master.GetElementByRank(100);
            });
        }
Exemple #5
0
        public void GetElementByRankOverflowTest()
        {
            var master = new SortSet <int, int>();

            master.Add(10, 10);

            ExceptionAssert.Throws <ArgumentOutOfRangeException>(() =>
            {
                master.GetElementByRank(1000);
            });
        }
Exemple #6
0
        public void TestRank()
        {
            var sortSets = new SortSet <int, int>();

            sortSets.Add(1000, 85);
            sortSets.Add(999, 75);
            sortSets.Add(998, 185);
            sortSets.Add(997, 85);
            sortSets.Add(996, 185);
            sortSets.Add(995, 85);

            Assert.AreEqual(1, sortSets.GetRank(995));
            Assert.AreEqual(995, sortSets.GetElementByRank(1));
            Assert.AreEqual(997, sortSets.GetElementByRank(2));
            Assert.AreEqual(1000, sortSets.GetElementByRank(3));
            Assert.AreEqual(996, sortSets.GetElementByRank(4));
            Assert.AreEqual(998, sortSets.GetElementByRank(5));

            Assert.AreEqual(3, sortSets.GetRangeCount(80, 90));
        }
Exemple #7
0
        public void GetElementByRank()
        {
            var num  = 50000;
            var list = new SortSet <int, int>();

            for (var i = 0; i < num; i++)
            {
                list.Add(i, i);
            }
            var rand = new Random();

            for (var i = 0; i < Math.Min(num, 100); i++)
            {
                var rank = rand.Next(0, num);
                var val  = list.GetElementByRank(rank);

                if (rank != val)
                {
                    Assert.Fail();
                }
            }
        }
Exemple #8
0
        public void RemoveRangeByScore()
        {
            var list = new SortSet <int, int>();

            for (var i = 0; i < 10; i++)
            {
                list.Add(i, i);
            }
            list.RemoveRangeByScore(3, 8);
            Assert.AreEqual(0, list.GetElementByRank(0));
            Assert.AreEqual(1, list.GetElementByRank(1));
            Assert.AreEqual(2, list.GetElementByRank(2));
            Assert.AreEqual(9, list.GetElementByRank(3));
            for (var i = 3; i < 9; i++)
            {
                list.Add(i, i);
            }
            list.Add(33, 3);
            list.RemoveRangeByScore(3, 3);
            Assert.AreEqual(0, list.GetElementByRank(0));
            Assert.AreEqual(1, list.GetElementByRank(1));
            Assert.AreEqual(2, list.GetElementByRank(2));
            Assert.AreEqual(4, list.GetElementByRank(3));
        }
Exemple #9
0
        public void GetElementByRankEmptyTest()
        {
            var master = new SortSet <int, int>();

            Assert.AreEqual(0, master.GetElementByRank(100));
        }