public void ChatRemoveest() { var watch = Stopwatch.StartNew(); var cache = new RankCacheStruct <ChatData>(); Assert.IsTrue(cache.RemoveRankByScore(ChatType.World.ToString(), 0, -1)); WaitEnd(watch); }
public void RankTest() { var cache = new RankCacheStruct <LvRank>(); LvRank rank = new LvRank() { UserId = 10000, Score = 100 }; Assert.IsTrue(cache.AddRank(rank)); Assert.IsTrue(cache.RemoveRankByScore(LvRank.Lv, 0, null)); for (int i = 0; i < 100; i++) { LvRank lvRank = new LvRank() { UserId = 10001 + i, Score = i + 1 }; int no = (int)cache.GetRankNo(lvRank.Key, lvRank); if (no < 1) { Assert.IsTrue(cache.AddRank(lvRank)); } } int count; Assert.IsTrue(cache.TryGetRankCount(LvRank.Lv, out count)); Assert.IsTrue(count == 100); var userList = cache.TakeRank(LvRank.Lv, 3).ToList(); Trace.WriteLine("Top 3:" + string.Join(",", userList.Select(t => t.UserId))); Assert.IsTrue(userList[0].UserId == 10100); Assert.IsTrue(cache.ExchangeRank(LvRank.Lv, userList[0], userList[1])); userList = cache.TakeRank(LvRank.Lv, 3).ToList(); Assert.IsTrue(userList[0].UserId == 10099); Assert.IsTrue(cache.ExchangeRank(LvRank.Lv, userList[0], userList[1])); userList = cache.TakeRank(LvRank.Lv, 3).ToList(); Assert.IsTrue(userList[0].UserId == 10100); var three = userList[userList.Count - 1]; three.Score = 101; cache.Sort(LvRank.Lv, three); userList = cache.TakeRank(LvRank.Lv, 3).ToList(); Assert.IsTrue(userList[0].UserId == 10098); Trace.WriteLine("10100 RankNo:" + cache.GetRankNo(LvRank.Lv, t => t.UserId == 10100).FirstOrDefault()); three.Score = 98; cache.Sort(LvRank.Lv, three); //clear foreach (var item in cache.TakeRank(LvRank.Lv)) { cache.Remove(item); } }
public void ChatTest() { var watch = Stopwatch.StartNew(); var cache = new RankCacheStruct <ChatData>(); var list = cache.TakeRank(ChatType.World.ToString(), 50); Trace.WriteLine("list ms:" + watch.ElapsedMilliseconds); list = cache.TakeRank(ChatType.World.ToString(), 50); Trace.WriteLine("list count:" + list.Count()); WaitEnd(watch); }
public void ChatExchangeTest() { var watch = Stopwatch.StartNew(); var cache = new RankCacheStruct <ChatData>(); var list = cache.TakeRank(ChatType.World.ToString(), 50).ToList(); var t1 = list[5]; Trace.WriteLine("rank:" + list[5].Message); Assert.IsTrue(cache.ExchangeRank(ChatType.World.ToString(), list[list.Count - 1], list[5])); list = cache.TakeRank(ChatType.World.ToString(), 50).ToList(); var t2 = list[5]; Trace.WriteLine("rank:" + list[5].Message); Assert.AreNotEqual(t1, t2); WaitEnd(watch); }
public void ChatAddTest() { var watch = Stopwatch.StartNew(); var cache = new RankCacheStruct <ChatData>(); var addlist = new List <ChatData>(); for (int i = 0; i < 10; i++) { var chat = new ChatData(ChatType.World); chat.Message = "hello" + i; chat.SendTime = DateTime.Now; chat.ExpiredTime = DateTime.Now.AddDays(1); chat.Score = cache.GetNextNo(); addlist.Add(chat); } cache.AddRank(ChatType.World.ToString(), addlist.ToArray()); WaitEnd(watch); }