コード例 #1
0
ファイル: LRUCacheMapTest.cs プロジェクト: radtek/taste.net
        public void TestVersusDictionary()
        {
            LRUCacheMap <int, String> actual   = new LRUCacheMap <int, String>(1, 10000);
            IDictionary <int, String> expected = new Dictionary <int, String>(10000);
            Random r = RandomUtils.GetRandom();

            for (int i = 0; i < 10000; i++)
            {
                double d   = r.NextDouble();
                int    key = r.Next(100);
                if (d < 0.4)
                {
                    Assert.AreEqual(expected[key], actual[key]);
                }
                else
                {
                    if (d < 0.7)
                    {
                        expected.Add(key, "foo");
                        actual.Add(key, "foo");
                        //Assert.AreEqual(expected.Add(key, "foo"), actual.Add(key,"foo"));
                    }
                    else
                    {
                        Assert.AreEqual(expected.Remove(key), actual.Remove(key));
                    }
                    Assert.AreEqual(expected.Count, actual.Count);
                }
            }
        }
コード例 #2
0
ファイル: LRUCacheMapTest.cs プロジェクト: radtek/taste.net
        public void TestNull()
        {
            LRUCacheMap <String, String> map = new LRUCacheMap <String, String>();

            try
            {
                map.Add(null, "bar");
                Assert.Fail("Should have thrown NullReferenceException");
            }
            catch (ArgumentNullException)
            {
            }

            try
            {
                map.Add("foo", null);
                Assert.Fail("Should have thrown ArgumentNullException");
            }
            catch (ArgumentNullException)
            {
                // good
            }
            try
            {
                string v = map[null];
                Assert.Fail("Should have thrown ArgumentNullException");
            }
            catch (ArgumentNullException)
            {
            }
        }
コード例 #3
0
ファイル: LRUCacheMapTest.cs プロジェクト: ccollie/taste.net
 public void TestPutAndGet()
 {
     LRUCacheMap<String, String> map = new LRUCacheMap<String, String>();
     Assert.IsNull(map["foo"]);
     
     map.Add("foo", "bar");
     Assert.AreEqual("bar", map["foo"]);
 }
コード例 #4
0
ファイル: LRUCacheMapTest.cs プロジェクト: radtek/taste.net
        private static LRUCacheMap <String, String> BuildTestFastMap()
        {
            LRUCacheMap <String, String> map = new LRUCacheMap <String, String>();

            map.Add("foo", "bar");
            map.Add("baz", "bang");
            map.Add("alpha", "beta");
            return(map);
        }
コード例 #5
0
ファイル: LRUCacheMapTest.cs プロジェクト: radtek/taste.net
        public void testGrow()
        {
            LRUCacheMap <String, String> map = new LRUCacheMap <String, String>(1, LRUCacheMap <string, string> .NO_MAX_SIZE);

            map.Add("foo", "bar");
            map.Add("baz", "bang");
            Assert.AreEqual("bar", map["foo"]);
            Assert.AreEqual("bang", map["baz"]);
        }
コード例 #6
0
ファイル: LRUCacheMapTest.cs プロジェクト: radtek/taste.net
        public void TestPutAndGet()
        {
            LRUCacheMap <String, String> map = new LRUCacheMap <String, String>();

            Assert.IsNull(map["foo"]);

            map.Add("foo", "bar");
            Assert.AreEqual("bar", map["foo"]);
        }
コード例 #7
0
ファイル: LRUCacheMapTest.cs プロジェクト: ccollie/taste.net
 public void TestClear()
 {
     LRUCacheMap<String, String> map = new LRUCacheMap<String, String>();
     map.Add("foo", "bar");
     map.Clear();
     Assert.AreEqual(0, map.Count);
     Assert.IsTrue(map.IsEmpty);
     Assert.IsNull(map["foo"]);
 }
