Ejemplo n.º 1
0
        public void HugeDictionary_Basic()
        {
            HugeDictionary <string, int> dictionary;
            int value;

            dictionary = new HugeDictionary <string, int>(10);
            Assert.AreEqual(0, dictionary.Count);
            Assert.IsFalse(dictionary.ContainsKey("0"));
            Assert.IsFalse(dictionary.ContainsKey("1"));

            Assert.IsFalse(dictionary.TryGetValue("0", out value));
            Assert.AreEqual(0, value);
            Assert.IsFalse(dictionary.TryGetValue("1", out value));
            Assert.AreEqual(0, value);

            dictionary.Add("0", 0);
            Assert.AreEqual(1, dictionary.Count);
            Assert.AreEqual(0, dictionary["0"]);
            Assert.IsTrue(dictionary.ContainsKey("0"));
            Assert.IsFalse(dictionary.ContainsKey("1"));

            Assert.IsTrue(dictionary.TryGetValue("0", out value));
            Assert.AreEqual(0, value);
            Assert.IsFalse(dictionary.TryGetValue("1", out value));
            Assert.AreEqual(0, value);

            dictionary.Add("1", 1);
            Assert.AreEqual(2, dictionary.Count);
            Assert.AreEqual(0, dictionary["0"]);
            Assert.AreEqual(1, dictionary["1"]);
            Assert.IsTrue(dictionary.ContainsKey("0"));
            Assert.IsTrue(dictionary.ContainsKey("1"));

            Assert.IsTrue(dictionary.TryGetValue("0", out value));
            Assert.AreEqual(0, value);
            Assert.IsTrue(dictionary.TryGetValue("1", out value));
            Assert.AreEqual(1, value);

            dictionary.Remove("0");
            Assert.AreEqual(1, dictionary.Count);
            Assert.AreEqual(1, dictionary["1"]);
            Assert.IsFalse(dictionary.ContainsKey("0"));
            Assert.IsTrue(dictionary.ContainsKey("1"));

            Assert.IsFalse(dictionary.TryGetValue("0", out value));
            Assert.AreEqual(0, value);
            Assert.IsTrue(dictionary.TryGetValue("1", out value));
            Assert.AreEqual(1, value);

            dictionary.Clear();
            Assert.AreEqual(0, dictionary.Count);
            Assert.IsFalse(dictionary.ContainsKey("0"));
            Assert.IsFalse(dictionary.ContainsKey("1"));
        }
Ejemplo n.º 2
0
        public void HugeDictionary_Capacity()
        {
            HugeDictionary <string, int> dictionary;
            int value;

            dictionary = new HugeDictionary <string, int>(10, 5000);
            Assert.AreEqual(0, dictionary.Count);
            Assert.IsFalse(dictionary.ContainsKey("0"));
            Assert.IsFalse(dictionary.ContainsKey("1"));

            Assert.IsFalse(dictionary.TryGetValue("0", out value));
            Assert.AreEqual(0, value);
            Assert.IsFalse(dictionary.TryGetValue("1", out value));
            Assert.AreEqual(0, value);
        }
Ejemplo n.º 3
0
        public void HugeDictionary_KeyComparer()
        {
            HugeDictionary <string, int> dictionary;

            dictionary = new HugeDictionary <string, int>(10, StringComparer.OrdinalIgnoreCase);
            Assert.AreEqual(0, dictionary.Count);
            Assert.IsFalse(dictionary.ContainsKey("one"));
            Assert.IsFalse(dictionary.ContainsKey("two"));

            dictionary.Add("one", 0);
            Assert.AreEqual(1, dictionary.Count);
            Assert.AreEqual(0, dictionary["one"]);
            Assert.AreEqual(0, dictionary["ONE"]);
            Assert.IsTrue(dictionary.ContainsKey("one"));
            Assert.IsTrue(dictionary.ContainsKey("One"));
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Returns true if the given index is in this index.
 /// </summary>
 /// <param name="idx"></param>
 /// <returns></returns>
 public bool Contains(long idx)
 {
     return(_coordinates.ContainsKey(idx));
 }