コード例 #1
0
        public void DescendingStalenessSort()
        {
            var chatScores = new Dictionary <Chat, double>();

            chatScores.Add(Chat.Create("c1").Staleness(3.1), 1);
            chatScores.Add(Chat.Create("c2").Staleness(3), 1);
            chatScores.Add(Chat.Create("c3").Staleness(1.1), 1);
            chatScores.Add(Chat.Create("c4"), 0);
            chatScores.Add(Chat.Create("c5"), 10);

            var list = FuzzySearch.DescendingStalenessRandomizedSort(chatScores);

            for (int i = 1; i < list.Count; i++)
            {
                Assert.That(list[i].Value <= list[i - 1].Value, Is.True);
            }

            //list.ForEach((kvp) => Console.WriteLine(kvp.Key + " -> " + kvp.Value));

            var chats = (from kvp in list select kvp.Key).ToList();

            Assert.That(chats[0].text, Is.EqualTo("c5"));
            Assert.That(chats[1].text, Is.EqualTo("c3"));
            Assert.That(chats[2].text, Is.EqualTo("c2"));
            Assert.That(chats[3].text, Is.EqualTo("c1"));
            Assert.That(chats[4].text, Is.EqualTo("c4"));
        }