コード例 #8
0
ファイル: LRUCacheMapTest.cs プロジェクト: radtek/taste.net
        public void TestClear()
        {
            LRUCacheMap <String, String> map = new LRUCacheMap <String, String>();

            map.Add("foo", "bar");
            map.Clear();
            Assert.AreEqual(0, map.Count);
            Assert.IsTrue(map.IsEmpty);
            Assert.IsNull(map["foo"]);
        }
コード例 #9
0
ファイル: LRUCacheMapTest.cs プロジェクト: ccollie/taste.net
 public void TestSizeEmpty()
 {
     LRUCacheMap<String, String> map = new LRUCacheMap<String, String>();
     Assert.AreEqual(0, map.Count);
     Assert.IsTrue(map.IsEmpty);
     map.Add("foo", "bar");
     Assert.AreEqual(1, map.Count);
     Assert.IsFalse(map.IsEmpty);
     map.Remove("foo");
     Assert.AreEqual(0, map.Count);
     Assert.IsTrue(map.IsEmpty);
 }
コード例 #10
0
ファイル: LRUCacheMapTest.cs プロジェクト: radtek/taste.net
        public void TestContains()
        {
            LRUCacheMap <String, String> map = BuildTestFastMap();

            Assert.IsTrue(map.ContainsKey("foo"));
            Assert.IsTrue(map.ContainsKey("baz"));
            Assert.IsTrue(map.ContainsKey("alpha"));
            Assert.IsTrue(map.ContainsValue("bar"));
            Assert.IsTrue(map.ContainsValue("bang"));
            Assert.IsTrue(map.ContainsValue("beta"));
            Assert.IsFalse(map.ContainsKey("something"));
        }
コード例 #11
0
ファイル: LRUCacheMapTest.cs プロジェクト: radtek/taste.net
        public void TestValues()
        {
            LRUCacheMap <String, String> map      = BuildTestFastMap();
            ICollection <String>         expected = new List <String>(3);

            expected.Add("bar");
            expected.Add("bang");
            expected.Add("beta");
            ICollection <String> actual = map.Values;

            Assert.IsTrue(ContainsAll <string>(expected, actual));
            Assert.IsTrue(ContainsAll <string>(actual, expected));
        }
コード例 #12
0
ファイル: LRUCacheMapTest.cs プロジェクト: radtek/taste.net
        public void TestMaxSize()
        {
            LRUCacheMap <String, String> map = new LRUCacheMap <String, String>(1, 1);

            map.Add("foo", "bar");
            Assert.AreEqual(1, map.Count);
            map.Add("baz", "bang");
            Assert.AreEqual(1, map.Count);
            Assert.IsNull(map["foo"]);
            map.Add("baz", "buzz");
            Assert.AreEqual(1, map.Count);
            Assert.AreEqual("buzz", map["baz"]);
        }
コード例 #13
0
ファイル: LRUCacheMapTest.cs プロジェクト: radtek/taste.net
        public void TestSizeEmpty()
        {
            LRUCacheMap <String, String> map = new LRUCacheMap <String, String>();

            Assert.AreEqual(0, map.Count);
            Assert.IsTrue(map.IsEmpty);
            map.Add("foo", "bar");
            Assert.AreEqual(1, map.Count);
            Assert.IsFalse(map.IsEmpty);
            map.Remove("foo");
            Assert.AreEqual(0, map.Count);
            Assert.IsTrue(map.IsEmpty);
        }
コード例 #14
0
ファイル: LRUCacheMapTest.cs プロジェクト: radtek/taste.net
        public void TestKeys()
        {
            LRUCacheMap <String, String> map      = BuildTestFastMap();
            ICollection <String>         expected = new List <String>(3);

            expected.Add("foo");
            expected.Add("baz");
            expected.Add("alpha");

            ICollection <String> actual = map.Keys;

            Assert.IsTrue(ContainsAll <string>(expected, actual));
            Assert.IsTrue(ContainsAll <string>(actual, expected));
        }
