Exemplo n.º 1
0
        public void Can_update_a_stored_item_with_new_value()
        {
            var map = new IntHashMap <string>();

            map.AddOrUpdate(42, "1");
            map.AddOrUpdate(42, "3");

            Assert.AreEqual("3", map.GetValueOrDefault(42));
            Assert.AreEqual(1, map.Count);
        }
Exemplo n.º 2
0
        public void Can_store_and_retrieve_value_from_map()
        {
            var map = new IntHashMap <string>();

            map.AddOrUpdate(42, "1");
            map.AddOrUpdate(42 + 32, "2");

            // interrupt the keys with ne key
            map.AddOrUpdate(43, "a");
            map.AddOrUpdate(43 + 32, "b");

            map.AddOrUpdate(42 + 32 + 32, "3");

            Assert.AreEqual("1", map.GetValueOrDefault(42));
            Assert.AreEqual("2", map.GetValueOrDefault(42 + 32));
            Assert.AreEqual("3", map.GetValueOrDefault(42 + 32 + 32));
            Assert.AreEqual(null, map.GetValueOrDefault(42 + 32 + 32 + 32));

            Assert.AreEqual("a", map.GetValueOrDefault(43));
        }
Exemplo n.º 3
0
        public void Can_remove_the_stored_item()
        {
            var map = new IntHashMap <string>();

            map.AddOrUpdate(42, "1");
            map.AddOrUpdate(42 + 32, "2");
            map.AddOrUpdate(42 + 32 + 32, "3");

            map.Remove(42 + 32);

            Assert.AreEqual(2, map.Count);
            Assert.AreEqual("3", map.GetValueOrDefault(42 + 32 + 32));
        }
Exemplo n.º 4
0
        public void Can_remove_the_stored_item_twice()
        {
            var map = new IntHashMap <string>(2);

            map.AddOrUpdate(42, "1");
            map.AddOrUpdate(41, "41");
            map.AddOrUpdate(42 + 32, "2");
            map.AddOrUpdate(43, "43");
            map.AddOrUpdate(42 + 32 + 32, "3");

            // removing twice
            map.Remove(42 + 32);
            map.Remove(42 + 32);

            Assert.AreEqual(4, map.Count);
            Assert.AreEqual("3", map.GetValueOrDefault(42 + 32 + 32));
        }