示例#1
0
        [Test] public void TestRandom()
        {
            SimpleCache <string> c  = new SimpleCache <string>();
            StringBuilder        sb = new StringBuilder("12345678");
            int           seed      = Environment.TickCount;
            Random        r         = new Random(seed);
            List <string> words     = new List <string>();
            int           cacheHits = 0;

            for (int i = 0; i < 1000; i++)
            {
                for (int ci = 0; ci < 8; ci++)
                {
                    sb[ci] = (char)r.Next(0x7F);
                }
                words.Add(sb.ToString());

                Try(words[r.Next(words.Count)], c, ref cacheHits);
                Try(words[r.Next(words.Count)], c, ref cacheHits);
                Try(words[r.Next(words.Count)], c, ref cacheHits);
            }
            Assert.GreaterOrEqual(c.CacheHits, 500);
            Assert.GreaterOrEqual(c.CacheMisses, 500);
        }
示例#2
0
        private void Try(string word, SimpleCache <string> c, ref int cacheHits)
        {
            string cacheWord = c.Cache(word);

            Assert.AreEqual(word, cacheWord);
        }