コード例 #15
0
ファイル: LRUCacheMapTest.cs プロジェクト: radtek/taste.net
        public void TestEntries()
        {
            LRUCacheMap <String, String> map          = BuildTestFastMap();
            ICollection <String>         expectedKeys = new List <String>(3);

            expectedKeys.Add("foo");
            expectedKeys.Add("baz");
            expectedKeys.Add("alpha");

            ICollection <String> expectedValues = new List <String>(3);

            expectedValues.Add("bar");
            expectedValues.Add("bang");
            expectedValues.Add("beta");
            Assert.AreEqual(3, expectedValues.Count);
            foreach (KeyValuePair <string, string> entry in map)
            {
                expectedKeys.Remove(entry.Key);
                expectedValues.Remove(entry.Value);
            }
            Assert.AreEqual(0, expectedKeys.Count);
            Assert.AreEqual(0, expectedValues.Count);
        }
コード例 #16
0
ファイル: LRUCacheMapTest.cs プロジェクト: ccollie/taste.net
 public void testGrow()
 {
     LRUCacheMap<String, String> map = new LRUCacheMap<String, String>(1, LRUCacheMap<string, string>.NO_MAX_SIZE);
     map.Add("foo", "bar");
     map.Add("baz", "bang");
     Assert.AreEqual("bar", map["foo"]);
     Assert.AreEqual("bang", map["baz"]);
 }
コード例 #17
0
ファイル: LRUCacheMapTest.cs プロジェクト: ccollie/taste.net
 public void TestMaxSize()
 {
     LRUCacheMap<String, String> map = new LRUCacheMap<String, String>(1, 1);
     map.Add("foo", "bar");
     Assert.AreEqual(1, map.Count);
     map.Add("baz", "bang");
     Assert.AreEqual(1, map.Count);
     Assert.IsNull(map["foo"]);
     map.Add("baz", "buzz");
     Assert.AreEqual(1, map.Count);
     Assert.AreEqual("buzz", map["baz"]);
 }
コード例 #18
0
ファイル: LRUCacheMapTest.cs プロジェクト: ccollie/taste.net
 private static LRUCacheMap<String, String> BuildTestFastMap()
 {
     LRUCacheMap<String, String> map = new LRUCacheMap<String, String>();
     map.Add("foo", "bar");
     map.Add("baz", "bang");
     map.Add("alpha", "beta");
     return map;
 }
コード例 #19
0
ファイル: LRUCacheMapTest.cs プロジェクト: ccollie/taste.net
        public void TestNull() 
        {
            LRUCacheMap<String, String> map = new LRUCacheMap<String, String>();
            try
            {
                map.Add(null, "bar");
                Assert.Fail("Should have thrown NullReferenceException");
            }
            catch (ArgumentNullException)
            {
            }

            try
            {
                map.Add("foo", null);
                Assert.Fail("Should have thrown ArgumentNullException");
            }
            catch (ArgumentNullException)
            {
                // good
            }
            try
            {
                string v = map[null];
                Assert.Fail("Should have thrown ArgumentNullException");
            }
            catch (ArgumentNullException)
            {

            }          
        }
コード例 #20
0
ファイル: LRUCacheMapTest.cs プロジェクト: ccollie/taste.net
 public void TestVersusDictionary()
 {
     LRUCacheMap<int, String> actual = new LRUCacheMap<int, String>(1, 10000);
     IDictionary<int, String> expected = new Dictionary<int, String>(10000);
     Random r = RandomUtils.GetRandom();
     for (int i = 0; i < 10000; i++)
     {
         double d = r.NextDouble();
         int key = r.Next(100);
         if (d < 0.4)
         {
             Assert.AreEqual(expected[key], actual[key]);
         }
         else
         {
             if (d < 0.7)
             {
                 expected.Add(key, "foo");
                 actual.Add(key, "foo");
                 //Assert.AreEqual(expected.Add(key, "foo"), actual.Add(key,"foo"));
             }
             else
             {
                 Assert.AreEqual(expected.Remove(key), actual.Remove(key));
             }
             Assert.AreEqual(expected.Count, actual.Count);
         }
     }
 }