Пример #1
0
        private static FastMap <String, String> buildTestFastMap()
        {
            FastMap <String, String> map = new FastMap <String, String>();

            map.put("foo", "bar");
            map.put("baz", "bang");
            map.put("alpha", "beta");
            return(map);
        }
Пример #2
0
        public void testGrow()
        {
            IDictionary <String, String> map = new FastMap <String, String>(1, FastMap.NO_MAX_SIZE);

            map.put("foo", "bar");
            map.put("baz", "bang");
            Assert.AreEqual("bar", map.get("foo"));
            Assert.AreEqual("bang", map.get("baz"));
        }
Пример #3
0
        public void testMaxSize()
        {
            IDictionary <String, String> map = new FastMap <String, String>(1, 1);

            map.put("foo", "bar");
            Assert.AreEqual(1, map.Count);
            map.put("baz", "bang");
            Assert.AreEqual(1, map.Count);
            Assert.IsNull(map.get("foo"));
            map.put("baz", "buzz");
            Assert.AreEqual(1, map.Count);
            Assert.AreEqual("buzz", map.get("baz"));
        }
Пример #4
0
        public void testVersusHashMap()
        {
            IDictionary <Integer, String> actual   = new FastMap <Integer, String>(1, 1000000);
            IDictionary <Integer, String> expected = Maps.newHashMapWithExpectedSize(1000000);
            Random r = RandomUtils.getRandom();

            for (int i = 0; i < 1000000; i++)
            {
                double  d   = r.nextDouble();
                Integer key = r.nextInt(100);
                if (d < 0.4)
                {
                    Assert.AreEqual(expected.get(key), actual.get(key));
                }
                else
                {
                    if (d < 0.7)
                    {
                        Assert.AreEqual(expected.put(key, "foo"), actual.put(key, "foo"));
                    }
                    else
                    {
                        Assert.AreEqual(expected.remove(key), actual.remove(key));
                    }
                    Assert.AreEqual(expected.Count, actual.Count);
                    Assert.AreEqual(expected.isEmpty(), actual.isEmpty());
                }
            }
        }
Пример #5
0
        public void testNull1()
        {
            IDictionary <String, String> map = new FastMap <String, String>();

            Assert.IsNull(map.get(null));
            map.put(null, "bar");
        }
Пример #6
0
        public void testPutAndGet()
        {
            IDictionary <string, string> map = new FastMap <String, String>();

            Assert.IsNull(map.get("foo"));
            map.put("foo", "bar");
            Assert.AreEqual("bar", map.get("foo"));
        }
Пример #7
0
 public void testClear() {
   IDictionary<String, String> map = new FastMap<String, String>();
   map.put("foo", "bar");
   map.clear();
   Assert.AreEqual(0, map.Count);
   Assert.True(map.isEmpty());
   Assert.IsNull(map.get("foo"));
 }
Пример #8
0
        public void testClear()
        {
            IDictionary <String, String> map = new FastMap <String, String>();

            map.put("foo", "bar");
            map.clear();
            Assert.AreEqual(0, map.Count);
            Assert.True(map.isEmpty());
            Assert.IsNull(map.get("foo"));
        }
Пример #9
0
 public void testSizeEmpty() {
   IDictionary<String, String> map = new FastMap<String, String>();
   Assert.AreEqual(0, map.Count);
   Assert.True(map.isEmpty());
   map.put("foo", "bar");
   Assert.AreEqual(1, map.Count);
   Assert.False(map.isEmpty());
   map.remove("foo");
   Assert.AreEqual(0, map.Count);
   Assert.True(map.isEmpty());
 }
Пример #10
0
        public void testSizeEmpty()
        {
            IDictionary <String, String> map = new FastMap <String, String>();

            Assert.AreEqual(0, map.Count);
            Assert.True(map.isEmpty());
            map.put("foo", "bar");
            Assert.AreEqual(1, map.Count);
            Assert.False(map.isEmpty());
            map.remove("foo");
            Assert.AreEqual(0, map.Count);
            Assert.True(map.isEmpty());
        }
Пример #11
0
 public void testVersusHashMap() {
   IDictionary<Integer, String> actual = new FastMap<Integer, String>(1, 1000000);
   IDictionary<Integer, String> expected = Maps.newHashMapWithExpectedSize(1000000);
   Random r = RandomUtils.getRandom();
   for (int i = 0; i < 1000000; i++) {
     double d = r.nextDouble();
     Integer key = r.nextInt(100);
     if (d < 0.4) {
       Assert.AreEqual(expected.get(key), actual.get(key));
     } else {
       if (d < 0.7) {
         Assert.AreEqual(expected.put(key, "foo"), actual.put(key, "foo"));
       } else {
         Assert.AreEqual(expected.remove(key), actual.remove(key));
       }
       Assert.AreEqual(expected.Count, actual.Count);
       Assert.AreEqual(expected.isEmpty(), actual.isEmpty());
     }
   }
 }
Пример #12
0
 public void testNull2() {
   IDictionary<String, String> map = new FastMap<String, String>();
   map.put("foo", null);
 }
Пример #13
0
 public void testNull1() {
   IDictionary<String, String> map = new FastMap<String, String>();
   Assert.IsNull(map.get(null));
   map.put(null, "bar");
 }
Пример #14
0
 public void testPutAndGet() {
   IDictionary<string, string> map = new FastMap<String, String>();
   Assert.IsNull(map.get("foo"));
   map.put("foo", "bar");
   Assert.AreEqual("bar", map.get("foo"));
 }
Пример #15
0
 private static FastMap<String, String> buildTestFastMap() {
   FastMap<String, String> map = new FastMap<String, String>();
   map.put("foo", "bar");
   map.put("baz", "bang");
   map.put("alpha", "beta");
   return map;
 }
Пример #16
0
 public void testMaxSize() {
   IDictionary<String, String> map = new FastMap<String, String>(1, 1);
   map.put("foo", "bar");
   Assert.AreEqual(1, map.Count);
   map.put("baz", "bang");
   Assert.AreEqual(1, map.Count);
   Assert.IsNull(map.get("foo"));
   map.put("baz", "buzz");
   Assert.AreEqual(1, map.Count);
   Assert.AreEqual("buzz", map.get("baz"));
 }
Пример #17
0
        public void testNull2()
        {
            IDictionary <String, String> map = new FastMap <String, String>();

            map.put("foo", null);
        }
Пример #18
0
 public void testGrow() {
   IDictionary<String, String> map = new FastMap<String, String>(1, FastMap.NO_MAX_SIZE);
   map.put("foo", "bar");
   map.put("baz", "bang");
   Assert.AreEqual("bar", map.get("foo"));
   Assert.AreEqual("bang", map.get("baz"));
 }